1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

scm_i_make_continuation takes vm and vm_cont args explicitly

* libguile/continuations.h:
* libguile/continuations.c (scm_i_make_continuation): Take VM and VM
  continuation arguments as well; I'm not convinced that saving all VM
  continuations was the right thing, and in any case we only ever saved
  the latest. Running a new VM should create a continuation barrier.

* libguile/stacks.c (scm_make_stack):
* libguile/vm-i-system.c (call/cc, tail-call/cc): Adapt callers.

* libguile/vm.h (scm_i_vm_capture_continuation)
  (scm_i_vm_reinstate_continuation): Change to be internal, and to only
  capture and reinstate continuations for a particular VM.
This commit is contained in:
Andy Wingo 2010-02-07 14:50:51 +01:00
parent 997659f898
commit 269479e31f
6 changed files with 20 additions and 22 deletions

View file

@ -191,7 +191,7 @@ continuation_print (SCM obj, SCM port, scm_print_state *state SCM_UNUSED)
continuation. */ continuation. */
#define FUNC_NAME "scm_i_make_continuation" #define FUNC_NAME "scm_i_make_continuation"
SCM 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_i_thread *thread = SCM_I_CURRENT_THREAD;
SCM cont; SCM cont;
@ -214,7 +214,8 @@ scm_i_make_continuation (int *first)
#endif #endif
continuation->offset = continuation->stack - src; continuation->offset = continuation->stack - src;
memcpy (continuation->stack, src, sizeof (SCM_STACKITEM) * stack_size); 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); 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); contregs = scm_c_vector_ref (scm_program_objects (continuation), 0);
cont = SCM_CONTREGS (contregs); 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 = SCM_VM_CONT_DATA (cont->vm_cont);
struct scm_vm_cont *data; return scm_c_make_frame (cont->vm_cont,
vm_cont = scm_cdr (scm_car (cont->vm_conts));
data = SCM_VM_CONT_DATA (vm_cont);
return scm_c_make_frame (vm_cont,
data->fp + data->reloc, data->fp + data->reloc,
data->sp + data->reloc, data->sp + data->reloc,
data->ip, data->ip,
@ -334,7 +332,8 @@ copy_stack (void *data)
copy_stack_data *d = (copy_stack_data *)data; copy_stack_data *d = (copy_stack_data *)data;
memcpy (d->dst, d->continuation->stack, memcpy (d->dst, d->continuation->stack,
sizeof (SCM_STACKITEM) * d->continuation->num_stack_items); 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__ #ifdef __ia64__
SCM_I_CURRENT_THREAD->pending_rbs_continuation = d->continuation; SCM_I_CURRENT_THREAD->pending_rbs_continuation = d->continuation;
#endif #endif

View file

@ -53,7 +53,8 @@ typedef struct
#endif /* __ia64__ */ #endif /* __ia64__ */
size_t num_stack_items; /* size of the saved stack. */ size_t num_stack_items; /* size of the saved stack. */
SCM root; /* continuation root identifier. */ 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 /* The offset from the live stack location to this copy. This is
used to adjust pointers from within the copied stack to the stack 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_call_with_current_continuation (SCM proc);
SCM_INTERNAL SCM scm_i_continuation_to_frame (SCM cont); SCM_INTERNAL SCM scm_i_continuation_to_frame (SCM cont);
SCM_INTERNAL void scm_i_continuation_call (SCM cont, size_t n, SCM *argv); SCM_INTERNAL void scm_i_continuation_call (SCM cont, size_t n, SCM *argv);

View file

@ -199,7 +199,7 @@ SCM_DEFINE (scm_make_stack, "make-stack", 1, 0, 1,
SCM cont; SCM cont;
struct scm_vm_cont *c; 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); c = SCM_VM_CONT_DATA (cont);
frame = scm_c_make_frame (cont, c->fp + c->reloc, frame = scm_c_make_frame (cont, c->fp + c->reloc,

View file

@ -1093,7 +1093,7 @@ VM_DEFINE_INSTRUCTION (64, call_cc, "call/cc", 0, 1, 1)
SCM proc, cont; SCM proc, cont;
POP (proc); POP (proc);
SYNC_ALL (); SYNC_ALL ();
cont = scm_i_make_continuation (&first); cont = scm_i_make_continuation (&first, vm, capture_vm_cont (vp));
if (first) if (first)
{ {
PUSH ((SCM)fp); /* dynamic link */ 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; SCM proc, cont;
POP (proc); POP (proc);
SYNC_ALL (); SYNC_ALL ();
cont = scm_i_make_continuation (&first); cont = scm_i_make_continuation (&first, vm, capture_vm_cont (vp));
ASSERT (sp == vp->sp); ASSERT (sp == vp->sp);
ASSERT (fp == vp->fp); ASSERT (fp == vp->fp);
if (first) if (first)

View file

@ -137,17 +137,15 @@ reinstate_vm_cont (struct scm_vm *vp, SCM cont)
call to vm_run; but that's currently not implemented. call to vm_run; but that's currently not implemented.
*/ */
SCM SCM
scm_vm_capture_continuations (void) scm_i_vm_capture_continuation (SCM vm)
{ {
SCM vm = scm_the_vm (); return capture_vm_cont (SCM_VM_DATA (vm));
return scm_acons (vm, capture_vm_cont (SCM_VM_DATA (vm)), SCM_EOL);
} }
void 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 (vm), cont);
reinstate_vm_cont (SCM_VM_DATA (SCM_CAAR (conts)), SCM_CDAR (conts));
} }
static void static void

View file

@ -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_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)) #define SCM_VM_CONT_DATA(CONT) ((struct scm_vm_cont *) SCM_CELL_WORD_1 (CONT))
SCM_API SCM scm_vm_capture_continuations (void); SCM_INTERNAL SCM scm_i_vm_capture_continuation (SCM vm);
SCM_API void scm_vm_reinstate_continuations (SCM conts); SCM_INTERNAL void scm_i_vm_reinstate_continuation (SCM vm, SCM cont);
SCM_API SCM scm_load_compiled_with_vm (SCM file); SCM_API SCM scm_load_compiled_with_vm (SCM file);