aboutsummaryrefslogtreecommitdiffstats
path: root/src/comp.c
diff options
context:
space:
mode:
authorAndrea Corallo2019-08-18 21:48:49 +0200
committerAndrea Corallo2020-01-01 11:37:39 +0100
commit70a7c65742244403422d7c3e4b79a2046c1cefb7 (patch)
tree4b3a1b27ddf699dcdcfb3cad3d5103550493d563 /src/comp.c
parentc8a0b81f8ffe093910dd3ad2852dd47a15587d9e (diff)
downloademacs-70a7c65742244403422d7c3e4b79a2046c1cefb7.tar.gz
emacs-70a7c65742244403422d7c3e4b79a2046c1cefb7.zip
move away from modules
Diffstat (limited to 'src/comp.c')
-rw-r--r--src/comp.c87
1 files changed, 81 insertions, 6 deletions
diff --git a/src/comp.c b/src/comp.c
index 953a1dd9d0f..5233a72aa5d 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -31,6 +31,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
31#include "bytecode.h" 31#include "bytecode.h"
32#include "atimer.h" 32#include "atimer.h"
33#include "window.h" 33#include "window.h"
34#include "dynlib.h"
34 35
35#define DEFAULT_SPEED 2 /* See comp-speed var. */ 36#define DEFAULT_SPEED 2 /* See comp-speed var. */
36 37
@@ -2555,11 +2556,6 @@ DEFUN ("comp--init-ctxt", Fcomp__init_ctxt, Scomp__init_ctxt,
2555 define_add1_sub1 (); 2556 define_add1_sub1 ();
2556 define_negate (); 2557 define_negate ();
2557 2558
2558 gcc_jit_context_new_global (comp.ctxt,
2559 NULL,
2560 GCC_JIT_GLOBAL_EXPORTED,
2561 comp.int_type,
2562 "native_compiled_emacs_lisp");
2563 return Qt; 2559 return Qt;
2564} 2560}
2565 2561
@@ -2699,7 +2695,7 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file,
2699 gcc_jit_context_dump_to_file (comp.ctxt, filename, 1); 2695 gcc_jit_context_dump_to_file (comp.ctxt, filename, 1);
2700 } 2696 }
2701 2697
2702 AUTO_STRING (dot_so, ".so"); /* FIXME use correct var */ 2698 AUTO_STRING (dot_so, NATIVE_ELISP_SUFFIX);
2703 const char *filename = 2699 const char *filename =
2704 (const char *) SDATA (CALLN (Fconcat, ctxtname, dot_so)); 2700 (const char *) SDATA (CALLN (Fconcat, ctxtname, dot_so));
2705 2701
@@ -2831,6 +2827,81 @@ helper_set_data_relocs (Lisp_Object *d_relocs_vec, char const *relocs)
2831} 2827}
2832 2828
2833 2829
2830
2831/************************************/
2832/* Native compiler load functions. */
2833/************************************/
2834
2835typedef char *(*comp_litt_str_func) (void);
2836
2837static Lisp_Object
2838comp_retrive_obj (dynlib_handle_ptr handle, const char *str_name)
2839{
2840 comp_litt_str_func f = dynlib_sym (handle, str_name);
2841 char *res = f();
2842 return Fread (build_string (res));
2843}
2844
2845static int
2846load_comp_unit (dynlib_handle_ptr handle)
2847{
2848 Lisp_Object *data_relocs = dynlib_sym (handle, "data_relocs");
2849
2850 Lisp_Object d_vec = comp_retrive_obj (handle, "text_data_relocs");
2851 EMACS_UINT d_vec_len = XFIXNUM (Flength (d_vec));
2852
2853 for (EMACS_UINT i = 0; i < d_vec_len; i++)
2854 data_relocs[i] = AREF (d_vec, i);
2855
2856 Lisp_Object func_list = comp_retrive_obj (handle, "text_funcs");
2857
2858 while (func_list)
2859 {
2860 Lisp_Object el = XCAR (func_list);
2861 Lisp_Object Qsym = AREF (el, 0);
2862 char *c_func_name = SSDATA (AREF (el, 1));
2863 Lisp_Object args = AREF (el, 2);
2864 ptrdiff_t minargs = XFIXNUM (XCAR (args));
2865 ptrdiff_t maxargs = FIXNUMP (XCDR (args)) ? XFIXNUM (XCDR (args)) : MANY;
2866 /* char *doc = SSDATA (AREF (el, 3)); */
2867 void *func = dynlib_sym (handle, c_func_name);
2868 eassert (func);
2869
2870 union Aligned_Lisp_Subr *x = xmalloc (sizeof (union Aligned_Lisp_Subr));
2871 x->s.header.size = PVEC_SUBR << PSEUDOVECTOR_AREA_BITS;
2872 x->s.function.a0 = func;
2873 x->s.min_args = minargs;
2874 x->s.max_args = maxargs;
2875 x->s.symbol_name = SSDATA (Fsymbol_name (Qsym));
2876 defsubr(x);
2877
2878 func_list = XCDR (func_list);
2879 }
2880
2881 return 0;
2882}
2883
2884/* Load related routines. */
2885DEFUN ("native-elisp-load", Fnative_elisp_load, Snative_elisp_load, 1, 1, 0,
2886 doc: /* Load native elisp code FILE. */)
2887 (Lisp_Object file)
2888{
2889 dynlib_handle_ptr handle;
2890
2891 CHECK_STRING (file);
2892 handle = dynlib_open (SSDATA (file));
2893 if (!handle)
2894 xsignal2 (Qcomp_unit_open_failed, file, build_string (dynlib_error ()));
2895
2896 int r = load_comp_unit (handle);
2897
2898 if (r != 0)
2899 xsignal2 (Qcomp_unit_init_failed, file, INT_TO_INTEGER (r));
2900
2901 return Qt;
2902}
2903
2904
2834void 2905void
2835syms_of_comp (void) 2906syms_of_comp (void)
2836{ 2907{
@@ -2874,11 +2945,15 @@ syms_of_comp (void)
2874 DEFSYM (Qnegate, "negate"); 2945 DEFSYM (Qnegate, "negate");
2875 DEFSYM (QFnumberp, "Fnumberp"); 2946 DEFSYM (QFnumberp, "Fnumberp");
2876 DEFSYM (QFintegerp, "Fintegerp"); 2947 DEFSYM (QFintegerp, "Fintegerp");
2948 /* Returned values. */
2949 DEFSYM (Qcomp_unit_open_failed, "comp-unit-open-failed");
2950 DEFSYM (Qcomp_unit_init_failed, "comp-unit-init-failed");
2877 2951
2878 defsubr (&Scomp__init_ctxt); 2952 defsubr (&Scomp__init_ctxt);
2879 defsubr (&Scomp__release_ctxt); 2953 defsubr (&Scomp__release_ctxt);
2880 defsubr (&Scomp__add_func_to_ctxt); 2954 defsubr (&Scomp__add_func_to_ctxt);
2881 defsubr (&Scomp__compile_ctxt_to_file); 2955 defsubr (&Scomp__compile_ctxt_to_file);
2956 defsubr (&Snative_elisp_load);
2882 2957
2883 staticpro (&comp.func_hash); 2958 staticpro (&comp.func_hash);
2884 comp.func_hash = Qnil; 2959 comp.func_hash = Qnil;