]> git.eshelyaron.com Git - emacs.git/commitdiff
move away from modules
authorAndrea Corallo <andrea_corallo@yahoo.it>
Sun, 18 Aug 2019 19:48:49 +0000 (21:48 +0200)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:37:39 +0000 (11:37 +0100)
src/comp.c
src/emacs-module.c
src/lread.c

index 953a1dd9d0fa29eb39f05f4006fe4c8a21915d32..5233a72aa5d6b12c472ae53eb335c026f69defbd 100644 (file)
@@ -31,6 +31,7 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 #include "bytecode.h"
 #include "atimer.h"
 #include "window.h"
+#include "dynlib.h"
 
 #define DEFAULT_SPEED 2 /* See comp-speed var.  */
 
@@ -2555,11 +2556,6 @@ DEFUN ("comp--init-ctxt", Fcomp__init_ctxt, Scomp__init_ctxt,
   define_add1_sub1 ();
   define_negate ();
 
-  gcc_jit_context_new_global (comp.ctxt,
-                             NULL,
-                             GCC_JIT_GLOBAL_EXPORTED,
-                             comp.int_type,
-                             "native_compiled_emacs_lisp");
   return Qt;
 }
 
@@ -2699,7 +2695,7 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file,
       gcc_jit_context_dump_to_file (comp.ctxt, filename, 1);
     }
 
-  AUTO_STRING (dot_so, ".so"); /* FIXME use correct var */
+  AUTO_STRING (dot_so, NATIVE_ELISP_SUFFIX);
   const char *filename =
     (const char *) SDATA (CALLN (Fconcat, ctxtname, dot_so));
 
@@ -2830,6 +2826,81 @@ helper_set_data_relocs (Lisp_Object *d_relocs_vec, char const *relocs)
 {
 }
 
+\f
+
+/************************************/
+/* Native compiler load functions.  */
+/************************************/
+
+typedef char *(*comp_litt_str_func) (void);
+
+static Lisp_Object
+comp_retrive_obj (dynlib_handle_ptr handle, const char *str_name)
+{
+  comp_litt_str_func f = dynlib_sym (handle, str_name);
+  char *res = f();
+  return Fread (build_string (res));
+}
+
+static int
+load_comp_unit (dynlib_handle_ptr handle)
+{
+  Lisp_Object *data_relocs = dynlib_sym (handle, "data_relocs");
+
+  Lisp_Object d_vec = comp_retrive_obj (handle, "text_data_relocs");
+  EMACS_UINT d_vec_len = XFIXNUM (Flength (d_vec));
+
+  for (EMACS_UINT i = 0; i < d_vec_len; i++)
+    data_relocs[i] = AREF (d_vec, i);
+
+  Lisp_Object func_list = comp_retrive_obj (handle, "text_funcs");
+
+  while (func_list)
+    {
+      Lisp_Object el = XCAR (func_list);
+      Lisp_Object Qsym = AREF (el, 0);
+      char *c_func_name = SSDATA (AREF (el, 1));
+      Lisp_Object args = AREF (el, 2);
+      ptrdiff_t minargs = XFIXNUM (XCAR (args));
+      ptrdiff_t maxargs = FIXNUMP (XCDR (args)) ? XFIXNUM (XCDR (args)) : MANY;
+      /* char *doc = SSDATA (AREF (el, 3)); */
+      void *func = dynlib_sym (handle, c_func_name);
+      eassert (func);
+
+      union Aligned_Lisp_Subr *x = xmalloc (sizeof (union Aligned_Lisp_Subr));
+      x->s.header.size = PVEC_SUBR << PSEUDOVECTOR_AREA_BITS;
+      x->s.function.a0 = func;
+      x->s.min_args = minargs;
+      x->s.max_args = maxargs;
+      x->s.symbol_name = SSDATA (Fsymbol_name (Qsym));
+      defsubr(x);
+
+      func_list = XCDR (func_list);
+    }
+
+  return 0;
+}
+
+/* Load related routines. */
+DEFUN ("native-elisp-load", Fnative_elisp_load, Snative_elisp_load, 1, 1, 0,
+       doc: /* Load native elisp code FILE.  */)
+  (Lisp_Object file)
+{
+  dynlib_handle_ptr handle;
+
+  CHECK_STRING (file);
+  handle = dynlib_open (SSDATA (file));
+  if (!handle)
+    xsignal2 (Qcomp_unit_open_failed, file, build_string (dynlib_error ()));
+
+  int r = load_comp_unit (handle);
+
+  if (r != 0)
+    xsignal2 (Qcomp_unit_init_failed, file, INT_TO_INTEGER (r));
+
+  return Qt;
+}
+
 \f
 void
 syms_of_comp (void)
@@ -2874,11 +2945,15 @@ syms_of_comp (void)
   DEFSYM (Qnegate, "negate");
   DEFSYM (QFnumberp, "Fnumberp");
   DEFSYM (QFintegerp, "Fintegerp");
+  /* Returned values.  */
+  DEFSYM (Qcomp_unit_open_failed, "comp-unit-open-failed");
+  DEFSYM (Qcomp_unit_init_failed, "comp-unit-init-failed");
 
   defsubr (&Scomp__init_ctxt);
   defsubr (&Scomp__release_ctxt);
   defsubr (&Scomp__add_func_to_ctxt);
   defsubr (&Scomp__compile_ctxt_to_file);
+  defsubr (&Snative_elisp_load);
 
   staticpro (&comp.func_hash);
   comp.func_hash = Qnil;
index e14ef89d8f9ff4fdb535fc0222871c089ba31e3a..bbb0e3dadd94e44497476c29759857ab7e74546e 100644 (file)
@@ -944,64 +944,6 @@ module_signal_or_throw (struct emacs_env_private *env)
     }
 }
 
-\f
-/*
-  Native compiler load functions.
-  FIXME: Move away from here.
-*/
-
-typedef char *(*comp_litt_str_func) (void);
-
-static Lisp_Object
-comp_retrive_obj (dynlib_handle_ptr handle, const char *str_name)
-{
-  comp_litt_str_func f = dynlib_sym (handle, str_name);
-  char *res = f();
-  return Fread (build_string (res));
-}
-
-static int
-comp_load_unit (dynlib_handle_ptr handle, emacs_env *env)
-{
-  Lisp_Object *data_relocs = dynlib_sym (handle, "data_relocs");
-
-  Lisp_Object d_vec = comp_retrive_obj (handle, "text_data_relocs");
-  EMACS_UINT d_vec_len = XFIXNUM (Flength (d_vec));
-
-  for (EMACS_UINT i = 0; i < d_vec_len; i++)
-    data_relocs[i] = AREF (d_vec, i);
-
-  Lisp_Object func_list = comp_retrive_obj (handle, "text_funcs");
-
-  while (func_list)
-    {
-      Lisp_Object el = XCAR (func_list);
-      Lisp_Object Qsym = AREF (el, 0);
-      char *c_func_name = SSDATA (AREF (el, 1));
-      Lisp_Object args = AREF (el, 2);
-      ptrdiff_t minargs = XFIXNUM (XCAR (args));
-      ptrdiff_t maxargs = FIXNUMP (XCDR (args)) ? XFIXNUM (XCDR (args)) : MANY;
-      /* char *doc = SSDATA (AREF (el, 3)); */
-      void *func = dynlib_sym (handle, c_func_name);
-      eassert (func);
-      /* Ffset (Qsym, */
-      /*            value_to_lisp (module_make_function (env, minargs, maxargs, func, */
-      /*                                                 doc, NULL))); */
-
-      union Aligned_Lisp_Subr *x = xmalloc (sizeof (union Aligned_Lisp_Subr));
-      x->s.header.size = PVEC_SUBR << PSEUDOVECTOR_AREA_BITS;
-      x->s.function.a0 = func;
-      x->s.min_args = minargs;
-      x->s.max_args = maxargs;
-      x->s.symbol_name = SSDATA (Fsymbol_name (Qsym));
-      defsubr(x);
-
-      func_list = XCDR (func_list);
-    }
-
-  return 0;
-}
-
 /* Live runtime and environment objects, for assertions.  */
 static Lisp_Object Vmodule_runtimes;
 static Lisp_Object Vmodule_environments;
@@ -1012,7 +954,7 @@ DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0,
 {
   dynlib_handle_ptr handle;
   emacs_init_function module_init;
-  void *gpl_sym, *native_comp;
+  void *gpl_sym;
 
   CHECK_STRING (file);
   handle = dynlib_open (SSDATA (file));
@@ -1020,17 +962,13 @@ DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0,
     xsignal2 (Qmodule_open_failed, file, build_string (dynlib_error ()));
 
   gpl_sym = dynlib_sym (handle, "plugin_is_GPL_compatible");
-  native_comp = dynlib_sym (handle, "native_compiled_emacs_lisp");
-  if (!gpl_sym && !native_comp)
+  if (!gpl_sym)
     xsignal1 (Qmodule_not_gpl_compatible, file);
 
-  if (!native_comp)
-    {
-      module_init =
-       (emacs_init_function) dynlib_func (handle, "emacs_module_init");
-      if (!module_init)
-       xsignal1 (Qmissing_module_init_function, file);
-    }
+  module_init = (emacs_init_function) dynlib_func (handle, "emacs_module_init");
+  if (!module_init)
+    xsignal1 (Qmissing_module_init_function, file);
+
   struct emacs_runtime rt_pub;
   struct emacs_runtime_private rt_priv;
   emacs_env env_pub;
@@ -1051,7 +989,7 @@ DEFUN ("module-load", Fmodule_load, Smodule_load, 1, 1, 0,
   ptrdiff_t count = SPECPDL_INDEX ();
   record_unwind_protect_ptr (finalize_runtime_unwind, rt);
 
-  int r = native_comp ? comp_load_unit (handle, &env_pub) : module_init (rt);
+  int r = module_init (rt);
 
   /* Process the quit flag first, so that quitting doesn't get
      overridden by other non-local exits.  */
index ca7b29f690b01520f6b25e7c043837b52f10925a..1a5074cb70bdd8f2ecae5a6e51c46f6dea69f118 100644 (file)
@@ -1281,6 +1281,11 @@ Return t if the file exists and loads successfully.  */)
   bool is_module = false;
 #endif
 
+#ifdef HAVE_LIBGCCJIT
+  bool is_native_elisp = suffix_p (found, NATIVE_ELISP_SUFFIX);
+#else
+  bool is_native_elisp = false;
+#endif
   /* Check if we're stuck in a recursive load cycle.
 
      2000-09-21: It's not possible to just check for the file loaded
@@ -1379,7 +1384,7 @@ Return t if the file exists and loads successfully.  */)
             } /* !load_prefer_newer */
        }
     }
-  else if (!is_module)
+  else if (!is_module && !is_native_elisp)
     {
       /* We are loading a source file (*.el).  */
       if (!NILP (Vload_source_file_function))
@@ -1406,7 +1411,7 @@ Return t if the file exists and loads successfully.  */)
       stream = NULL;
       errno = EINVAL;
     }
-  else if (!is_module)
+  else if (!is_module && !is_native_elisp)
     {
 #ifdef WINDOWSNT
       emacs_close (fd);
@@ -1422,7 +1427,7 @@ Return t if the file exists and loads successfully.  */)
      might be accessed by the unbind_to call below.  */
   struct infile input;
 
-  if (is_module)
+  if (is_module || is_native_elisp)
     {
       /* `module-load' uses the file name, so we can close the stream
          now.  */
@@ -1452,6 +1457,8 @@ Return t if the file exists and loads successfully.  */)
                 file, 1);
       else if (is_module)
         message_with_string ("Loading %s (module)...", file, 1);
+      else if (is_native_elisp)
+        message_with_string ("Loading %s (native compiled elisp)...", file, 1);
       else if (!compiled)
        message_with_string ("Loading %s (source)...", file, 1);
       else if (newer)
@@ -1475,6 +1482,18 @@ Return t if the file exists and loads successfully.  */)
 #else
       /* This cannot happen.  */
       emacs_abort ();
+#endif
+    }
+  else if (is_native_elisp)
+    {
+#ifdef HAVE_LIBGCCJIT
+      specbind (Qcurrent_load_list, Qnil);
+      LOADHIST_ATTACH (found);
+      Fnative_elisp_load (found);
+      build_load_history (found, true);
+#else
+      /* This cannot happen.  */
+      emacs_abort ();
 #endif
     }
   else
@@ -4866,21 +4885,19 @@ This list includes suffixes for both compiled and source Emacs Lisp files.
 This list should not include the empty string.
 `load' and related functions try to append these suffixes, in order,
 to the specified file name if a suffix is allowed or required.  */);
+  Vload_suffixes = list2 (build_pure_c_string (".elc"),
+                         build_pure_c_string (".el"));
 #ifdef HAVE_MODULES
+  Vload_suffixes = Fcons (build_pure_c_string (MODULES_SUFFIX), Vload_suffixes);
 #ifdef MODULES_SECONDARY_SUFFIX
-  Vload_suffixes = list4 (build_pure_c_string (".elc"),
-                         build_pure_c_string (".el"),
-                         build_pure_c_string (MODULES_SUFFIX),
-                          build_pure_c_string (MODULES_SECONDARY_SUFFIX));
-#else
-  Vload_suffixes = list3 (build_pure_c_string (".elc"),
-                         build_pure_c_string (".el"),
-                         build_pure_c_string (MODULES_SUFFIX));
+  Vload_suffixes =
+    Fcons (build_pure_c_string (MODULES_SECONDARY_SUFFIX), Vload_suffixes);
 #endif
-#else
-  Vload_suffixes = list2 (build_pure_c_string (".elc"),
-                         build_pure_c_string (".el"));
 #endif
+#ifdef HAVE_LIBGCCJIT
+  Vload_suffixes = Fcons (build_pure_c_string (NATIVE_ELISP_SUFFIX), Vload_suffixes);
+#endif
+
   DEFVAR_LISP ("module-file-suffix", Vmodule_file_suffix,
               doc: /* Suffix of loadable module file, or nil if modules are not supported.  */);
 #ifdef HAVE_MODULES