From: Andrea Corallo Date: Sat, 7 Sep 2019 09:17:02 +0000 (+0200) Subject: basic file compilation working X-Git-Tag: emacs-28.0.90~2727^2~1208 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=29fcb6ca1280fc01c652dcecc331b20cd88a5729;p=emacs.git basic file compilation working --- diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 736f4f62235..ec7b036a677 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -563,8 +563,9 @@ Each element is (INDEX . VALUE)") (defvar byte-compile-depth 0 "Current depth of execution stack.") (defvar byte-compile-maxdepth 0 "Maximum depth of execution stack.") -;; These are use by comp.el to spill +;; 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) @@ -2271,6 +2272,10 @@ we output that argument and the following argument 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)) ;; 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)) @@ -3121,9 +3126,8 @@ for symbols generated by the byte compiler itself." (out (list 'byte-code (byte-compile-lapcode byte-compile-output) 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) - (push out byte-to-native-bytecode-output)) + ;; Spill output for the native compiler here + (push byte-compile-output byte-to-native-lap-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 cfaf453932d..1a426560ba5 100644 --- a/lisp/emacs-lisp/comp.el +++ b/lisp/emacs-lisp/comp.el @@ -243,6 +243,8 @@ Put PREFIX in front of it." (defun comp-decrypt-lambda-list (x) "Decript lambda list X." + (unless (fixnump x) + (error "Can't native compile a non lexical scoped function")) (let ((rest (not (= (logand x 128) 0))) (mandatory (logand x 127)) (nonrest (ash x -8))) @@ -254,7 +256,7 @@ Put PREFIX in front of it." :nonrest nonrest)))) (defun comp-spill-lap-function (function-name) - "Spill LAP for FUNCTION-NAME." + "Byte compile FUNCTION-NAME spilling data from the byte compiler." (let* ((f (symbol-function function-name)) (func (make-comp-func :symbol-name function-name :func f @@ -268,23 +270,45 @@ Put PREFIX in front of it." (comp-within-log-buff (cl-prettyprint byte-to-native-lap-output)) (let ((lambda-list (aref (comp-func-byte-func func) 0))) - (if (fixnump lambda-list) - (setf (comp-func-args func) - (comp-decrypt-lambda-list lambda-list)) - (error "Can't native compile a non lexical scoped function"))) + (setf (comp-func-args func) + (comp-decrypt-lambda-list lambda-list))) (setf (comp-func-lap func) (car byte-to-native-lap-output)) (setf (comp-func-frame-size func) (aref (comp-func-byte-func func) 3)) func)) +(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))) + (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 + for lambda-list = (aref bytecode 0) + for func = (make-comp-func :symbol-name function-name + :byte-func bytecode + :c-func-name (comp-c-func-name + function-name + "F") + :args (comp-decrypt-lambda-list lambda-list) + :lap lap + :frame-size (aref bytecode 3)) + do (comp-within-log-buff + (cl-prettyprint lap)) + collect func)) + (defun comp-spill-lap (input) "Byte compile and spill the LAP rapresentation for INPUT. 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-lap-output ())) + (byte-to-native-names ()) + (byte-to-native-lap-output ()) + (byte-to-native-bytecode-output ())) (cl-typecase input (symbol (list (comp-spill-lap-function input))) - (string (error "To be implemented"))))) + (string (comp-spill-lap-functions-file input))))) ;;; Limplification pass specific code. @@ -905,11 +929,11 @@ Prepare every functions for final compilation and drive the C side." (defun native-compile (input) "Compile INPUT into native code. This is the entrypoint for the Emacs Lisp native compiler. -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." +If INPUT is a symbol, native-compile its function definition. +If INPUT is a string, use it as the file path to be native compiled." (unless (or (symbolp input) (stringp input)) - (error "Trying to native compile something not a function or file")) + (error "Trying to native compile something not a symbol function or file")) (let ((data input) (comp-ctxt (make-comp-ctxt :output (if (symbolp input) (symbol-name input) diff --git a/src/comp.c b/src/comp.c index 905cc70b6b3..07c779369c8 100644 --- a/src/comp.c +++ b/src/comp.c @@ -3057,9 +3057,9 @@ helper_PSEUDOVECTOR_TYPEP_XUNTAG (const union vectorlike_header *a, } -/*********************************/ -/* Native elisp load functions. */ -/*********************************/ +/**************************************/ +/* Functions used to load eln files. */ +/**************************************/ static Lisp_Object Vnative_elisp_refs_hash;