From 49f2f894d68503d002efe9711bbb6e046ae18ea3 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 19 Aug 2008 22:58:48 +0000 Subject: [PATCH] fix non-tail self call with lots of args svn: r11347 --- src/mzscheme/src/jit.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/mzscheme/src/jit.c b/src/mzscheme/src/jit.c index c925dce5ed..d27f78ae46 100644 --- a/src/mzscheme/src/jit.c +++ b/src/mzscheme/src/jit.c @@ -2287,6 +2287,25 @@ static int is_a_procedure(Scheme_Object *v, mz_jit_state *jitter) return 0; } +static int generate_nontail_self_setup(mz_jit_state *jitter) +{ + void *pp, **pd; + pp = jit_patchable_movi_p(JIT_R2, jit_forward()); + pd = (void **)scheme_malloc(2 * sizeof(void *)); + pd[0] = pp; + pd[1] = jitter->patch_depth; + jitter->patch_depth = pd; + (void)jit_patchable_movi_p(JIT_R0, jitter->self_nontail_code); +#ifdef JIT_PRECISE_GC + /* Get this closure's pointer from the run stack */ + { + int depth = jitter->depth + jitter->extra_pushed - 1; + jit_ldxi_p(JIT_V1, JIT_RUNSTACK, WORDS_TO_BYTES(depth)); + } +#endif + return 0; +} + static int generate_app(Scheme_App_Rec *app, Scheme_Object **alt_rands, int num_rands, mz_jit_state *jitter, int is_tail, int multi_ok) { @@ -2542,8 +2561,12 @@ static int generate_app(Scheme_App_Rec *app, Scheme_Object **alt_rands, int num_ } else { if (direct_prim) generate_direct_prim_non_tail_call(jitter, num_rands, multi_ok, 0); - else + else { + if (nontail_self) { + generate_nontail_self_setup(jitter); + } generate_non_tail_call(jitter, num_rands, direct_native, jitter->need_set_rs, multi_ok, nontail_self, 0); + } } } else { /* Jump to code to implement a tail call for num_rands arguments */ @@ -2579,20 +2602,7 @@ static int generate_app(Scheme_App_Rec *app, Scheme_Object **alt_rands, int num_ code = shared_non_tail_code[dp][num_rands][mo]; if (nontail_self) { - void *pp, **pd; - pp = jit_patchable_movi_p(JIT_R2, jit_forward()); - pd = (void **)scheme_malloc(2 * sizeof(void *)); - pd[0] = pp; - pd[1] = jitter->patch_depth; - jitter->patch_depth = pd; - (void)jit_patchable_movi_p(JIT_R0, jitter->self_nontail_code); -#ifdef JIT_PRECISE_GC - /* Get this closure's pointer from the run stack */ - { - int depth = jitter->depth + jitter->extra_pushed - 1; - jit_ldxi_p(JIT_V1, JIT_RUNSTACK, WORDS_TO_BYTES(depth)); - } -#endif + generate_nontail_self_setup(jitter); } (void)jit_calli(code);