diff options
| author | Andrea Corallo | 2019-08-10 22:13:45 +0200 |
|---|---|---|
| committer | Andrea Corallo | 2020-01-01 11:33:58 +0100 |
| commit | df59970cc41cee834f2432a18a098ec7de16f7ae (patch) | |
| tree | bf8deec9d4e086812e4214c5843d42386ac72149 /src/comp.c | |
| parent | a42d67628942244b0cb90276c4e0ec77e967c0bc (diff) | |
| download | emacs-df59970cc41cee834f2432a18a098ec7de16f7ae.tar.gz emacs-df59970cc41cee834f2432a18a098ec7de16f7ae.zip | |
improve routine dispatcher
Diffstat (limited to 'src/comp.c')
| -rw-r--r-- | src/comp.c | 122 |
1 files changed, 65 insertions, 57 deletions
diff --git a/src/comp.c b/src/comp.c index 3a9fbe733da..37264039edf 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -152,6 +152,20 @@ static comp_t comp; | |||
| 152 | 152 | ||
| 153 | FILE *logfile = NULL; | 153 | FILE *logfile = NULL; |
| 154 | 154 | ||
| 155 | |||
| 156 | |||
| 157 | Lisp_Object helper_save_window_excursion (Lisp_Object v1); | ||
| 158 | |||
| 159 | void helper_unwind_protect (Lisp_Object handler); | ||
| 160 | |||
| 161 | Lisp_Object helper_temp_output_buffer_setup (Lisp_Object x); | ||
| 162 | |||
| 163 | Lisp_Object helper_unbind_n (int val); | ||
| 164 | |||
| 165 | bool helper_PSEUDOVECTOR_TYPEP_XUNTAG (const union vectorlike_header *a, | ||
| 166 | enum pvec_type code); | ||
| 167 | |||
| 168 | |||
| 155 | static char * ATTRIBUTE_FORMAT_PRINTF (1, 2) | 169 | static char * ATTRIBUTE_FORMAT_PRINTF (1, 2) |
| 156 | format_string (const char *format, ...) | 170 | format_string (const char *format, ...) |
| 157 | { | 171 | { |
| @@ -234,10 +248,9 @@ declare_block (const char * block_name) | |||
| 234 | } | 248 | } |
| 235 | 249 | ||
| 236 | static void | 250 | static void |
| 237 | register_dispatch (const char *name, void *func) | 251 | register_dispatch (Lisp_Object key, void *func) |
| 238 | { | 252 | { |
| 239 | Lisp_Object key = make_string (name, strlen (name)); | 253 | Lisp_Object value = make_mint_ptr (func); |
| 240 | Lisp_Object value = make_pointer_integer (XPL (func)); | ||
| 241 | Fputhash (key, value, comp.routine_dispatcher); | 254 | Fputhash (key, value, comp.routine_dispatcher); |
| 242 | } | 255 | } |
| 243 | 256 | ||
| @@ -1098,11 +1111,11 @@ emit_limple_call (Lisp_Object args) | |||
| 1098 | Lisp_Object calle_sym = FIRST (args); | 1111 | Lisp_Object calle_sym = FIRST (args); |
| 1099 | char *calle = (char *) SDATA (SYMBOL_NAME (calle_sym)); | 1112 | char *calle = (char *) SDATA (SYMBOL_NAME (calle_sym)); |
| 1100 | Lisp_Object emitter = | 1113 | Lisp_Object emitter = |
| 1101 | Fgethash (SYMBOL_NAME (calle_sym), comp.routine_dispatcher, Qnil); | 1114 | Fgethash (calle_sym, comp.routine_dispatcher, Qnil); |
| 1102 | 1115 | ||
| 1103 | if (!NILP (emitter)) | 1116 | if (!NILP (emitter)) |
| 1104 | { | 1117 | { |
| 1105 | gcc_jit_rvalue * (* emitter_ptr) (Lisp_Object) = XFIXNUMPTR (emitter); | 1118 | gcc_jit_rvalue * (* emitter_ptr) (Lisp_Object) = xmint_pointer (emitter); |
| 1106 | return emitter_ptr (args); | 1119 | return emitter_ptr (args); |
| 1107 | } | 1120 | } |
| 1108 | else if (calle[0] == 'F') | 1121 | else if (calle[0] == 'F') |
| @@ -2045,6 +2058,14 @@ DEFUN ("comp-init-ctxt", Fcomp_init_ctxt, Scomp_init_ctxt, | |||
| 2045 | return Qnil; | 2058 | return Qnil; |
| 2046 | } | 2059 | } |
| 2047 | 2060 | ||
| 2061 | if (NILP (comp.routine_dispatcher)) | ||
| 2062 | { | ||
| 2063 | /* Move this into syms_of_comp the day will be dumpable. */ | ||
| 2064 | comp.routine_dispatcher = CALLN (Fmake_hash_table); | ||
| 2065 | register_dispatch (Qset_internal, emit_set_internal); | ||
| 2066 | register_dispatch (Qhelper_unbind_n, helper_unbind_n); | ||
| 2067 | } | ||
| 2068 | |||
| 2048 | comp.ctxt = gcc_jit_context_acquire(); | 2069 | comp.ctxt = gcc_jit_context_acquire(); |
| 2049 | comp.funcs = Qnil; | 2070 | comp.funcs = Qnil; |
| 2050 | 2071 | ||
| @@ -2349,64 +2370,12 @@ DEFUN ("comp-compile-and-load-ctxt", Fcomp_compile_and_load_ctxt, | |||
| 2349 | return Qt; | 2370 | return Qt; |
| 2350 | } | 2371 | } |
| 2351 | 2372 | ||
| 2352 | void | ||
| 2353 | syms_of_comp (void) | ||
| 2354 | { | ||
| 2355 | /* Limple instruction set. */ | ||
| 2356 | DEFSYM (Qcomment, "comment"); | ||
| 2357 | DEFSYM (Qjump, "jump"); | ||
| 2358 | DEFSYM (Qcall, "call"); | ||
| 2359 | DEFSYM (Qcallref, "callref"); | ||
| 2360 | DEFSYM (Qncall, "ncall"); | ||
| 2361 | DEFSYM (Qsetpar, "setpar"); | ||
| 2362 | DEFSYM (Qncall_prolog, "ncall-prolog"); | ||
| 2363 | DEFSYM (Qsetimm, "setimm"); | ||
| 2364 | DEFSYM (Qreturn, "return"); | ||
| 2365 | DEFSYM (Qcomp_mvar, "comp-mvar"); | ||
| 2366 | DEFSYM (Qcond_jump, "cond-jump"); | ||
| 2367 | DEFSYM (Qpush_handler, "push-handler"); | ||
| 2368 | DEFSYM (Qpop_handler, "pop-handler"); | ||
| 2369 | DEFSYM (Qcondition_case, "condition-case"); | ||
| 2370 | DEFSYM (Qcatcher, "catcher"); | ||
| 2371 | |||
| 2372 | defsubr (&Scomp_init_ctxt); | ||
| 2373 | defsubr (&Scomp_release_ctxt); | ||
| 2374 | defsubr (&Scomp_add_func_to_ctxt); | ||
| 2375 | defsubr (&Scomp_compile_and_load_ctxt); | ||
| 2376 | comp.func_hash = Qnil; | ||
| 2377 | comp.routine_dispatcher = Qnil; | ||
| 2378 | staticpro (&comp.func_hash); | ||
| 2379 | staticpro (&comp.func_blocks); | ||
| 2380 | |||
| 2381 | comp.routine_dispatcher = CALLN (Fmake_hash_table, QCtest, Qequal); | ||
| 2382 | register_dispatch ("set_internal", emit_set_internal); | ||
| 2383 | register_dispatch ("helper_unbind_n", emit_simple_limple_call); | ||
| 2384 | staticpro (&comp.routine_dispatcher); | ||
| 2385 | |||
| 2386 | DEFVAR_INT ("comp-speed", comp_speed, | ||
| 2387 | doc: /* From 0 to 3. */); | ||
| 2388 | comp_speed = DEFAULT_SPEED; | ||
| 2389 | |||
| 2390 | } | ||
| 2391 | |||
| 2392 | 2373 | ||
| 2393 | /******************************************************************************/ | 2374 | /******************************************************************************/ |
| 2394 | /* Helper functions called from the runtime. */ | 2375 | /* Helper functions called from the runtime. */ |
| 2395 | /* These can't be statics till shared mechanism is used to solve relocations. */ | 2376 | /* These can't be statics till shared mechanism is used to solve relocations. */ |
| 2396 | /******************************************************************************/ | 2377 | /******************************************************************************/ |
| 2397 | 2378 | ||
| 2398 | /* TODO: cleanup */ | ||
| 2399 | |||
| 2400 | Lisp_Object helper_save_window_excursion (Lisp_Object v1); | ||
| 2401 | |||
| 2402 | void helper_unwind_protect (Lisp_Object handler); | ||
| 2403 | |||
| 2404 | Lisp_Object helper_temp_output_buffer_setup (Lisp_Object x); | ||
| 2405 | |||
| 2406 | Lisp_Object helper_unbind_n (int val); | ||
| 2407 | |||
| 2408 | bool helper_PSEUDOVECTOR_TYPEP_XUNTAG (const union vectorlike_header *a, | ||
| 2409 | enum pvec_type code); | ||
| 2410 | Lisp_Object | 2379 | Lisp_Object |
| 2411 | helper_save_window_excursion (Lisp_Object v1) | 2380 | helper_save_window_excursion (Lisp_Object v1) |
| 2412 | { | 2381 | { |
| @@ -2448,4 +2417,43 @@ helper_PSEUDOVECTOR_TYPEP_XUNTAG (const union vectorlike_header *a, | |||
| 2448 | code); | 2417 | code); |
| 2449 | } | 2418 | } |
| 2450 | 2419 | ||
| 2420 | void | ||
| 2421 | syms_of_comp (void) | ||
| 2422 | { | ||
| 2423 | /* Limple instruction set. */ | ||
| 2424 | DEFSYM (Qcomment, "comment"); | ||
| 2425 | DEFSYM (Qjump, "jump"); | ||
| 2426 | DEFSYM (Qcall, "call"); | ||
| 2427 | DEFSYM (Qcallref, "callref"); | ||
| 2428 | DEFSYM (Qncall, "ncall"); | ||
| 2429 | DEFSYM (Qsetpar, "setpar"); | ||
| 2430 | DEFSYM (Qncall_prolog, "ncall-prolog"); | ||
| 2431 | DEFSYM (Qsetimm, "setimm"); | ||
| 2432 | DEFSYM (Qreturn, "return"); | ||
| 2433 | DEFSYM (Qcomp_mvar, "comp-mvar"); | ||
| 2434 | DEFSYM (Qcond_jump, "cond-jump"); | ||
| 2435 | DEFSYM (Qpush_handler, "push-handler"); | ||
| 2436 | DEFSYM (Qpop_handler, "pop-handler"); | ||
| 2437 | DEFSYM (Qcondition_case, "condition-case"); | ||
| 2438 | DEFSYM (Qcatcher, "catcher"); | ||
| 2439 | DEFSYM (Qset_internal, "set_internal"); | ||
| 2440 | DEFSYM (Qhelper_unbind_n, "helper_unbind_n"); | ||
| 2441 | |||
| 2442 | defsubr (&Scomp_init_ctxt); | ||
| 2443 | defsubr (&Scomp_release_ctxt); | ||
| 2444 | defsubr (&Scomp_add_func_to_ctxt); | ||
| 2445 | defsubr (&Scomp_compile_and_load_ctxt); | ||
| 2446 | staticpro (&comp.func_hash); | ||
| 2447 | staticpro (&comp.func_blocks); | ||
| 2448 | comp.func_hash = Qnil; | ||
| 2449 | comp.routine_dispatcher = Qnil; | ||
| 2450 | |||
| 2451 | staticpro (&comp.routine_dispatcher); | ||
| 2452 | comp.routine_dispatcher = Qnil; | ||
| 2453 | |||
| 2454 | DEFVAR_INT ("comp-speed", comp_speed, | ||
| 2455 | doc: /* From 0 to 3. */); | ||
| 2456 | comp_speed = DEFAULT_SPEED; | ||
| 2457 | } | ||
| 2458 | |||
| 2451 | #endif /* HAVE_LIBGCCJIT */ | 2459 | #endif /* HAVE_LIBGCCJIT */ |