]> git.eshelyaron.com Git - emacs.git/commitdiff
basic file compilation working
authorAndrea Corallo <akrl@sdf.org>
Sat, 7 Sep 2019 09:17:02 +0000 (11:17 +0200)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:37:44 +0000 (11:37 +0100)
lisp/emacs-lisp/bytecomp.el
lisp/emacs-lisp/comp.el
src/comp.c

index 736f4f62235e5419c644f5ddc4de14e0ff7f2cda..ec7b036a67714bc69e3066f4abe86d7bf3b1b521 100644 (file)
@@ -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)))
index cfaf453932dc6ed5fadb8926405889beb16413b5..1a426560ba56998f4a28383a901b06a5e5c98a96 100644 (file)
@@ -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)))))
 
 \f
 ;;; 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)
index 905cc70b6b38606cd9ea7992cc75e1bbdfeaf854..07c779369c80d0d6448235ef61433ddc72343168 100644 (file)
@@ -3057,9 +3057,9 @@ helper_PSEUDOVECTOR_TYPEP_XUNTAG (const union vectorlike_header *a,
 }
 
 \f
-/*********************************/
-/* Native elisp load functions.  */
-/*********************************/
+/**************************************/
+/* Functions used to load eln files.  */
+/**************************************/
 
 static Lisp_Object Vnative_elisp_refs_hash;