(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)))
(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)))
/**************************************/
static Lisp_Object Vnative_elisp_refs_hash;
-static Lisp_Object load_handle_stack;
-
static void
prevent_gc (Lisp_Object obj)
{
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
*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);
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;
}
= 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 */