diff options
author | Andy Wingo <wingo@pobox.com> | 2010-02-26 13:05:25 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2010-02-26 13:05:25 +0100 |
commit | adbdfd6d2418b1404af48d480c2273f501517d6e (patch) | |
tree | 9624620bcedfbdd1cc29a9454b2cbcfdebdf808b /libguile/vm.c | |
parent | 416f26c7534a018c59f1c8d888dc9153f42d86d1 (diff) | |
download | guile-adbdfd6d2418b1404af48d480c2273f501517d6e.tar.gz |
rewinding prompts works
* libguile/control.h (SCM_PROMPT_HANDLER): Remove, it was unused.
(SCM_PROMPT_DYNWINDS): Rename from SCM_PROMPT_DYNENV.
* libguile/control.c: (scm_c_make_prompt): Take another arg, the winds
that are to be in place for the prompt. Fix allocation to be 4 words
instead of 5 (the handler was never used).
* libguile/eval.c (eval):
* libguile/throw.c (pre_init_catch): Adapt to scm_c_make_prompt change.
* libguile/vm-i-system.c (partial-cont-call): Grovel the new elements of
the wind list in order to call setjmp() on the new prompts. Pass
cookie to vm_reinstate_partial_continuation.
(prompt): Adapt to scm_c_make_prompt change.
* libguile/vm.c (vm_reinstate_partial_continuation): Take a cookie arg,
used when winding captured prompts onto the stack. Winding a prompt
implies making a new prompt, actually -- with new registers, a new
jump buffer, new winds, etc.
* test-suite/tests/control.test ("rewinding prompts"): Add a test for
rewinding prompts.
Diffstat (limited to 'libguile/vm.c')
-rw-r--r-- | libguile/vm.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/libguile/vm.c b/libguile/vm.c index 85e0e7ada..142061185 100644 --- a/libguile/vm.c +++ b/libguile/vm.c @@ -231,7 +231,7 @@ vm_abort (SCM vm, size_t n, scm_t_int64 vm_cookie) static void vm_reinstate_partial_continuation (SCM vm, SCM cont, SCM intwinds, - size_t n, SCM *argv) + size_t n, SCM *argv, scm_t_int64 vm_cookie) { struct scm_vm *vp; struct scm_vm_cont *cp; @@ -267,8 +267,6 @@ vm_reinstate_partial_continuation (SCM vm, SCM cont, SCM intwinds, vp->fp = RELOC (cp->fp); vp->ip = cp->mvra; -#undef RELOC - /* now push args. ip is in a MV context. */ for (i = 0; i < n; i++) { @@ -278,14 +276,32 @@ vm_reinstate_partial_continuation (SCM vm, SCM cont, SCM intwinds, vp->sp++; *vp->sp = scm_from_size_t (n); - /* Finally, rewind the dynamic state. */ + /* Finally, rewind the dynamic state. + + We have to treat prompts specially, because we could be rewinding the + dynamic state from a different thread, or just a different position on the + C and/or VM stack -- so we need to reset the jump buffers so that an abort + comes back here, with appropriately adjusted sp and fp registers. */ { long delta = 0; SCM newwinds = scm_i_dynwinds (); for (; scm_is_pair (intwinds); intwinds = scm_cdr (intwinds), delta--) - newwinds = scm_cons (scm_car (intwinds), newwinds); + { + SCM x = scm_car (intwinds); + if (SCM_PROMPT_P (x)) + /* the jmpbuf will be reset by our caller */ + x = scm_c_make_prompt (SCM_PROMPT_TAG (x), + RELOC (SCM_PROMPT_REGISTERS (x)->fp), + RELOC (SCM_PROMPT_REGISTERS (x)->sp), + SCM_PROMPT_REGISTERS (x)->ip, + SCM_PROMPT_ESCAPE_P (x), + vm_cookie, + newwinds); + newwinds = scm_cons (x, newwinds); + } scm_dowinds (newwinds, delta); } +#undef RELOC } |