aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrea Corallo2020-10-12 22:34:57 +0200
committerAndrea Corallo2020-10-14 11:04:36 +0200
commit4f0e87903095da1225830e27ef27e61ba9ff08af (patch)
treebcda9b34f6f4c4283e49861c728d9ec013a6ef35
parent8861ee8b087b4e5d9ac9186a2c2d8e44b07fc186 (diff)
downloademacs-4f0e87903095da1225830e27ef27e61ba9ff08af.tar.gz
emacs-4f0e87903095da1225830e27ef27e61ba9ff08af.zip
Rework `native-compile' interface so it can return compiled functions
* lisp/emacs-lisp/comp.el (native-compile): Return the compiled function when the input is a symbol or a form. * test/src/comp-tests.el (free-fun, tco, fw-prop): Update tests for new `native-compile' interface.
-rw-r--r--lisp/emacs-lisp/comp.el21
-rw-r--r--test/src/comp-tests.el6
2 files changed, 17 insertions, 10 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 98f552599e9..cd13c44fa91 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -2854,12 +2854,16 @@ display a message."
2854;;;###autoload 2854;;;###autoload
2855(defun native-compile (function-or-file &optional with-late-load output) 2855(defun native-compile (function-or-file &optional with-late-load output)
2856 "Compile FUNCTION-OR-FILE into native code. 2856 "Compile FUNCTION-OR-FILE into native code.
2857This is the entry-point for the Emacs Lisp native compiler. 2857This is the syncronous entry-point for the Emacs Lisp native
2858FUNCTION-OR-FILE is a function symbol or a path to an Elisp file. 2858compiler.
2859When WITH-LATE-LOAD non-nil mark the compilation unit for late load 2859FUNCTION-OR-FILE is a function symbol, a form or the
2860once finished compiling (internal use only). 2860filename of an Emacs Lisp source file.
2861When OUTPUT is non-nil use it as filename for the compiled object. 2861When WITH-LATE-LOAD non-nil mark the compilation unit for late
2862Return the compile object filename." 2862load once finished compiling (internal use only). When OUTPUT is
2863non-nil use it as filename for the compiled object.
2864If FUNCTION-OR-FILE is a filename return the filename of the
2865compiled object. If FUNCTION-OR-FILE is a function symbol or a
2866form return the compiled function."
2863 (comp-ensure-native-compiler) 2867 (comp-ensure-native-compiler)
2864 (unless (or (functionp function-or-file) 2868 (unless (or (functionp function-or-file)
2865 (stringp function-or-file)) 2869 (stringp function-or-file))
@@ -2888,7 +2892,10 @@ Return the compile object filename."
2888 (signal (car err) (if (consp err-val) 2892 (signal (car err) (if (consp err-val)
2889 (cons function-or-file err-val) 2893 (cons function-or-file err-val)
2890 (list function-or-file err-val)))))) 2894 (list function-or-file err-val))))))
2891 data)) 2895 (if (stringp function-or-file)
2896 data
2897 ;; So we return the compiled function.
2898 (native-elisp-load data))))
2892 2899
2893;;;###autoload 2900;;;###autoload
2894(defun batch-native-compile () 2901(defun batch-native-compile ()
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el
index 317a6113af2..79bac3f711f 100644
--- a/test/src/comp-tests.el
+++ b/test/src/comp-tests.el
@@ -359,7 +359,7 @@ Check that the resulting binaries do not differ."
359 (interactive) 359 (interactive)
360 3) 360 3)
361 t) 361 t)
362 (load (native-compile #'comp-tests-free-fun-f)) 362 (native-compile #'comp-tests-free-fun-f)
363 363
364 (should (subr-native-elisp-p (symbol-function #'comp-tests-free-fun-f))) 364 (should (subr-native-elisp-p (symbol-function #'comp-tests-free-fun-f)))
365 (should (= (comp-tests-free-fun-f) 3)) 365 (should (= (comp-tests-free-fun-f) 3))
@@ -692,7 +692,7 @@ CHECKER should always return nil to have a pass."
692 b 692 b
693 (comp-tests-tco-f (+ a b) a (- count 1)))) 693 (comp-tests-tco-f (+ a b) a (- count 1))))
694 t) 694 t)
695 (load (native-compile #'comp-tests-tco-f)) 695 (native-compile #'comp-tests-tco-f)
696 (should (subr-native-elisp-p (symbol-function #'comp-tests-tco-f))) 696 (should (subr-native-elisp-p (symbol-function #'comp-tests-tco-f)))
697 (should (= (comp-tests-tco-f 1 0 10) 55)))) 697 (should (= (comp-tests-tco-f 1 0 10) 55))))
698 698
@@ -714,7 +714,7 @@ CHECKER should always return nil to have a pass."
714 (c (concat a b))) ; <= has to optimize 714 (c (concat a b))) ; <= has to optimize
715 (length c))) ; <= has to optimize 715 (length c))) ; <= has to optimize
716 t) 716 t)
717 (load (native-compile #'comp-tests-fw-prop-1-f)) 717 (native-compile #'comp-tests-fw-prop-1-f)
718 (should (subr-native-elisp-p (symbol-function #'comp-tests-fw-prop-1-f))) 718 (should (subr-native-elisp-p (symbol-function #'comp-tests-fw-prop-1-f)))
719 (should (= (comp-tests-fw-prop-1-f) 6)))) 719 (should (= (comp-tests-fw-prop-1-f) 6))))
720 720