diff --git a/libguile/jit.c b/libguile/jit.c index 02e24858c..69b202132 100644 --- a/libguile/jit.c +++ b/libguile/jit.c @@ -121,7 +121,7 @@ compile_compose_continuation (scm_jit_state *j, uint32_t a) } static void -compile_call_cc (scm_jit_state *j) +compile_capture_continuation (scm_jit_state *j, uint32_t dst) { } diff --git a/libguile/vm-engine.c b/libguile/vm-engine.c index eaaa2858a..b22dee920 100644 --- a/libguile/vm-engine.c +++ b/libguile/vm-engine.c @@ -379,7 +379,6 @@ VM_NAME (scm_thread *thread) SCM_FRAME_SET_MACHINE_RETURN_ADDRESS (new_fp, 0); VP->fp = new_fp; - SYNC_IP (); RESET_FRAME (nlocals); ip = CALL_INTRINSIC (get_callee_vcode, (thread)); CACHE_SP (); @@ -429,7 +428,6 @@ VM_NAME (scm_thread *thread) */ VM_DEFINE_OP (3, tail_call, "tail-call", OP1 (X32)) { - SYNC_IP (); ip = CALL_INTRINSIC (get_callee_vcode, (thread)); CACHE_SP (); NEXT (0); @@ -726,28 +724,21 @@ VM_NAME (scm_thread *thread) NEXT (2); } - /* call/cc _:24 + /* capture-continuation dst:24 * - * Capture the current continuation, and tail-apply the procedure in - * local slot 1 to it. This instruction is part of the implementation - * of `call/cc', and is not generated by the compiler. + * Capture the current continuation. This instruction is part of the + * implementation of `call/cc', and is not generated by the compiler. */ - VM_DEFINE_OP (15, call_cc, "call/cc", OP1 (X32)) + VM_DEFINE_OP (15, capture_continuation, "capture-continuation", DOP1 (X8_S24)) { - SCM cont; + uint32_t dst; + + UNPACK_24 (op, dst); SYNC_IP (); - cont = CALL_INTRINSIC (capture_continuation, (thread)); + SP_SET (dst, CALL_INTRINSIC (capture_continuation, (thread))); - RESET_FRAME (2); - - SP_SET (1, SP_REF (0)); - SP_SET (0, cont); - - ip = CALL_INTRINSIC (get_callee_vcode, (thread)); - CACHE_SP (); - - NEXT (0); + NEXT (1); } /* abort _:24 diff --git a/libguile/vm.c b/libguile/vm.c index ff01f6284..8ad8cfe3f 100644 --- a/libguile/vm.c +++ b/libguile/vm.c @@ -338,7 +338,9 @@ static const uint32_t vm_builtin_call_with_values_code[] = { static const uint32_t vm_builtin_call_with_current_continuation_code[] = { SCM_PACK_OP_24 (assert_nargs_ee, 2), - SCM_PACK_OP_24 (call_cc, 0) + SCM_PACK_OP_12_12 (mov, 1, 0), + SCM_PACK_OP_24 (capture_continuation, 0), + SCM_PACK_OP_24 (tail_call, 0) }; static const uint32_t vm_handle_interrupt_code[] = { @@ -1332,6 +1334,8 @@ get_callee_vcode (scm_thread *thread) return SCM_PROGRAM_CODE (proc); } + vp->ip = SCM_FRAME_VIRTUAL_RETURN_ADDRESS (vp->fp); + scm_error (scm_arg_type_key, NULL, "Wrong type to apply: ~S", scm_list_1 (proc), scm_list_1 (proc)); }