diff options
author | Andy Wingo <wingo@pobox.com> | 2018-08-12 15:57:53 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2018-08-12 15:57:53 +0200 |
commit | a20feea43e3a8cf2460c254fb65d5e3aed6bd756 (patch) | |
tree | 0db0ea0e21515d6eddc3055c4ad4a5b1613c4904 /libguile/continuations.c | |
parent | 939b1ae23f680365fb6fd0a78653a281aaed95b6 (diff) | |
download | guile-a20feea43e3a8cf2460c254fb65d5e3aed6bd756.tar.gz |
Continuations capture machine code address
* libguile/continuations.c (scm_i_continuation_to_frame): Adapt to vra
field renaming.
(scm_i_reinstate_continuation, grow_stack, copy_stack_and_call)
(scm_dynthrow): Take mra of continuation. Set on the vp before the
longjmp.
* libguile/continuations.h: Update scm_i_reinstate_continuation
prototype.
* libguile/dynstack.h:
* libguile/control.c (scm_suspendable_continuation_p):
* libguile/dynstack.c (PROMPT_WORDS, PROMPT_VRA, PROMPT_MRA):
(PROMPT_JMPBUF, scm_dynstack_push_prompt, scm_dynstack_find_prompt)
(scm_dynstack_wind_prompt): Store both virtual and machine return
addresses on the dynstack, for prompts.
* libguile/eval.c (eval): Pass NULL for mra.
* libguile/intrinsics.c (push_prompt): Add mra arg, and pass it to the
dynstack.
* libguile/intrinsics.h: Update prototypes so that continuation-related
intrinsics can save and restore the MRA.
* libguile/jit.h:
* libguile/jit.c: Return VRA when JIT code needs to tier down.
* libguile/stacks.c (find_prompt, scm_make_stack)
* libguile/throw.c (catch): Adapt find-prompt calls.
* libguile/vm-engine.c (instrument-entry, instrument-loop): Add logic to
continue with vcode after the mcode finishes.
(compose-continuation, capture-continuation, abort, prompt): Add logic
to pass NULL as captured MRA, but continue with mcode from new
continuations, if appropriate.
* libguile/vm.c (scm_i_vm_cont_to_frame, capture_stack)
(scm_i_capture_current_stack, reinstate_continuation_x)
(capture_continuation, compose_continuation_inner, compose_continuation)
(capture_delimited_continuation, abort_to_prompt): Adapt to plumb
around machine code continuations.
(scm_call_n): Check "mra_after_abort" field for machine code
continuation, if any.
* libguile/vm.h (struct scm_vm): Add "mra_after_abort" field.
(struct scm_vm_cont): Rename "ra" field to "vra" and add "mra" field.
Diffstat (limited to 'libguile/continuations.c')
-rw-r--r-- | libguile/continuations.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/libguile/continuations.c b/libguile/continuations.c index c7e008f18..479266e99 100644 --- a/libguile/continuations.c +++ b/libguile/continuations.c @@ -228,7 +228,7 @@ scm_i_continuation_to_frame (SCM continuation, struct scm_frame *frame) frame->stack_holder = data; frame->fp_offset = data->fp_offset; frame->sp_offset = data->stack_size; - frame->ip = data->ra; + frame->ip = data->vra; return 1; } @@ -261,7 +261,7 @@ scm_i_contregs (SCM contregs) * with their correct stack. */ -static void scm_dynthrow (SCM); +static void scm_dynthrow (SCM, uint8_t *); /* Grow the stack by a fixed amount to provide space to copy in the * continuation. Possibly this function has to be called several times @@ -273,12 +273,12 @@ static void scm_dynthrow (SCM); static scm_t_bits scm_i_dummy; static void -grow_stack (SCM cont) +grow_stack (SCM cont, uint8_t *mra) { scm_t_bits growth[100]; scm_i_dummy = (scm_t_bits) growth; - scm_dynthrow (cont); + scm_dynthrow (cont, mra); } @@ -289,7 +289,7 @@ grow_stack (SCM cont) static void copy_stack_and_call (scm_t_contregs *continuation, - SCM_STACKITEM * dst) + SCM_STACKITEM * dst, uint8_t *mra) { scm_t_dynstack *dynstack; scm_t_bits *joint; @@ -305,6 +305,7 @@ copy_stack_and_call (scm_t_contregs *continuation, scm_dynstack_wind (&thread->dynstack, joint); + thread->vm.mra_after_abort = mra; longjmp (continuation->jmpbuf, 1); } @@ -313,7 +314,7 @@ copy_stack_and_call (scm_t_contregs *continuation, * actual copying and continuation calling. */ static void -scm_dynthrow (SCM cont) +scm_dynthrow (SCM cont, uint8_t *mra) { scm_thread *thread = SCM_I_CURRENT_THREAD; scm_t_contregs *continuation = SCM_CONTREGS (cont); @@ -326,17 +327,17 @@ scm_dynthrow (SCM cont) #else dst -= continuation->num_stack_items; if (dst <= &stack_top_element) - grow_stack (cont); + grow_stack (cont, mra); #endif /* def SCM_STACK_GROWS_UP */ SCM_FLUSH_REGISTER_WINDOWS; - copy_stack_and_call (continuation, dst); + copy_stack_and_call (continuation, dst, mra); } void -scm_i_reinstate_continuation (SCM cont) +scm_i_reinstate_continuation (SCM cont, uint8_t *mra) { - scm_dynthrow (cont); + scm_dynthrow (cont, mra); abort (); /* Unreachable. */ } |