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/vm-engine.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/vm-engine.c')
-rw-r--r-- | libguile/vm-engine.c | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/libguile/vm-engine.c b/libguile/vm-engine.c index 26ba16816..9789fc82d 100644 --- a/libguile/vm-engine.c +++ b/libguile/vm-engine.c @@ -472,8 +472,8 @@ VM_NAME (scm_thread *thread) if (mcode) { - scm_jit_enter_mcode (thread, mcode); - CACHE_REGISTER (); + ip = scm_jit_enter_mcode (thread, mcode); + CACHE_SP (); NEXT (0); } } @@ -672,14 +672,25 @@ VM_NAME (scm_thread *thread) { SCM vmcont; uint32_t cont_idx; + uint8_t *mcode; UNPACK_24 (op, cont_idx); vmcont = SCM_PROGRAM_FREE_VARIABLE_REF (FP_REF (0), cont_idx); SYNC_IP (); - CALL_INTRINSIC (compose_continuation, (thread, vmcont)); - CACHE_REGISTER (); - NEXT (0); + mcode = CALL_INTRINSIC (compose_continuation, (thread, vmcont)); + + if (mcode) + { + ip = scm_jit_enter_mcode (thread, mcode); + CACHE_SP (); + NEXT (0); + } + else + { + CACHE_REGISTER (); + NEXT (0); + } } /* instrument-loop _:24 data:32 @@ -705,8 +716,8 @@ VM_NAME (scm_thread *thread) if (mcode) { - scm_jit_enter_mcode (thread, mcode); - CACHE_REGISTER (); + ip = scm_jit_enter_mcode (thread, mcode); + CACHE_SP (); NEXT (0); } } @@ -724,11 +735,12 @@ VM_NAME (scm_thread *thread) VM_DEFINE_OP (15, capture_continuation, "capture-continuation", DOP1 (X8_S24)) { uint32_t dst; + uint8_t *mra = NULL; UNPACK_24 (op, dst); SYNC_IP (); - SP_SET (dst, CALL_INTRINSIC (capture_continuation, (thread))); + SP_SET (dst, CALL_INTRINSIC (capture_continuation, (thread, mra))); NEXT (1); } @@ -741,19 +753,32 @@ VM_NAME (scm_thread *thread) */ VM_DEFINE_OP (16, abort, "abort", OP1 (X32)) { + uint8_t *mcode = NULL; + /* FIXME: Really we should capture the caller's registers. Until then, manually advance the IP so that when the prompt resumes, it continues with the next instruction. */ ip++; SYNC_IP (); - CALL_INTRINSIC (abort_to_prompt, (thread)); + mcode = CALL_INTRINSIC (abort_to_prompt, (thread, mcode)); /* If abort_to_prompt returned, that means there were no intervening C frames to jump over, so we just continue directly. */ - CACHE_REGISTER (); + ABORT_CONTINUATION_HOOK (); - NEXT (0); + + if (mcode) + { + ip = scm_jit_enter_mcode (thread, mcode); + CACHE_SP (); + NEXT (0); + } + else + { + CACHE_REGISTER (); + NEXT (0); + } } /* builtin-ref dst:12 idx:12 @@ -1623,6 +1648,7 @@ VM_NAME (scm_thread *thread) uint32_t tag, proc_slot; int32_t offset; uint8_t escape_only_p; + uint8_t *mra = NULL; UNPACK_24 (op, tag); escape_only_p = ip[1] & 0x1; @@ -1633,7 +1659,7 @@ VM_NAME (scm_thread *thread) /* Push the prompt onto the dynamic stack. */ SYNC_IP (); CALL_INTRINSIC (push_prompt, (thread, escape_only_p, SP_REF (tag), - VP->fp - proc_slot, ip + offset)); + VP->fp - proc_slot, ip + offset, mra)); NEXT (3); } |