home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 2 / amigaformatcd02.iso / comms / netsoftware / irchat24.lha / irchat24 / irchat.lha / elisp / bytecomp-runtime.el next >
Encoding:
Text File  |  1994-03-06  |  7.1 KB  |  189 lines

  1. ;;; -*- Mode:Emacs-Lisp -*-
  2.  
  3. ;; Runtime support for the new optimizing byte compiler.  
  4. ;; By Jamie Zawinski <jwz@lucid.com>.
  5. ;; Last Modified: 12-jun-92.
  6. ;;
  7. ;; The code in this file should always be loaded, because it defines things 
  8. ;; like "defsubst" which should work interpreted as well.  The code in 
  9. ;; bytecomp.el and byte-optimize.el can be loaded as needed.
  10. ;;
  11. ;; This should be loaded by loadup.el or startup.el.  If you can't modify
  12. ;; those files, load this from your .emacs file.  But if you are using
  13. ;; emacs18, this file must be loaded before any .elc files which were
  14. ;; generated by the new compiler without emacs18 compatibility turned on.
  15. ;; If this file is loaded, certain emacs19 binaries will run in emacs18.
  16. ;; Meditate on the meanings of byte-compile-generate-emacs19-bytecodes and
  17. ;; byte-compile-emacs18-compatibility.
  18.  
  19.  
  20. ;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
  21.  
  22. ;; This file is part of GNU Emacs.
  23.  
  24. ;; GNU Emacs is free software; you can redistribute it and/or modify
  25. ;; it under the terms of the GNU General Public License as published by
  26. ;; the Free Software Foundation; either version 2, or (at your option)
  27. ;; any later version.
  28.  
  29. ;; GNU Emacs is distributed in the hope that it will be useful,
  30. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  32. ;; GNU General Public License for more details.
  33.  
  34. ;; You should have received a copy of the GNU General Public License
  35. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  36. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  37.  
  38.  
  39. ;; emacs-18 compatibility.
  40.  
  41. (if (fboundp 'make-byte-code)
  42.     nil
  43.   ;;
  44.   ;; To avoid compiler bootstrapping problems, this temporary uncompiled
  45.   ;; make-byte-code is needed to load the compiled one.  Ignore the warnings.
  46.   (fset 'make-byte-code
  47.     '(lambda (arglist bytestring constants stackdepth doc)
  48.        (list 'lambda arglist doc
  49.          (list 'byte-code bytestring constants stackdepth))))
  50.   ;;
  51.   ;; Now get a compiled version.
  52.   (defun make-byte-code (arglist bytestring constants stackdepth
  53.                  &optional doc &rest interactive)
  54.     "For compatibility with Emacs19 ``.elc'' files."
  55.     (nconc (list 'lambda arglist)
  56.        ;; #### Removed the (stringp doc) for speed.  Because the V19
  57.        ;;    make-byte-code depends on the args being correct, it won't
  58.        ;;    help to make a smarter version for V18 alone.
  59.        ;;    Btw, it should have been (or (stringp doc) (natnump doc)).  
  60.        (if doc (list doc))
  61.        (if interactive
  62.            (list (cons 'interactive (if (car interactive) interactive))))
  63.        (list (list 'byte-code bytestring constants stackdepth)))))
  64.  
  65.  
  66. ;;; interface to selectively inlining functions.
  67. ;;; This only happens when source-code optimization is turned on.
  68.  
  69. ;; Redefined in byte-optimize.el.
  70. (fset 'inline 'progn)
  71. (put 'inline 'lisp-indent-hook 0)
  72.  
  73.  
  74. ;;; Interface to inline functions.
  75.  
  76. (defmacro proclaim-inline (&rest fns)
  77.   "Cause the named functions to be open-coded when called from compiled code.
  78. They will only be compiled open-coded when byte-compile-optimize is true."
  79.   (cons 'eval-and-compile
  80.     (mapcar '(lambda (x)
  81.            (or (memq (get x 'byte-optimizer)
  82.                  '(nil byte-compile-inline-expand))
  83.                (error
  84.             "%s already has a byte-optimizer, can't make it inline"
  85.             x))
  86.            (list 'put (list 'quote x)
  87.              ''byte-optimizer ''byte-compile-inline-expand))
  88.         fns)))
  89.  
  90.  
  91. (defmacro proclaim-notinline (&rest fns)
  92.   "Cause the named functions to no longer be open-coded."
  93.   (cons 'eval-and-compile
  94.     (mapcar '(lambda (x)
  95.            (if (eq (get x 'byte-optimizer) 'byte-compile-inline-expand)
  96.                (put x 'byte-optimizer nil))
  97.            (list 'if (list 'eq (list 'get (list 'quote x) ''byte-optimizer)
  98.                    ''byte-compile-inline-expand)
  99.              (list 'put x ''byte-optimizer nil)))
  100.         fns)))
  101.  
  102. ;; This has a special byte-hunk-handler in bytecomp.el.
  103. (defmacro defsubst (name arglist &rest body)
  104.   "Same syntax as defun, but the defined function will always be open-coded,
  105. so long as byte-compile-optimize is true."
  106.   (list 'prog1
  107.     (cons 'defun (cons name (cons arglist body)))
  108.     (list 'proclaim-inline name)))
  109.  
  110. (defun make-obsolete (fn new)
  111.   "Make the byte-compiler warn that FUNCTION is obsolete,
  112. and NEW should be used instead.  If NEW is a string, then that is the
  113. `use instead' message."
  114.   (interactive "aMake function obsolete: \nxObsoletion replacement: ")
  115.   (let ((handler (get fn 'byte-compile)))
  116.     (if (eq 'byte-compile-obsolete handler)
  117.     (setcar (get fn 'byte-obsolete-info) new)
  118.       (put fn 'byte-obsolete-info (cons new handler))
  119.       (put fn 'byte-compile 'byte-compile-obsolete)))
  120.   fn)
  121.  
  122. (defun make-obsolete-variable (var new)
  123.   "Make the byte-compiler warn that VARIABLE is obsolete,
  124. and NEW should be used instead.  If NEW is a string, then that is the
  125. `use instead' message."
  126.   (interactive
  127.    (list
  128.     (let ((str (completing-read "Make variable obsolete: " obarray 'boundp t)))
  129.       (if (equal str "") (error ""))
  130.       (intern str))
  131.     (car (read-from-string (read-string "Obsoletion replacement: ")))))
  132.   (put var 'byte-obsolete-variable new)
  133.   var)
  134.  
  135. (put 'dont-compile 'lisp-indent-hook 0)
  136. (defmacro dont-compile (&rest body)
  137.   "Like progn, but the body will always run interpreted (not compiled).
  138. If you think you need this, you're probably making a mistake somewhere."
  139.   (list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body)))))
  140.  
  141.  
  142. ;;; interface to evaluating things at compile time and/or load time
  143. ;;; these macro must come after any uses of them in this file, as their
  144. ;;; definition in the file overrides the magic definitions on the
  145. ;;; byte-compile-macro-environment.
  146.  
  147. (put 'eval-when-compile 'lisp-indent-hook 0)
  148. (defmacro eval-when-compile (&rest body)
  149.   "Like progn, but evaluates the body at compile-time.  The result of the
  150. body appears to the compiler as a quoted constant."
  151.   ;; Not necessary because we have it in b-c-initial-macro-environment
  152.   ;; (list 'quote (eval (cons 'progn body)))
  153.   (cons 'progn body))
  154.  
  155. (put 'eval-and-compile 'lisp-indent-hook 0)
  156. (defmacro eval-and-compile (&rest body)
  157.   "Like progn, but evaluates the body at compile-time as well as at load-time."
  158.   ;; Remember, it's magic.
  159.   (cons 'progn body))
  160.  
  161.  
  162. ;;; Interface to file-local byte-compiler parameters.
  163. ;;; Redefined in bytecomp.el.
  164.  
  165. (put 'byte-compiler-options 'lisp-indent-hook 0)
  166. (defmacro byte-compiler-options (&rest args)
  167.   "Set some compilation-parameters for this file.  This will affect only the
  168. file in which it appears; this does nothing when evaluated, and when loaded
  169. from a .el file.
  170.  
  171. Each argument to this macro must be a list of a key and a value.
  172.  
  173.   Keys:          Values:        Corresponding variable:
  174.  
  175.   verbose      t, nil        byte-compile-verbose
  176.   optimize      t, nil, source, byte    byte-compile-optimize
  177.   warnings      list of warnings    byte-compile-warnings
  178.               Legal elements: (callargs redefine free-vars unresolved)
  179.   file-format      emacs18, emacs19    byte-compile-emacs18-compatibility
  180.   new-bytecodes      t, nil        byte-compile-generate-emacs19-bytecodes
  181.  
  182. For example, this might appear at the top of a source file:
  183.  
  184.     (byte-compiler-options
  185.       (optimize t)
  186.       (warnings (- free-vars))        ; Don't warn about free variables
  187.       (file-format emacs19))"
  188.   nil)
  189.