diff options
author | Andy Wingo <wingo@pobox.com> | 2009-12-13 17:05:10 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-12-13 17:19:59 +0100 |
commit | 9331f91cc411fc2a09a59308bb889f3f5f735e49 (patch) | |
tree | fe3bf6d8a0590c7118aaaa99de51eb7c61d014b8 /libguile/memoize.c | |
parent | 4abb824cdbd5f16a836da8ab75cc24a6a53f3b35 (diff) | |
download | guile-9331f91cc411fc2a09a59308bb889f3f5f735e49.tar.gz |
primitive-eval passes first N args on stack directly, not via apply
* libguile/memoize.c (MAKMEMO_CALL): Memoize in the number of arguments
at the call site.
(memoize, scm_m_cond, memoize_named_let, unmemoize):
* libguile/eval.c (eval): Adapt to changes in call memoization.
* module/ice-9/eval.scm (primitive-eval): For calls, pass the first N
arguments directly on the stack, and only the rest as a consed
argument list to apply. Currently N is 4.
Diffstat (limited to 'libguile/memoize.c')
-rw-r--r-- | libguile/memoize.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/libguile/memoize.c b/libguile/memoize.c index ae3bbea16..c544f21b0 100644 --- a/libguile/memoize.c +++ b/libguile/memoize.c @@ -207,8 +207,8 @@ scm_t_bits scm_tc16_memoized; MAKMEMO (SCM_M_CONT, proc) #define MAKMEMO_CALL_WITH_VALUES(prod, cons) \ MAKMEMO (SCM_M_CALL_WITH_VALUES, scm_cons (prod, cons)) -#define MAKMEMO_CALL(proc, args) \ - MAKMEMO (SCM_M_CALL, scm_cons (proc, args)) +#define MAKMEMO_CALL(proc, nargs, args) \ + MAKMEMO (SCM_M_CALL, scm_cons (proc, scm_cons (SCM_I_MAKINUM (nargs), args))) #define MAKMEMO_LEX_REF(n) \ MAKMEMO (SCM_M_LEXICAL_REF, SCM_I_MAKINUM (n)) #define MAKMEMO_LEX_SET(n, val) \ @@ -345,11 +345,15 @@ memoize (SCM exp, SCM env) return trans (exp, env); else { + SCM proc; SCM args = SCM_EOL; - for (; scm_is_pair (exp); exp = CDR (exp)) + int nargs = 0; + proc = memoize (CAR (exp), env); + for (exp = CDR (exp); scm_is_pair (exp); exp = CDR (exp), nargs++) args = scm_cons (memoize (CAR (exp), env), args); if (scm_is_null (exp)) - return MAKMEMO (SCM_M_CALL, scm_reverse_x (args, SCM_UNDEFINED)); + return MAKMEMO_CALL (proc, nargs, + scm_reverse_x (args, SCM_UNDEFINED)); else syntax_error ("expected a proper list", exp, SCM_UNDEFINED); } @@ -566,6 +570,7 @@ scm_m_cond (SCM expr, SCM env) i = MAKMEMO_IF (MAKMEMO_LEX_REF (0), MAKMEMO_CALL (memoize (CADDR (clause), scm_cons (tmp, new_env)), + 1, scm_list_1 (MAKMEMO_LEX_REF (0))), MAKMEMO_QUOTE (SCM_UNSPECIFIED)); SCM_SETCDR (loc, @@ -793,6 +798,7 @@ memoize_named_let (const SCM expr, SCM env) memoize_sequence (CDDDR (expr), memoize_env_extend (env, rvariables)))), MAKMEMO_CALL (MAKMEMO_LEX_REF (0), + nreq, memoize_exprs (inits, env))))); } @@ -1054,7 +1060,7 @@ unmemoize (const SCM expr) case SCM_M_BEGIN: return scm_cons (scm_sym_begin, unmemoize_exprs (args)); case SCM_M_CALL: - return unmemoize_exprs (args); + return scm_cons (unmemoize (CAR (args)), unmemoize_exprs (CDDR (args))); case SCM_M_CONT: return scm_list_2 (scm_sym_atcall_cc, unmemoize (args)); case SCM_M_CALL_WITH_VALUES: |