Mercurial > hg > xemacs-beta
comparison lisp/bytecomp-runtime.el @ 4949:018e13fdeaeb
compile-related functions added, for use in Unicode-internal ws
-------------------- ChangeLog entries follow: --------------------
lisp/ChangeLog addition:
2010-01-17 Ben Wing <ben@xemacs.org>
* bytecomp-runtime.el:
* bytecomp-runtime.el (error-unless-tests-match): New.
* bytecomp-runtime.el (byte-compile-file-being-compiled): New.
* bytecomp-runtime.el (compiled-if): New.
* bytecomp-runtime.el (compiled-when): New.
Add functions for dealing with conditional compilation of different code
depending on the presence or absence of features. Necessary for some
Mule code where code is run during compilation (macros or eval-when-compile)
but, depending on how the code is written, the code itself will crash
either with or without Unicode-internal.
compiled-if and compiled-when are the basic functions for conditional
compilation. They automatically trigger an error message upon file
loading if, at that time, the test expression that selected which code
to compile does not have the same value as at compile time.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Sun, 17 Jan 2010 04:52:48 -0600 |
parents | 0e3842cd22e2 |
children | 0d43872986b6 |
comparison
equal
deleted
inserted
replaced
4948:8b230c53075b | 4949:018e13fdeaeb |
---|---|
1 ;;; bytecomp-runtime.el --- byte-compiler support for inlining | 1 ;;; bytecomp-runtime.el --- byte-compiler support for inlining |
2 | 2 |
3 ;; Copyright (C) 1992, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1992, 1997 Free Software Foundation, Inc. |
4 ;; Copyright (C) 2002 Ben Wing. | 4 ;; Copyright (C) 2002, 2010 Ben Wing. |
5 | 5 |
6 ;; Author: Jamie Zawinski <jwz@jwz.org> | 6 ;; Author: Jamie Zawinski <jwz@jwz.org> |
7 ;; Author: Hallvard Furuseth <hbf@ulrik.uio.no> | 7 ;; Author: Hallvard Furuseth <hbf@ulrik.uio.no> |
8 ;; Maintainer: XEmacs Development Team | 8 ;; Maintainer: XEmacs Development Team |
9 ;; Keywords: internal, dumped | 9 ;; Keywords: internal, dumped |
491 SYMBOL must be quoted and can be a list of SYMBOLS. See also | 491 SYMBOL must be quoted and can be a list of SYMBOLS. See also |
492 `with-obsolete-variable'." | 492 `with-obsolete-variable'." |
493 `(with-byte-compiler-warnings-suppressed 'obsolete ,@body)) | 493 `(with-byte-compiler-warnings-suppressed 'obsolete ,@body)) |
494 | 494 |
495 | 495 |
496 | |
497 (defmacro error-unless-tests-match (test &optional source) | |
498 "Signal an error unless TEST matches when being compiled and loaded. | |
499 This is for use in a file that will be byte-compiled. Unless TEST has the | |
500 same nilness or non-nilness when the file is compiled and loaded, an error | |
501 will be signalled. SOURCE is the name of the source file." | |
502 (let ((source (eval source))) | |
503 `(unless (eq (not ,test) ,(not (eval test))) | |
504 (error ,(format "This file was compiled with `%s' %s, | |
505 but it was %s when run. This file needs to be compiled with | |
506 the same value for the expression as when it is run. Please delete | |
507 %s and rebuild." | |
508 test (if (eval test) "true" "false") | |
509 (if (eval test) "false" "true") | |
510 (cond | |
511 ((null source) "the .elc for this file") | |
512 ((string-match "\.elc$" source) source) | |
513 ((string-match "\.el$" source) (concat source "c")) | |
514 (t (concat source ".elc")))))))) | |
515 | |
516 (defun byte-compile-file-being-compiled () | |
517 "When byte-compiling a file, return the name of the file being compiled. | |
518 Return nil otherwise." | |
519 (or | |
520 ;;The first of these, but not the second, seems to work noninteractively; | |
521 ;;vice-versa interactively. This is because interactively a *Compile Log* | |
522 ;;buffer is created and byte-compile-log-1 inserts a "Compiling file ..." | |
523 ;;message into thelog buffer, and then sets byte-compile-current-file to | |
524 ;;nil to indicate that the message shouldn't be printed again. | |
525 (and-boundp 'byte-compile-current-file byte-compile-current-file) | |
526 (and-boundp 'byte-compile-log-buffer | |
527 (with-current-buffer byte-compile-log-buffer | |
528 (save-excursion | |
529 (and (re-search-backward "Compiling file \\(.*\\) at " nil t) | |
530 (match-string 1))))))) | |
531 | |
532 | |
533 (defmacro compiled-if (test if &rest else) | |
534 "Like a regular `if' statement but the TEST will be evalled at compile time. | |
535 If TEST doesn't match at compile time and load time, an error will be | |
536 signalled." | |
537 (let ((being-compiled (byte-compile-file-being-compiled))) | |
538 `(progn | |
539 (error-unless-tests-match ,test ,being-compiled) | |
540 ,(if (eval test) | |
541 if | |
542 `(progn ,else))))) | |
543 | |
544 (defmacro compiled-when (test &rest when) | |
545 "Like a regular `when' statement but the TEST will be evalled at compile time. | |
546 See `compiled-if'." | |
547 `(compiled-if ,test (progn ,@when))) | |
548 | |
549 | |
496 ;;; Interface to file-local byte-compiler parameters. | 550 ;;; Interface to file-local byte-compiler parameters. |
497 ;;; Redefined in bytecomp.el. | 551 ;;; Redefined in bytecomp.el. |
498 | 552 |
499 ;;; The great RMS speaketh: | 553 ;;; The great RMS speaketh: |
500 ;;; | 554 ;;; |