fix problem with continuations captured under a module-body prompt

Closes PR 11165
 where the problem was a misordering of a prompt and a stack push
This commit is contained in:
Matthew Flatt 2010-09-17 12:44:54 -06:00
parent 17ac1fae3a
commit bbde0dfbd2
3 changed files with 40 additions and 6 deletions

View File

@ -11781,6 +11781,27 @@ void scheme_pop_prefix(Scheme_Object **rs)
MZ_RUNSTACK = rs;
}
Scheme_Object *scheme_suspend_prefix(Scheme_Object **rs)
{
if (rs != MZ_RUNSTACK) {
Scheme_Object *v;
v = MZ_RUNSTACK[0];
MZ_RUNSTACK++;
return v;
} else
return NULL;
}
Scheme_Object **scheme_resume_prefix(Scheme_Object *v)
{
if (v) {
--MZ_RUNSTACK;
MZ_RUNSTACK[0] = v;
return MZ_RUNSTACK + 1;
} else
return MZ_RUNSTACK;
}
/*========================================================================*/
/* bytecode validation */
/*========================================================================*/

View File

@ -4565,9 +4565,15 @@ static void eval_module_body(Scheme_Env *menv, Scheme_Env *env)
#endif
}
static Scheme_Object *body_one_expr(void *expr, int argc, Scheme_Object **argv)
static Scheme_Object *body_one_expr(void *prefix_plus_expr, int argc, Scheme_Object **argv)
{
return _scheme_eval_linked_expr_multi((Scheme_Object *)expr);
Scheme_Object *v, **saved_runstack;
saved_runstack = scheme_resume_prefix(SCHEME_CAR((Scheme_Object *)prefix_plus_expr));
v = _scheme_eval_linked_expr_multi(SCHEME_CDR((Scheme_Object *)prefix_plus_expr));
scheme_suspend_prefix(saved_runstack);
return v;
}
static int needs_prompt(Scheme_Object *e)
@ -4607,7 +4613,7 @@ void *scheme_module_run_finish(Scheme_Env *menv, Scheme_Env *env)
{
Scheme_Thread *p;
Scheme_Module *m = menv->module;
Scheme_Object *body, **save_runstack;
Scheme_Object *body, **save_runstack, *save_prefix;
int depth;
int i, cnt;
Scheme_Cont_Frame_Data cframe;
@ -4659,9 +4665,14 @@ void *scheme_module_run_finish(Scheme_Env *menv, Scheme_Env *env)
cnt = SCHEME_VEC_SIZE(m->body);
for (i = 0; i < cnt; i++) {
body = SCHEME_VEC_ELS(m->body)[i];
if (needs_prompt(body))
(void)_scheme_call_with_prompt_multi(body_one_expr, body);
else
if (needs_prompt(body)) {
/* We need to push the prefix after the prompt is set, so
restore the runstack and then add the prefix back. */
save_prefix = scheme_suspend_prefix(save_runstack);
(void)_scheme_call_with_prompt_multi(body_one_expr,
scheme_make_raw_pair(save_prefix, body));
scheme_resume_prefix(save_prefix);
} else
(void)_scheme_eval_linked_expr_multi(body);
}

View File

@ -2730,6 +2730,8 @@ Scheme_Object **scheme_push_prefix(Scheme_Env *genv, Resolve_Prefix *rp,
int src_phase, int now_phase,
Scheme_Env *dummy_env);
void scheme_pop_prefix(Scheme_Object **rs);
Scheme_Object *scheme_suspend_prefix(Scheme_Object **rs);
Scheme_Object **scheme_resume_prefix(Scheme_Object *v);
Scheme_Object *scheme_eval_clone(Scheme_Object *expr);
Resolve_Prefix *scheme_prefix_eval_clone(Resolve_Prefix *rp);