aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-02-25 00:54:15 +0000
committerRichard M. Stallman1994-02-25 00:54:15 +0000
commitd9e42bcf3664f56652bcc5660f7eb869c755c6f0 (patch)
tree8d9fc0e4529bd6ae76f45aea5d4c28f4d9714d19
parent71d78000997f506af8b648cea924c09bdb59a0e1 (diff)
downloademacs-d9e42bcf3664f56652bcc5660f7eb869c755c6f0.tar.gz
emacs-d9e42bcf3664f56652bcc5660f7eb869c755c6f0.zip
(byte-compile-protect-from-advice): New macro that
temporarily deactivates advice of `defun/defmacro' while BODY is run. (byte-compile-from-buffer, byte-compile-top-level): Use `byte-compile-protect-from-advice' to protect compilation.
-rw-r--r--lisp/emacs-lisp/bytecomp.el187
1 files changed, 109 insertions, 78 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index b72e5bcd0df..e991ddbdd66 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1246,70 +1246,100 @@ With argument, insert value in current buffer after the form."
1246 ((message "%s" (prin1-to-string value))))))) 1246 ((message "%s" (prin1-to-string value)))))))
1247 1247
1248 1248
1249(defmacro byte-compile-protect-from-advice (&rest body)
1250 ;; Temporarily deactivates advice of `defun/defmacro' while BODY is run.
1251 ;; After completion of BODY the initial advice state is reinstated.
1252 ;; If `defun/defmacro' are actively advised during compilation then the
1253 ;; compilation of nested `defun/defmacro's produces incorrect code which
1254 ;; is the motivation for this macro. It calls the functions `ad-is-active',
1255 ;; `ad-activate' and `ad-deactivate' which will be reported as undefined
1256 ;; functions during the compilation of the compiler.
1257 (` (let (;; make sure no `require' activates them by
1258 ;; accident via a call to `ad-start-advice':
1259 (ad-advised-definers '(fset defalias define-function))
1260 defun-active-p defmacro-active-p)
1261 (cond (;; check whether Advice is loaded:
1262 (fboundp 'ad-scan-byte-code-for-fsets)
1263 ;; save activation state of `defun/defmacro' and
1264 ;; deactivate them if their advice is active:
1265 (if (setq defun-active-p (ad-is-active 'defun))
1266 (ad-deactivate 'defun))
1267 (if (setq defmacro-active-p (ad-is-active 'defmacro))
1268 (ad-deactivate 'defmacro))))
1269 (unwind-protect
1270 (progn
1271 (,@ body))
1272 ;; reactivate what was active before:
1273 (if defun-active-p
1274 (ad-activate 'defun))
1275 (if defmacro-active-p
1276 (ad-activate 'defmacro))))))
1277
1249(defun byte-compile-from-buffer (inbuffer &optional eval) 1278(defun byte-compile-from-buffer (inbuffer &optional eval)
1250 ;; buffer --> output-buffer, or buffer --> eval form, return nil 1279 ;; buffer --> output-buffer, or buffer --> eval form, return nil
1251 (let (outbuffer) 1280 (byte-compile-protect-from-advice
1252 (let (;; Prevent truncation of flonums and lists as we read and print them 1281 (let (outbuffer)
1253 (float-output-format nil) 1282 (let (;; Prevent truncation of flonums and lists as we read and print them
1254 (case-fold-search nil) 1283 (float-output-format nil)
1255 (print-length nil) 1284 (case-fold-search nil)
1256 ;; Simulate entry to byte-compile-top-level 1285 (print-length nil)
1257 (byte-compile-constants nil) 1286 ;; Simulate entry to byte-compile-top-level
1258 (byte-compile-variables nil) 1287 (byte-compile-constants nil)
1259 (byte-compile-tag-number 0) 1288 (byte-compile-variables nil)
1260 (byte-compile-depth 0) 1289 (byte-compile-tag-number 0)
1261 (byte-compile-maxdepth 0) 1290 (byte-compile-depth 0)
1262 (byte-compile-output nil) 1291 (byte-compile-maxdepth 0)
1263;; #### This is bound in b-c-close-variables. 1292 (byte-compile-output nil)
1264;; (byte-compile-warnings (if (eq byte-compile-warnings t) 1293 ;; #### This is bound in b-c-close-variables.
1265;; byte-compile-warning-types 1294 ;; (byte-compile-warnings (if (eq byte-compile-warnings t)
1266;; byte-compile-warnings)) 1295 ;; byte-compile-warning-types
1267 ) 1296 ;; byte-compile-warnings))
1268 (byte-compile-close-variables 1297 )
1269 (save-excursion 1298 (byte-compile-close-variables
1270 (setq outbuffer
1271 (set-buffer (get-buffer-create " *Compiler Output*")))
1272 (erase-buffer)
1273 ;; (emacs-lisp-mode)
1274 (setq case-fold-search nil)
1275
1276 ;; This is a kludge. Some operating systems (OS/2, DOS) need to
1277 ;; write files containing binary information specially.
1278 ;; Under most circumstances, such files will be in binary
1279 ;; overwrite mode, so those OS's use that flag to guess how
1280 ;; they should write their data. Advise them that .elc files
1281 ;; need to be written carefully.
1282 (setq overwrite-mode 'overwrite-mode-binary))
1283 (displaying-byte-compile-warnings
1284 (save-excursion 1299 (save-excursion
1285 (set-buffer inbuffer) 1300 (setq outbuffer
1286 (goto-char 1) 1301 (set-buffer (get-buffer-create " *Compiler Output*")))
1287 (while (progn 1302 (erase-buffer)
1288 (while (progn (skip-chars-forward " \t\n\^l") 1303 ;; (emacs-lisp-mode)
1289 (looking-at ";")) 1304 (setq case-fold-search nil)
1290 (forward-line 1)) 1305
1291 (not (eobp))) 1306 ;; This is a kludge. Some operating systems (OS/2, DOS) need to
1292 (byte-compile-file-form (read inbuffer))) 1307 ;; write files containing binary information specially.
1293 ;; Compile pending forms at end of file. 1308 ;; Under most circumstances, such files will be in binary
1294 (byte-compile-flush-pending) 1309 ;; overwrite mode, so those OS's use that flag to guess how
1295 (and (not eval) (byte-compile-insert-header)) 1310 ;; they should write their data. Advise them that .elc files
1296 (byte-compile-warn-about-unresolved-functions) 1311 ;; need to be written carefully.
1297 ;; always do this? When calling multiple files, it 1312 (setq overwrite-mode 'overwrite-mode-binary))
1298 ;; would be useful to delay this warning until all have 1313 (displaying-byte-compile-warnings
1299 ;; been compiled. 1314 (save-excursion
1300 (setq byte-compile-unresolved-functions nil))) 1315 (set-buffer inbuffer)
1301 (save-excursion 1316 (goto-char 1)
1302 (set-buffer outbuffer) 1317 (while (progn
1303 (goto-char (point-min))))) 1318 (while (progn (skip-chars-forward " \t\n\^l")
1304 (if (not eval) 1319 (looking-at ";"))
1305 outbuffer 1320 (forward-line 1))
1306 (while (condition-case nil 1321 (not (eobp)))
1307 (progn (setq form (read outbuffer)) 1322 (byte-compile-file-form (read inbuffer)))
1308 t) 1323 ;; Compile pending forms at end of file.
1309 (end-of-file nil)) 1324 (byte-compile-flush-pending)
1310 (eval form)) 1325 (and (not eval) (byte-compile-insert-header))
1311 (kill-buffer outbuffer) 1326 (byte-compile-warn-about-unresolved-functions)
1312 nil))) 1327 ;; always do this? When calling multiple files, it
1328 ;; would be useful to delay this warning until all have
1329 ;; been compiled.
1330 (setq byte-compile-unresolved-functions nil)))
1331 (save-excursion
1332 (set-buffer outbuffer)
1333 (goto-char (point-min)))))
1334 (if (not eval)
1335 outbuffer
1336 (while (condition-case nil
1337 (progn (setq form (read outbuffer))
1338 t)
1339 (end-of-file nil))
1340 (eval form))
1341 (kill-buffer outbuffer)
1342 nil))))
1313 1343
1314(defun byte-compile-insert-header () 1344(defun byte-compile-insert-header ()
1315 (save-excursion 1345 (save-excursion
@@ -1786,23 +1816,24 @@ If FORM is a lambda or a macro, byte-compile it as a function."
1786 ;; 'progn or t -> a list of forms, 1816 ;; 'progn or t -> a list of forms,
1787 ;; 'lambda -> body of a lambda, 1817 ;; 'lambda -> body of a lambda,
1788 ;; 'file -> used at file-level. 1818 ;; 'file -> used at file-level.
1789 (let ((byte-compile-constants nil) 1819 (byte-compile-protect-from-advice
1790 (byte-compile-variables nil) 1820 (let ((byte-compile-constants nil)
1791 (byte-compile-tag-number 0) 1821 (byte-compile-variables nil)
1792 (byte-compile-depth 0) 1822 (byte-compile-tag-number 0)
1793 (byte-compile-maxdepth 0) 1823 (byte-compile-depth 0)
1794 (byte-compile-output nil)) 1824 (byte-compile-maxdepth 0)
1795 (if (memq byte-optimize '(t source)) 1825 (byte-compile-output nil))
1796 (setq form (byte-optimize-form form for-effect))) 1826 (if (memq byte-optimize '(t source))
1797 (while (and (eq (car-safe form) 'progn) (null (cdr (cdr form)))) 1827 (setq form (byte-optimize-form form for-effect)))
1798 (setq form (nth 1 form))) 1828 (while (and (eq (car-safe form) 'progn) (null (cdr (cdr form))))
1799 (if (and (eq 'byte-code (car-safe form)) 1829 (setq form (nth 1 form)))
1800 (not (memq byte-optimize '(t byte))) 1830 (if (and (eq 'byte-code (car-safe form))
1801 (stringp (nth 1 form)) (vectorp (nth 2 form)) 1831 (not (memq byte-optimize '(t byte)))
1802 (natnump (nth 3 form))) 1832 (stringp (nth 1 form)) (vectorp (nth 2 form))
1803 form 1833 (natnump (nth 3 form)))
1804 (byte-compile-form form for-effect) 1834 form
1805 (byte-compile-out-toplevel for-effect output-type)))) 1835 (byte-compile-form form for-effect)
1836 (byte-compile-out-toplevel for-effect output-type)))))
1806 1837
1807(defun byte-compile-out-toplevel (&optional for-effect output-type) 1838(defun byte-compile-out-toplevel (&optional for-effect output-type)
1808 (if for-effect 1839 (if for-effect