diff --git a/libguile/continuations.c b/libguile/continuations.c index 6caceca53..fc47d9b40 100644 --- a/libguile/continuations.c +++ b/libguile/continuations.c @@ -191,7 +191,7 @@ continuation_print (SCM obj, SCM port, scm_print_state *state SCM_UNUSED) continuation. */ #define FUNC_NAME "scm_i_make_continuation" SCM -scm_i_make_continuation (int *first) +scm_i_make_continuation (int *first, SCM vm, SCM vm_cont) { scm_i_thread *thread = SCM_I_CURRENT_THREAD; SCM cont; @@ -214,7 +214,8 @@ scm_i_make_continuation (int *first) #endif continuation->offset = continuation->stack - src; memcpy (continuation->stack, src, sizeof (SCM_STACKITEM) * stack_size); - continuation->vm_conts = scm_vm_capture_continuations (); + continuation->vm = vm; + continuation->vm_cont = vm_cont; SCM_NEWSMOB (cont, tc16_continuation, continuation); @@ -265,13 +266,10 @@ scm_i_continuation_to_frame (SCM continuation) contregs = scm_c_vector_ref (scm_program_objects (continuation), 0); cont = SCM_CONTREGS (contregs); - if (!scm_is_null (cont->vm_conts)) + if (scm_is_true (cont->vm_cont)) { - SCM vm_cont; - struct scm_vm_cont *data; - vm_cont = scm_cdr (scm_car (cont->vm_conts)); - data = SCM_VM_CONT_DATA (vm_cont); - return scm_c_make_frame (vm_cont, + struct scm_vm_cont *data = SCM_VM_CONT_DATA (cont->vm_cont); + return scm_c_make_frame (cont->vm_cont, data->fp + data->reloc, data->sp + data->reloc, data->ip, @@ -334,7 +332,8 @@ copy_stack (void *data) copy_stack_data *d = (copy_stack_data *)data; memcpy (d->dst, d->continuation->stack, sizeof (SCM_STACKITEM) * d->continuation->num_stack_items); - scm_vm_reinstate_continuations (d->continuation->vm_conts); + scm_i_vm_reinstate_continuation (d->continuation->vm, + d->continuation->vm_cont); #ifdef __ia64__ SCM_I_CURRENT_THREAD->pending_rbs_continuation = d->continuation; #endif diff --git a/libguile/continuations.h b/libguile/continuations.h index 93b8dc750..a9d2feee0 100644 --- a/libguile/continuations.h +++ b/libguile/continuations.h @@ -53,7 +53,8 @@ typedef struct #endif /* __ia64__ */ size_t num_stack_items; /* size of the saved stack. */ SCM root; /* continuation root identifier. */ - SCM vm_conts; /* vm continuations (they use separate stacks) */ + SCM vm; /* vm */ + SCM vm_cont; /* vm's stack and regs */ /* The offset from the live stack location to this copy. This is used to adjust pointers from within the copied stack to the stack @@ -71,7 +72,7 @@ typedef struct -SCM_INTERNAL SCM scm_i_make_continuation (int *first); +SCM_INTERNAL SCM scm_i_make_continuation (int *first, SCM vm, SCM vm_cont); SCM_INTERNAL SCM scm_i_call_with_current_continuation (SCM proc); SCM_INTERNAL SCM scm_i_continuation_to_frame (SCM cont); SCM_INTERNAL void scm_i_continuation_call (SCM cont, size_t n, SCM *argv); diff --git a/libguile/stacks.c b/libguile/stacks.c index ce5830c5b..58155902f 100644 --- a/libguile/stacks.c +++ b/libguile/stacks.c @@ -199,7 +199,7 @@ SCM_DEFINE (scm_make_stack, "make-stack", 1, 0, 1, SCM cont; struct scm_vm_cont *c; - cont = scm_cdar (scm_vm_capture_continuations ()); + cont = scm_i_vm_capture_continuation (scm_the_vm ()); c = SCM_VM_CONT_DATA (cont); frame = scm_c_make_frame (cont, c->fp + c->reloc, diff --git a/libguile/vm-i-system.c b/libguile/vm-i-system.c index de0210010..e5a9d7a0e 100644 --- a/libguile/vm-i-system.c +++ b/libguile/vm-i-system.c @@ -1093,7 +1093,7 @@ VM_DEFINE_INSTRUCTION (64, call_cc, "call/cc", 0, 1, 1) SCM proc, cont; POP (proc); SYNC_ALL (); - cont = scm_i_make_continuation (&first); + cont = scm_i_make_continuation (&first, vm, capture_vm_cont (vp)); if (first) { PUSH ((SCM)fp); /* dynamic link */ @@ -1130,7 +1130,7 @@ VM_DEFINE_INSTRUCTION (65, tail_call_cc, "tail-call/cc", 0, 1, 1) SCM proc, cont; POP (proc); SYNC_ALL (); - cont = scm_i_make_continuation (&first); + cont = scm_i_make_continuation (&first, vm, capture_vm_cont (vp)); ASSERT (sp == vp->sp); ASSERT (fp == vp->fp); if (first) diff --git a/libguile/vm.c b/libguile/vm.c index 9aa101a3a..425e57ed5 100644 --- a/libguile/vm.c +++ b/libguile/vm.c @@ -137,17 +137,15 @@ reinstate_vm_cont (struct scm_vm *vp, SCM cont) call to vm_run; but that's currently not implemented. */ SCM -scm_vm_capture_continuations (void) +scm_i_vm_capture_continuation (SCM vm) { - SCM vm = scm_the_vm (); - return scm_acons (vm, capture_vm_cont (SCM_VM_DATA (vm)), SCM_EOL); + return capture_vm_cont (SCM_VM_DATA (vm)); } void -scm_vm_reinstate_continuations (SCM conts) +scm_i_vm_reinstate_continuation (SCM vm, SCM cont) { - for (; conts != SCM_EOL; conts = SCM_CDR (conts)) - reinstate_vm_cont (SCM_VM_DATA (SCM_CAAR (conts)), SCM_CDAR (conts)); + reinstate_vm_cont (SCM_VM_DATA (vm), cont); } static void diff --git a/libguile/vm.h b/libguile/vm.h index c121061f3..8540356aa 100644 --- a/libguile/vm.h +++ b/libguile/vm.h @@ -98,8 +98,8 @@ struct scm_vm_cont { #define SCM_VM_CONT_P(OBJ) (SCM_NIMP (OBJ) && SCM_TYP7 (OBJ) == scm_tc7_vm_cont) #define SCM_VM_CONT_DATA(CONT) ((struct scm_vm_cont *) SCM_CELL_WORD_1 (CONT)) -SCM_API SCM scm_vm_capture_continuations (void); -SCM_API void scm_vm_reinstate_continuations (SCM conts); +SCM_INTERNAL SCM scm_i_vm_capture_continuation (SCM vm); +SCM_INTERNAL void scm_i_vm_reinstate_continuation (SCM vm, SCM cont); SCM_API SCM scm_load_compiled_with_vm (SCM file);