guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 07/13: Refactor handling of active VM registers


From: Andy Wingo
Subject: [Guile-commits] 07/13: Refactor handling of active VM registers
Date: Wed, 27 Jun 2018 14:00:12 -0400 (EDT)

wingo pushed a commit to branch master
in repository guile.

commit 18431e6e63243eebefa3e77684d7b75e69c0fcb5
Author: Andy Wingo <address@hidden>
Date:   Wed Jun 27 18:21:04 2018 +0200

    Refactor handling of active VM registers
    
    * libguile/threads.h (scm_thread): Remove unused jmp_buf regs member.
    * libguile/vm.h (struct scm_vm): Rename resumable_prompt_cookie to just
      "registers"; we know it's a jmp_buf pointer.
    * libguile/vm.c (scm_call_n):
    * libguile/throw.c (catch):
    * libguile/eval.c (eval):
    * libguile/control.c (scm_suspendable_continuation_p): Adapt to cookie
      renaming.
---
 libguile/control.c | 2 +-
 libguile/eval.c    | 6 +++---
 libguile/threads.h | 5 +----
 libguile/throw.c   | 6 +++---
 libguile/vm.c      | 6 +++---
 libguile/vm.h      | 4 +++-
 6 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/libguile/control.c b/libguile/control.c
index 3068f6a..2e10b58 100644
--- a/libguile/control.c
+++ b/libguile/control.c
@@ -124,7 +124,7 @@ scm_suspendable_continuation_p (SCM tag)
 
   if (scm_dynstack_find_prompt (&thread->dynstack, tag, &flags,
                                 NULL, NULL, NULL, &registers))
-    return scm_from_bool (registers == thread->vm.resumable_prompt_cookie);
+    return scm_from_bool (registers == thread->vm.registers);
 
   return SCM_BOOL_F;
 }
diff --git a/libguile/eval.c b/libguile/eval.c
index 242759b..589a297 100644
--- a/libguile/eval.c
+++ b/libguile/eval.c
@@ -439,7 +439,7 @@ eval (SCM x, SCM env)
         scm_thread *t;
         SCM k, handler, res;
         jmp_buf registers;
-        const void *prev_cookie;
+        jmp_buf *prev_registers;
         ptrdiff_t saved_stack_depth;
 
         k = EVAL1 (CAR (mx), env);
@@ -457,11 +457,11 @@ eval (SCM x, SCM env)
                                   t->vm.ip,
                                   &registers);
 
-        prev_cookie = t->vm.resumable_prompt_cookie;
+        prev_registers = t->vm.registers;
         if (setjmp (registers))
           {
             /* The prompt exited nonlocally. */
-            t->vm.resumable_prompt_cookie = prev_cookie;
+            t->vm.registers = prev_registers;
             scm_gc_after_nonlocal_exit ();
             proc = handler;
             args = scm_i_prompt_pop_abort_args_x (&t->vm, saved_stack_depth);
diff --git a/libguile/threads.h b/libguile/threads.h
index 5ed4c65..733b6db 100644
--- a/libguile/threads.h
+++ b/libguile/threads.h
@@ -22,8 +22,6 @@
 
 
 
-#include <setjmp.h>
-
 #include "libguile/procs.h"
 #include "libguile/throw.h"
 #include "libguile/dynstack.h"
@@ -101,10 +99,9 @@ struct scm_thread {
   SCM continuation_root;
   SCM_STACKITEM *continuation_base;
 
-  /* For keeping track of the stack and registers. */
+  /* VM state for this thread.  */
   struct scm_vm vm;
   SCM_STACKITEM *base;
-  jmp_buf regs;
 };
 
 #define SCM_I_IS_THREAD(x)    SCM_SMOB_PREDICATE (scm_tc16_thread, x)
diff --git a/libguile/throw.c b/libguile/throw.c
index 8a6f0f8..f1f8540 100644
--- a/libguile/throw.c
+++ b/libguile/throw.c
@@ -86,7 +86,7 @@ catch (SCM tag, SCM thunk, SCM handler, SCM 
pre_unwind_handler)
   scm_t_dynstack *dynstack = &t->dynstack;
   scm_t_dynamic_state *dynamic_state = t->dynamic_state;
   jmp_buf registers;
-  const void *prev_cookie;
+  jmp_buf *prev_registers;
   ptrdiff_t saved_stack_depth;
 
   if (!scm_is_eq (tag, SCM_BOOL_T) && !scm_is_symbol (tag))
@@ -109,7 +109,7 @@ catch (SCM tag, SCM thunk, SCM handler, SCM 
pre_unwind_handler)
   scm_c_vector_set_x (eh, 1, prompt_tag);
   scm_c_vector_set_x (eh, 2, pre_unwind_handler);
 
-  prev_cookie = t->vm.resumable_prompt_cookie;
+  prev_registers = t->vm.registers;
   saved_stack_depth = t->vm.stack_top - t->vm.sp;
 
   /* Push the prompt and exception handler onto the dynamic stack. */
@@ -128,7 +128,7 @@ catch (SCM tag, SCM thunk, SCM handler, SCM 
pre_unwind_handler)
       /* A non-local return.  */
       SCM args;
 
-      t->vm.resumable_prompt_cookie = prev_cookie;
+      t->vm.registers = prev_registers;
       scm_gc_after_nonlocal_exit ();
 
       /* FIXME: We know where the args will be on the stack; we could
diff --git a/libguile/vm.c b/libguile/vm.c
index 3a603e4..442bd72 100644
--- a/libguile/vm.c
+++ b/libguile/vm.c
@@ -1411,7 +1411,7 @@ scm_call_n (SCM proc, SCM *argv, size_t nargs)
   {
     jmp_buf registers;
     int resume;
-    const void *prev_cookie = vp->resumable_prompt_cookie;
+    jmp_buf *prev_registers = thread->vm.registers;
     SCM ret;
 
     resume = setjmp (registers);
@@ -1422,9 +1422,9 @@ scm_call_n (SCM proc, SCM *argv, size_t nargs)
         vm_dispatch_abort_hook (vp);
       }
 
-    vp->resumable_prompt_cookie = &registers;
+    thread->vm.registers = &registers;
     ret = vm_engines[vp->engine](thread, &registers, resume);
-    vp->resumable_prompt_cookie = prev_cookie;
+    thread->vm.registers = prev_registers;
 
     return ret;
   }
diff --git a/libguile/vm.h b/libguile/vm.h
index cf777a6..a5cdacb 100644
--- a/libguile/vm.h
+++ b/libguile/vm.h
@@ -20,6 +20,8 @@
 #ifndef _SCM_VM_H_
 #define _SCM_VM_H_
 
+#include <setjmp.h>
+
 #include <libguile/gc.h>
 #include <libguile/programs.h>
 
@@ -56,7 +58,7 @@ struct scm_vm {
   union scm_vm_stack_element *stack_top; /* highest address in allocated stack 
*/
   SCM overflow_handler_stack;   /* alist of max-stack-size -> thunk */
   SCM hooks[SCM_VM_NUM_HOOKS]; /* hooks */
-  const void *resumable_prompt_cookie; /* opaque cookie */
+  jmp_buf *registers;           /* registers captured at latest vm entry  */
   int engine;                   /* which vm engine we're using */
 };
 



reply via email to

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