]> git.eshelyaron.com Git - emacs.git/commitdiff
remove load_handle_stack and use the implementation one
authorAndrea Corallo <akrl@sdf.org>
Sun, 22 Dec 2019 08:13:46 +0000 (09:13 +0100)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:38:14 +0000 (11:38 +0100)
lisp/emacs-lisp/comp.el
src/comp.c

index 60eb9420662c1c6f6f10b6c9b985f55227a72f3b..49f25d85c0eaabcd6284464a482bbd6b009af729 100644 (file)
@@ -1073,7 +1073,10 @@ the annotation emission."
                           (make-comp-mvar :constant (comp-func-c-name f))
                           (make-comp-mvar :constant (comp-func-doc f))
                           (make-comp-mvar :constant
-                                          (comp-func-int-spec f))))))
+                                          (comp-func-int-spec f))
+                          ;; This is the compilation unit it-self passed as
+                          ;; parameter.
+                          (make-comp-mvar :slot 0)))))
 
 (cl-defmethod comp-emit-for-top-level ((form byte-to-native-top-level))
   (let ((form (byte-to-native-top-level-form form)))
@@ -1083,17 +1086,24 @@ the annotation emission."
 
 (defun comp-limplify-top-level ()
   "Create a limple function doing the business for top level forms.
-This will be called at load-time."
+This will be called at load-time.
+
+Synthesize a function called 'top_level_run' that gets one single
+parameter (the compilation unit it-self).  To define native
+functions 'top_level_run' will call back `comp--register-subr'
+into the C code forwarding the compilation unit."
   (let* ((func (make-comp-func :name 'top-level-run
                                :c-name "top_level_run"
-                               :args (make-comp-args :min 0 :max 0)
-                               :frame-size 0))
+                               :args (make-comp-args :min 1 :max 1)
+                               :frame-size 1))
          (comp-func func)
          (comp-pass (make-comp-limplify
                      :curr-block (make--comp-block -1 0 'top-level)
-                     :frame (comp-new-frame 0))))
+                     :frame (comp-new-frame 1))))
     (comp-make-curr-block 'entry (comp-sp))
     (comp-emit-annotation "Top level")
+    ;; Assign the compilation unit incoming as parameter to the slot frame 0.
+    (comp-emit `(set-par-to-local ,(comp-slot-n 0) 0))
     (mapc #'comp-emit-for-top-level (comp-ctxt-top-level-forms comp-ctxt))
     (comp-emit `(return ,(make-comp-mvar :constant t)))
     (comp-limplify-finalize-function func)))
index c74e5cf2e6c54a5a760be01f8b70752726155083..0ec0edd27ea3f313bbe2c0f36dcbceac68e12f74 100644 (file)
@@ -3204,8 +3204,6 @@ helper_PSEUDOVECTOR_TYPEP_XUNTAG (Lisp_Object a, enum pvec_type code)
 /**************************************/
 
 static Lisp_Object Vnative_elisp_refs_hash;
-static Lisp_Object load_handle_stack;
-
 static void
 prevent_gc (Lisp_Object obj)
 {
@@ -3234,7 +3232,7 @@ load_comp_unit (Lisp_Object comp_u_obj, Lisp_Object file)
   EMACS_INT ***pure_reloc = dynlib_sym (handle, PURE_RELOC_SYM);
   Lisp_Object *data_relocs = dynlib_sym (handle, DATA_RELOC_SYM);
   void **freloc_link_table = dynlib_sym (handle, IMPORTED_FUNC_LINK_TABLE);
-  void (*top_level_run)(void) = dynlib_sym (handle, "top_level_run");
+  void (*top_level_run)(Lisp_Object) = dynlib_sym (handle, "top_level_run");
 
   if (!(current_thread_reloc
        && pure_reloc
@@ -3258,19 +3256,19 @@ load_comp_unit (Lisp_Object comp_u_obj, Lisp_Object file)
   *freloc_link_table = freloc.link_table;
 
   /* Executing this will perform all the expected environment modification.  */
-  top_level_run ();
+  top_level_run (comp_u_obj);
 
   return;
 }
 
 DEFUN ("comp--register-subr", Fcomp__register_subr, Scomp__register_subr,
-       6, 6, 0,
+       7, 7, 0,
        doc: /* This gets called by top_level_run during load phase to register
               each exported subr.  */)
      (Lisp_Object name, Lisp_Object minarg, Lisp_Object maxarg,
-      Lisp_Object c_name, Lisp_Object doc, Lisp_Object intspec)
+      Lisp_Object c_name, Lisp_Object doc, Lisp_Object intspec,
+      Lisp_Object comp_u)
 {
-  Lisp_Object comp_u = XCAR (load_handle_stack);
   dynlib_handle_ptr handle = XNATIVE_COMP_UNIT (comp_u)->handle;
   if (!handle)
     xsignal0 (Qwrong_register_subr_call);
@@ -3327,14 +3325,11 @@ DEFUN ("native-elisp-load", Fnative_elisp_load, Snative_elisp_load, 1, 1, 0,
   dynlib_handle_ptr handle =
     dynlib_open (format_string ("/proc/%d/fd/%d", getpid (), fd_out));
   Lisp_Object comp_u = make_native_comp_u (fd_in, handle);
-  load_handle_stack = Fcons (comp_u, load_handle_stack);
   if (!handle)
     xsignal2 (Qnative_lisp_load_failed, file, build_string (dynlib_error ()));
 
   load_comp_unit (comp_u, file);
 
-  load_handle_stack = XCDR (load_handle_stack);
-
   return Qt;
 }
 
@@ -3461,8 +3456,6 @@ syms_of_comp (void)
     = make_hash_table (hashtest_eq, DEFAULT_HASH_SIZE,
                       DEFAULT_REHASH_SIZE, DEFAULT_REHASH_THRESHOLD,
                       Qnil, false);
-  staticpro (&load_handle_stack);
-  load_handle_stack = Qnil;
 }
 
 #endif /* HAVE_NATIVE_COMP */