diff options
author | Stefan Monnier <monnier@IRO.UMontreal.CA> | 2017-07-14 00:32:34 -0400 |
---|---|---|
committer | Noam Postavsky <npostavs@gmail.com> | 2017-08-07 18:54:49 -0400 |
commit | cc30d77ecdd1b9155ade3d0656a84a0839ee2795 (patch) | |
tree | a0b0c1180b8152284d10420d4189eb7cebdbc7d7 /lisp/emacs-lisp | |
parent | 00f7e31110a27e568529192d7441d9631b9096bc (diff) | |
download | emacs-cc30d77ecdd1b9155ade3d0656a84a0839ee2795.tar.gz emacs-cc30d77ecdd1b9155ade3d0656a84a0839ee2795.tar.bz2 emacs-cc30d77ecdd1b9155ade3d0656a84a0839ee2795.zip |
Let `define-symbol-prop' take effect during compilation
* src/fns.c (syms_of_fns): New variable `overriding-plist-environment'.
(Fget): Consult it.
* lisp/emacs-lisp/bytecomp.el (byte-compile-close-variables): Let-bind
it to nil.
(byte-compile-define-symbol-prop): New function, handles compilation
of top-level `define-symbol-prop' and `function-put' calls by putting
the symbol setting into `overriding-plist-environment'.
Co-authored-by: Noam Postavsky <npostavs@gmail.com>
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/bytecomp.el | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 5fa7389e431..9e14c91c953 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -1572,6 +1572,7 @@ extra args." ;; macroenvironment. (copy-alist byte-compile-initial-macro-environment)) (byte-compile--outbuffer nil) + (overriding-plist-environment nil) (byte-compile-function-environment nil) (byte-compile-bound-variables nil) (byte-compile-lexical-variables nil) @@ -4714,6 +4715,34 @@ binding slots have been popped." 'byte-hunk-handler 'byte-compile-form-make-variable-buffer-local) (defun byte-compile-form-make-variable-buffer-local (form) (byte-compile-keep-pending form 'byte-compile-normal-call)) + +(put 'function-put 'byte-hunk-handler 'byte-compile-define-symbol-prop) +(put 'define-symbol-prop 'byte-hunk-handler 'byte-compile-define-symbol-prop) +(defun byte-compile-define-symbol-prop (form) + (pcase form + ((and `(,op ,fun ,prop ,val) + (guard (and (macroexp-const-p fun) + (macroexp-const-p prop) + (or (macroexp-const-p val) + ;; Also accept anonymous functions, since + ;; we're at top-level which implies they're + ;; also constants. + (pcase val (`(function (lambda . ,_)) t)))))) + (byte-compile-push-constant op) + (byte-compile-form fun) + (byte-compile-form prop) + (let* ((fun (eval fun)) + (prop (eval prop)) + (val (if (macroexp-const-p val) + (eval val) + (byte-compile-lambda (cadr val))))) + (push `(,fun + . (,prop ,val ,@(alist-get fun overriding-plist-environment))) + overriding-plist-environment) + (byte-compile-push-constant val) + (byte-compile-out 'byte-call 3))) + + (_ (byte-compile-keep-pending form)))) ;;; tags |