]> git.eshelyaron.com Git - emacs.git/commitdiff
split final pass + some code rework
authorAndrea Corallo <akrl@sdf.org>
Sat, 7 Sep 2019 06:57:07 +0000 (08:57 +0200)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:37:44 +0000 (11:37 +0100)
lisp/emacs-lisp/comp.el

index d7f6f606e885261d572fc474ab510c26ccae2ef9..cfaf453932dc6ed5fadb8926405889beb16413b5 100644 (file)
@@ -52,7 +52,8 @@
   "Every pass has the right to bind what it likes here.")
 
 (defconst comp-passes '(comp-spill-lap
-                        comp-limplify)
+                        comp-limplify
+                        comp-final)
   "Passes to be executed in order.")
 
 (defconst comp-known-ret-types '((cons . cons))
@@ -78,8 +79,9 @@
     "Hash table lap-op -> stack adjustment."))
 
 (cl-defstruct comp-ctxt
-  "This structure is to serve al relocation creation for the current compiler
- context."
+  "Lisp side of the compiler context."
+  (output nil :'string
+          :documentation "Target output filename for the compilation.")
   (funcs () :type list
          :documentation "Exported functions list.")
   (funcs-h (make-hash-table) :type hash-table
@@ -282,8 +284,7 @@ If INPUT is a string this is the file path to be compiled."
         (byte-to-native-lap-output ()))
     (cl-typecase input
       (symbol (list (comp-spill-lap-function input)))
-      (string (error "To be implemented"))
-      (otherwise (error "Trying to native compile something not a function or file")))))
+      (string (error "To be implemented")))))
 
 \f
 ;;; Limplification pass specific code.
@@ -857,10 +858,11 @@ the annotation emission."
           funcs))
 
 \f
-;;; C function wrappers
+;;; Final pass specific code.
 
 (defun comp-compile-ctxt-to-file (name)
-  "Compile as native code the current context naming it NAME."
+  "Compile as native code the current context naming it NAME.
+Prepare every functions for final compilation and drive the C side."
   (cl-assert (= (length (comp-ctxt-data-relocs-l comp-ctxt))
                 (hash-table-count (comp-ctxt-data-relocs-idx comp-ctxt))))
   (setf (comp-ctxt-funcs comp-ctxt)
@@ -883,9 +885,19 @@ the annotation emission."
   "Add FUNC to the current compiler contex."
   (puthash (comp-func-symbol-name func)
            func
-           (comp-ctxt-funcs-h comp-ctxt))
-  ;; (comp--add-func-to-ctxt func)
-  )
+           (comp-ctxt-funcs-h comp-ctxt)))
+
+(defun comp-final (data)
+  "Final pass driving DATA into the C side for code emission."
+  (let (compile-result)
+    (comp--init-ctxt)
+    (unwind-protect
+        (progn
+          (mapc #'comp-add-func-to-ctxt data)
+          (setq compile-result
+                (comp-compile-ctxt-to-file (comp-ctxt-output comp-ctxt))))
+      (and (comp--release-ctxt)
+           compile-result))))
 
 \f
 ;;; Entry points.
@@ -895,20 +907,16 @@ the annotation emission."
 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."
+  (unless (or (symbolp input)
+              (stringp input))
+    (error "Trying to native compile something not a function or file"))
   (let ((data input)
-        (comp-ctxt (make-comp-ctxt)))
+        (comp-ctxt (make-comp-ctxt :output (if (symbolp input)
+                                               (symbol-name input)
+                                             (file-name-sans-extension input)))))
     (mapc (lambda (pass)
             (setq data (funcall pass data)))
-          comp-passes)
-    ;; Once we have the final LIMPLE we jump into C.
-    (comp--init-ctxt)
-    (unwind-protect
-        (progn
-          (mapc #'comp-add-func-to-ctxt data)
-          (comp-compile-ctxt-to-file (if (symbolp input)
-                                         (symbol-name input)
-                                       (file-name-sans-extension input))))
-      (comp--release-ctxt))))
+          comp-passes)))
 
 (provide 'comp)