From: Andrea Corallo Date: Sun, 8 Sep 2019 13:40:56 +0000 (+0200) Subject: fix lambda handling and add a test for that X-Git-Tag: emacs-28.0.90~2727^2~1203 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=555450c7b1b1c02126bd9fc86486090fe2b829b5;p=emacs.git fix lambda handling and add a test for that --- diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 3d4b76b988b..f82993956b7 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -565,9 +565,8 @@ Each element is (INDEX . VALUE)") ;; These are use by comp.el to spill data out of here (defvar byte-native-compiling nil) -(defvar byte-to-native-names nil) -(defvar byte-to-native-lap-output nil) -(defvar byte-to-native-bytecode-output nil) +(defvar byte-last-lap nil) +(defvar byte-to-native-output nil) (defvar byte-to-native-top-level-forms nil) @@ -2274,9 +2273,8 @@ QUOTED says that we have to put a quote before the list that represents a doc string reference. `defvaralias', `autoload' and `custom-declare-variable' need that." (when byte-native-compiling - ;; Spill output for the native compiler here - (push name byte-to-native-names) - (push (apply #'vector form) byte-to-native-bytecode-output)) + ;; Spill output for the native compiler here + (push (list name byte-last-lap (apply #'vector form)) byte-to-native-output)) ;; We need to examine byte-compile-dynamic-docstrings ;; in the input buffer (now current), not in the output buffer. (let ((dynamic-docstrings byte-compile-dynamic-docstrings)) @@ -3131,7 +3129,7 @@ for symbols generated by the byte compiler itself." byte-compile-vector byte-compile-maxdepth))) (when byte-native-compiling ;; Spill output for the native compiler here - (push byte-compile-output byte-to-native-lap-output)) + (setq byte-last-lap byte-compile-output)) out)) ;; it's a trivial function ((cdr body) (cons 'progn (nreverse body))) diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el index 3ea500416de..39f00c57921 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -281,23 +281,18 @@ Put PREFIX in front of it." (defun comp-spill-lap-functions-file (filename) "Byte compile FILENAME spilling data from the byte compiler." (byte-compile-file filename) - (cl-assert (= (length byte-to-native-names) - (length byte-to-native-lap-output) - (length byte-to-native-bytecode-output))) (setf (comp-ctxt-top-level-defvars comp-ctxt) (mapcar (lambda (x) (if (eq (car x) 'defvar) (cdr x) (cl-assert nil))) byte-to-native-top-level-forms)) - (cl-loop for function-name in byte-to-native-names - for lap in byte-to-native-lap-output - for bytecode in byte-to-native-bytecode-output + (cl-loop for (name lap bytecode) in byte-to-native-output for lambda-list = (aref bytecode 0) - for func = (make-comp-func :symbol-name function-name + for func = (make-comp-func :symbol-name name :byte-func bytecode :c-func-name (comp-c-func-name - function-name + name "F") :args (comp-decrypt-lambda-list lambda-list) :lap lap @@ -311,9 +306,8 @@ Put PREFIX in front of it." If INPUT is a symbol this is the function-name to be compiled. If INPUT is a string this is the file path to be compiled." (let ((byte-native-compiling t) - (byte-to-native-names ()) - (byte-to-native-lap-output ()) - (byte-to-native-bytecode-output ()) + (byte-last-lap nil) + (byte-to-native-output ()) (byte-to-native-top-level-forms ())) (cl-typecase input (symbol (list (comp-spill-lap-function input))) diff --git a/test/src/comp-test-funcs.el b/test/src/comp-test-funcs.el index 6d7311088ad..609147e7e28 100644 --- a/test/src/comp-test-funcs.el +++ b/test/src/comp-test-funcs.el @@ -216,6 +216,9 @@ ;; (insert "foo") ;; (buffer-string))) +(defun comp-tests-lambda-return-f () + (lambda (x) (1+ x))) + ;;;;;;;;;;;;;;;;;;;; ;; Tromey's tests ;; ;;;;;;;;;;;;;;;;;;;; diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index ea1aab6e4c9..47ae7899c69 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el @@ -256,6 +256,9 @@ (ert-deftest comp-tests-buffer () (should (string= (comp-tests-buff0-f) "foo"))) +(ert-deftest comp-tests-lambda-return () + (should (= (funcall (comp-tests-lambda-return-f) 3) 4))) + ;;;;;;;;;;;;;;;;;;;; ;; Tromey's tests ;; ;;;;;;;;;;;;;;;;;;;;