From b5d5cacbde80f968cbbc1bf08da79e6fe846aeaf Mon Sep 17 00:00:00 2001 From: Juan Jose Garcia Ripoll Date: Tue, 25 May 2010 19:42:44 +0200 Subject: [PATCH] Use a hash to seek the compilation strategies in the interpreter --- src/c/compiler.d | 23 +++++++++++++++++++---- src/c/main.d | 1 + src/h/external.h | 2 ++ src/h/internal.h | 2 -- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/c/compiler.d b/src/c/compiler.d index 9e2ab8220..568888486 100644 --- a/src/c/compiler.d +++ b/src/c/compiler.d @@ -2070,7 +2070,6 @@ static int compile_form(cl_env_ptr env, cl_object stmt, int flags) { const cl_compiler_ptr c_env = env->c_env; cl_object code_walker = ECL_SYM_VAL(env, @'si::*code-walker*'); - compiler_record *l; cl_object function; bool push = flags & FLAG_PUSH; int new_flags; @@ -2131,9 +2130,10 @@ compile_form(cl_env_ptr env, cl_object stmt, int flags) { stmt = ECL_CONS_CAR(stmt); goto QUOTED; } - for (l = database; l->symbol != OBJNULL; l++) { - /*cl_print(1, l->symbol);*/ - if (l->symbol == function) { + { + cl_object index = ecl_gethash(function, cl_core.compiler_dispatch); + if (index != OBJNULL) { + compiler_record *l = database + fix(index); c_env->lexical_level += l->lexical_increment; if (c_env->stepping && function != @'function' && c_env->lexical_level) @@ -2890,3 +2890,18 @@ si_make_lambda(cl_object name, cl_object rest) return output; } @) + +void +init_compiler() +{ + cl_object dispatch_table = + cl_core.compiler_dispatch = + cl__make_hash_table(@'eq', MAKE_FIXNUM(128), /* size */ + ecl_make_singlefloat(1.5f), /* rehash-size */ + ecl_make_singlefloat(0.5f), /* rehash-threshold */ + Cnil); /* thread-safe */ + int i; + for (i = 0; database[i].symbol; i++) { + ecl_sethash(database[i].symbol, dispatch_table, MAKE_FIXNUM(i)); + } +} diff --git a/src/c/main.d b/src/c/main.d index 5325f0d35..14dbb4e70 100644 --- a/src/c/main.d +++ b/src/c/main.d @@ -677,6 +677,7 @@ cl_boot(int argc, char **argv) ECL_SET(@'si::*load-hooks*', aux); init_error(); init_macros(); + init_compiler(); /* * Set up infrastructure for CLOS. diff --git a/src/h/external.h b/src/h/external.h index 7ffcd7ef5..3d51b6be9 100755 --- a/src/h/external.h +++ b/src/h/external.h @@ -243,6 +243,8 @@ struct cl_core_struct { cl_object reused_indices; #endif cl_object slash; + + cl_object compiler_dispatch; }; extern ECL_API struct cl_core_struct cl_core; diff --git a/src/h/internal.h b/src/h/internal.h index e2a1d048c..d564b5da7 100644 --- a/src/h/internal.h +++ b/src/h/internal.h @@ -43,9 +43,7 @@ extern void init_read(void); extern void init_stacks(cl_env_ptr); extern void init_unixint(int pass); extern void init_unixtime(void); -#if defined(__MINGW32__) extern void init_compiler(void); -#endif #ifdef ECL_THREADS extern void init_threads(cl_env_ptr); #endif