[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 18/26: Refactor continuation capture in VM
From: |
Andy Wingo |
Subject: |
[Guile-commits] 18/26: Refactor continuation capture in VM |
Date: |
Tue, 26 Jun 2018 11:26:14 -0400 (EDT) |
wingo pushed a commit to branch master
in repository guile.
commit 51e35158bad42b8db28e9272ebb279f17b76dbe4
Author: Andy Wingo <address@hidden>
Date: Tue Jun 26 11:25:07 2018 +0200
Refactor continuation capture in VM
* libguile/continuations.h:
* libguile/continuations.c (scm_i_make_continuation): Refactor to expect
registers to already be captured.
* libguile/scm.h (scm_i_thread): Add forward decl.
* libguile/threads.h (struct scm_i_thread): Just fill in the struct
type.
* libguile/vm-engine.c (call/cc); Use the registers already captured
before entering the VM.
---
libguile/continuations.c | 21 +++------------------
libguile/continuations.h | 4 ++--
libguile/scm.h | 2 +-
libguile/threads.h | 4 ++--
libguile/vm-engine.c | 37 +++++++++++--------------------------
5 files changed, 19 insertions(+), 49 deletions(-)
diff --git a/libguile/continuations.c b/libguile/continuations.c
index c99e0eb..172168e 100644
--- a/libguile/continuations.c
+++ b/libguile/continuations.c
@@ -166,18 +166,12 @@ restore_auxiliary_stack (scm_i_thread *thread,
scm_t_contregs *continuation)
#endif
}
-/* this may return more than once: the first time with the escape
- procedure, then subsequently with SCM_UNDEFINED (the vals already having
been
- placed on the VM stack). */
-#define FUNC_NAME "scm_i_make_continuation"
SCM
-scm_i_make_continuation (int *first, struct scm_vm *vp, SCM vm_cont)
+scm_i_make_continuation (jmp_buf *registers, scm_i_thread *thread, SCM vm_cont)
{
- scm_i_thread *thread = SCM_I_CURRENT_THREAD;
SCM cont;
scm_t_contregs *continuation;
long stack_size;
- const void *saved_cookie;
SCM_STACKITEM * src;
SCM_FLUSH_REGISTER_WINDOWS;
@@ -193,23 +187,14 @@ scm_i_make_continuation (int *first, struct scm_vm *vp,
SCM vm_cont)
#endif
continuation->offset = continuation->stack - src;
memcpy (continuation->stack, src, sizeof (SCM_STACKITEM) * stack_size);
+ memcpy (continuation->jmpbuf, registers, sizeof (*registers));
continuation->vm_cont = vm_cont;
- saved_cookie = vp->resumable_prompt_cookie;
capture_auxiliary_stack (thread, continuation);
SCM_NEWSMOB (cont, tc16_continuation, continuation);
- *first = !setjmp (continuation->jmpbuf);
- if (*first)
- return make_continuation_trampoline (cont);
- else
- {
- vp->resumable_prompt_cookie = saved_cookie;
- scm_gc_after_nonlocal_exit ();
- return SCM_UNDEFINED;
- }
+ return make_continuation_trampoline (cont);
}
-#undef FUNC_NAME
int
scm_i_continuation_to_frame (SCM continuation, struct scm_frame *frame)
diff --git a/libguile/continuations.h b/libguile/continuations.h
index 6b52f26..9e044c4 100644
--- a/libguile/continuations.h
+++ b/libguile/continuations.h
@@ -67,8 +67,8 @@ typedef struct
-SCM_INTERNAL SCM scm_i_make_continuation (int *first,
- struct scm_vm *vp,
+SCM_INTERNAL SCM scm_i_make_continuation (jmp_buf *registers,
+ scm_i_thread *thread,
SCM vm_cont);
SCM_INTERNAL void scm_i_reinstate_continuation (SCM cont) SCM_NORETURN;
diff --git a/libguile/scm.h b/libguile/scm.h
index 9996ec4..99b20fc 100644
--- a/libguile/scm.h
+++ b/libguile/scm.h
@@ -827,7 +827,7 @@ typedef int32_t scm_t_wchar;
struct scm_frame;
struct scm_vm;
union scm_vm_stack_element;
-
+typedef struct scm_i_thread scm_i_thread; /* FIXME: Rename. */
diff --git a/libguile/threads.h b/libguile/threads.h
index 50d4ba1..9f0ccc5 100644
--- a/libguile/threads.h
+++ b/libguile/threads.h
@@ -48,7 +48,7 @@ SCM_API scm_t_bits scm_tc16_condvar;
struct scm_thread_wake_data;
-typedef struct scm_i_thread {
+struct scm_i_thread {
struct scm_i_thread *next_thread;
SCM handle;
@@ -105,7 +105,7 @@ typedef struct scm_i_thread {
struct scm_vm vm;
SCM_STACKITEM *base;
jmp_buf regs;
-} scm_i_thread;
+};
#define SCM_I_IS_THREAD(x) SCM_SMOB_PREDICATE (scm_tc16_thread, x)
#define SCM_I_THREAD_DATA(x) ((scm_i_thread *) SCM_SMOB_DATA (x))
diff --git a/libguile/vm-engine.c b/libguile/vm-engine.c
index 6f2e093..0fdbf00 100644
--- a/libguile/vm-engine.c
+++ b/libguile/vm-engine.c
@@ -758,7 +758,6 @@ VM_NAME (scm_i_thread *thread, jmp_buf *registers, int
resume)
{
SCM vm_cont, cont;
scm_t_dynstack *dynstack;
- int first;
SYNC_IP ();
dynstack = scm_dynstack_capture_all (&thread->dynstack);
@@ -768,35 +767,21 @@ VM_NAME (scm_i_thread *thread, jmp_buf *registers, int
resume)
SCM_FRAME_RETURN_ADDRESS (VP->fp),
dynstack,
0);
- /* FIXME: Seems silly to capture the registers here, when they are
- already captured in the registers local, which here we are
- copying out to the heap; and likewise, the setjmp(®isters)
- code already has the non-local return handler. But oh
- well! */
- cont = scm_i_make_continuation (&first, VP, vm_cont);
-
- if (first)
- {
- RESET_FRAME (2);
-
- SP_SET (1, SP_REF (0));
- SP_SET (0, cont);
+ cont = scm_i_make_continuation (registers, thread, vm_cont);
- if (SCM_LIKELY (SCM_PROGRAM_P (SP_REF (1))))
- ip = SCM_PROGRAM_CODE (SP_REF (1));
- else
- ip = (uint32_t *) vm_apply_non_program_code;
+ RESET_FRAME (2);
- APPLY_HOOK ();
+ SP_SET (1, SP_REF (0));
+ SP_SET (0, cont);
- NEXT (0);
- }
+ if (SCM_LIKELY (SCM_PROGRAM_P (SP_REF (1))))
+ ip = SCM_PROGRAM_CODE (SP_REF (1));
else
- {
- CACHE_REGISTER ();
- ABORT_CONTINUATION_HOOK ();
- NEXT (0);
- }
+ ip = (uint32_t *) vm_apply_non_program_code;
+
+ APPLY_HOOK ();
+
+ NEXT (0);
}
/* abort _:24
- [Guile-commits] 05/26: Add __scm.h placeholder, (continued)
- [Guile-commits] 05/26: Add __scm.h placeholder, Andy Wingo, 2018/06/26
- [Guile-commits] 04/26: Deprecate scm_t_uint8 and similar typedefs, Andy Wingo, 2018/06/26
- [Guile-commits] 09/26: Fix intrinsics copyright line and include guards, Andy Wingo, 2018/06/26
- [Guile-commits] 07/26: Eagerly initialize thread VM; remove scm_the_vm, Andy Wingo, 2018/06/26
- [Guile-commits] 06/26: Inline struct scm_vm into struct scm_i_thread, Andy Wingo, 2018/06/26
- [Guile-commits] 03/26: Use ptrdiff_t instead of scm_t_ptrdiff, Andy Wingo, 2018/06/26
- [Guile-commits] 10/26: expand_stack intrinsic takes thread, Andy Wingo, 2018/06/26
- [Guile-commits] 01/26: Start to use C99 stdint in gen-scmconfig, Andy Wingo, 2018/06/26
- [Guile-commits] 08/26: VM gets VP from thread, Andy Wingo, 2018/06/26
- [Guile-commits] 20/26: Add intrinsic for call/cc, Andy Wingo, 2018/06/26
- [Guile-commits] 18/26: Refactor continuation capture in VM,
Andy Wingo <=
- [Guile-commits] 17/26: Foreign-call intrinsic boxes errno, Andy Wingo, 2018/06/26
- [Guile-commits] 25/26: Optimize abort-to-prompt to avoid alloca, Andy Wingo, 2018/06/26
- [Guile-commits] 15/26: Most header files use forward decl for union scm_vm_stack_element, Andy Wingo, 2018/06/26
- [Guile-commits] 14/26: Add intrinsic for foreign-call, Andy Wingo, 2018/06/26
- [Guile-commits] 11/26: Move VM keyword argument parsing to happen via an intrinsic, Andy Wingo, 2018/06/26
- [Guile-commits] 22/26: Add rest-arg-length intrinsic., Andy Wingo, 2018/06/26
- [Guile-commits] 16/26: Reinstating undelimited continuations uses intrinsic, Andy Wingo, 2018/06/26
- [Guile-commits] 24/26: Refactors to abort-to-prompt implementation, Andy Wingo, 2018/06/26
- [Guile-commits] 12/26: Add push-interrupt-frame VM intrinsic, Andy Wingo, 2018/06/26
- [Guile-commits] 13/26: Give multiple-values objects a tc7, Andy Wingo, 2018/06/26