guile-commits
[Top][All Lists]
Advanced

[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));
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]