[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 03/13: Change call/cc inst to capture-continuation
From: |
Andy Wingo |
Subject: |
[Guile-commits] 03/13: Change call/cc inst to capture-continuation |
Date: |
Sun, 19 Aug 2018 04:44:16 -0400 (EDT) |
wingo pushed a commit to branch lightning
in repository guile.
commit c3ff72cb811fef427f547063b7bb327f2a21e2df
Author: Andy Wingo <address@hidden>
Date: Wed Aug 8 15:40:12 2018 +0200
Change call/cc inst to capture-continuation
* libguile/jit.c (compile_capture_continuation): Rename from call_cc now
that the call is elsewhere.
* libguile/vm-engine.c (call, tail-call): Remove needless SYNC_IP before
get-callee-vcode; the intrinsic can sync the ip if needed from the
frame.
(capture-continuation): Rename from call/cc, and leave the call itself
to tail-call.
* libguile/vm.c (vm_builtin_call_with_current_continuation_code): Update
to put the continuation in a local and then tail call.
(get_callee_vcode): Sync vp->ip if we error.
---
libguile/jit.c | 2 +-
libguile/vm-engine.c | 27 +++++++++------------------
libguile/vm.c | 6 +++++-
3 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/libguile/jit.c b/libguile/jit.c
index 02e2485..69b2021 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 eaaa285..b22dee9 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;
-
- SYNC_IP ();
- cont = CALL_INTRINSIC (capture_continuation, (thread));
-
- RESET_FRAME (2);
+ uint32_t dst;
- SP_SET (1, SP_REF (0));
- SP_SET (0, cont);
+ UNPACK_24 (op, dst);
- ip = CALL_INTRINSIC (get_callee_vcode, (thread));
- CACHE_SP ();
+ SYNC_IP ();
+ SP_SET (dst, CALL_INTRINSIC (capture_continuation, (thread)));
- NEXT (0);
+ NEXT (1);
}
/* abort _:24
diff --git a/libguile/vm.c b/libguile/vm.c
index ff01f62..8ad8cfe 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));
}
- [Guile-commits] branch lightning updated (0d00164 -> 3827769), Andy Wingo, 2018/08/19
- [Guile-commits] 01/13: Minor optimization in RESET_FRAME, Andy Wingo, 2018/08/19
- [Guile-commits] 04/13: Add unpack-values-object intrinsic, Andy Wingo, 2018/08/19
- [Guile-commits] 03/13: Change call/cc inst to capture-continuation,
Andy Wingo <=
- [Guile-commits] 09/13: Update error-wrong-num-args intrinsic prototype, Andy Wingo, 2018/08/19
- [Guile-commits] 02/13: Rework program->ip mapping in VM to always call intrinsic, Andy Wingo, 2018/08/19
- [Guile-commits] 12/13: Define intrinsics for atomic ops, Andy Wingo, 2018/08/19
- [Guile-commits] 07/13: Continuations capture machine code address, Andy Wingo, 2018/08/19
- [Guile-commits] 05/13: Invoke VM hooks through intrinsics, Andy Wingo, 2018/08/19
- [Guile-commits] 06/13: Rework foreign-call trampoline, Andy Wingo, 2018/08/19
- [Guile-commits] 08/13: Adapt JIT calling convention; continuations take mra from stack, Andy Wingo, 2018/08/19
- [Guile-commits] 11/13: 64-bit intrinsic args and return values passed indirectly on 32-bit, Andy Wingo, 2018/08/19
- [Guile-commits] 10/13: Avoid needless 64-bit args on 32-bit machines for some intrinsics, Andy Wingo, 2018/08/19
- [Guile-commits] 13/13: Add instrumentation to VM builtins, Andy Wingo, 2018/08/19