1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-24 20:30:28 +02:00

Intrinsics take registers from thread

* libguile/continuations.c (scm_i_make_continuation): Remove registers
  argument; instead get from thread.
* libguile/vm-engine.c (vm_engine): Adapt VM engine to not receive a
  registers argument, and thus to not pass it to intrinsics either.
* libguile/intrinsics.h:
* libguile/intrinsics.c (push_prompt):
* libguile/vm.c (capture_continuation, compose_continuation)
  (abort_to_prompt): Refactor these intrinsics to not take a registers
  argument; it's not necessary.
  (scm_call_n): Don't pass registers argument.
This commit is contained in:
Andy Wingo 2018-06-27 18:42:21 +02:00
parent 154a5de3d7
commit 64d114817a
6 changed files with 28 additions and 35 deletions

View file

@ -167,7 +167,7 @@ restore_auxiliary_stack (scm_thread *thread, scm_t_contregs *continuation)
} }
SCM SCM
scm_i_make_continuation (jmp_buf *registers, scm_thread *thread, SCM vm_cont) scm_i_make_continuation (scm_thread *thread, SCM vm_cont)
{ {
SCM cont; SCM cont;
scm_t_contregs *continuation; scm_t_contregs *continuation;
@ -187,7 +187,7 @@ scm_i_make_continuation (jmp_buf *registers, scm_thread *thread, SCM vm_cont)
#endif #endif
continuation->offset = continuation->stack - src; continuation->offset = continuation->stack - src;
memcpy (continuation->stack, src, sizeof (SCM_STACKITEM) * stack_size); memcpy (continuation->stack, src, sizeof (SCM_STACKITEM) * stack_size);
memcpy (continuation->jmpbuf, registers, sizeof (*registers)); memcpy (continuation->jmpbuf, thread->vm.registers, sizeof (jmp_buf));
continuation->vm_cont = vm_cont; continuation->vm_cont = vm_cont;
capture_auxiliary_stack (thread, continuation); capture_auxiliary_stack (thread, continuation);

View file

@ -67,9 +67,7 @@ typedef struct
SCM_INTERNAL SCM scm_i_make_continuation (jmp_buf *registers, SCM_INTERNAL SCM scm_i_make_continuation (scm_thread *thread, SCM vm_cont);
scm_thread *thread,
SCM vm_cont);
SCM_INTERNAL void scm_i_reinstate_continuation (SCM cont) SCM_NORETURN; SCM_INTERNAL void scm_i_reinstate_continuation (SCM cont) SCM_NORETURN;
SCM_INTERNAL int scm_i_continuation_to_frame (SCM cont, SCM_INTERNAL int scm_i_continuation_to_frame (SCM cont,

View file

@ -348,7 +348,7 @@ current_module (scm_thread *thread)
} }
static void static void
push_prompt (scm_thread *thread, jmp_buf *registers, uint8_t escape_only_p, push_prompt (scm_thread *thread, uint8_t escape_only_p,
SCM tag, const union scm_vm_stack_element *sp, void *ra) SCM tag, const union scm_vm_stack_element *sp, void *ra)
{ {
struct scm_vm *vp = &thread->vm; struct scm_vm *vp = &thread->vm;
@ -357,7 +357,7 @@ push_prompt (scm_thread *thread, jmp_buf *registers, uint8_t escape_only_p,
flags = escape_only_p ? SCM_F_DYNSTACK_PROMPT_ESCAPE_ONLY : 0; flags = escape_only_p ? SCM_F_DYNSTACK_PROMPT_ESCAPE_ONLY : 0;
scm_dynstack_push_prompt (&thread->dynstack, flags, tag, scm_dynstack_push_prompt (&thread->dynstack, flags, tag,
vp->stack_top - vp->fp, vp->stack_top - sp, vp->stack_top - vp->fp, vp->stack_top - sp,
ra, registers); ra, thread->vm.registers);
} }
void void

View file

@ -54,20 +54,17 @@ typedef void (*scm_t_thread_u32_u32_scm_u8_u8_intrinsic) (scm_thread*, uint32_t,
typedef SCM (*scm_t_scm_from_scm_scm_scmp_sp_intrinsic) (SCM, SCM, SCM*, typedef SCM (*scm_t_scm_from_scm_scm_scmp_sp_intrinsic) (SCM, SCM, SCM*,
const union scm_vm_stack_element*); const union scm_vm_stack_element*);
typedef void (*scm_t_thread_scm_noreturn_intrinsic) (scm_thread*, SCM) SCM_NORETURN; typedef void (*scm_t_thread_scm_noreturn_intrinsic) (scm_thread*, SCM) SCM_NORETURN;
typedef SCM (*scm_t_scm_from_thread_regs_intrinsic) (scm_thread*, jmp_buf*);
typedef void (*scm_t_thread_regs_scm_intrinsic) (scm_thread*, jmp_buf*, SCM);
typedef int (*scm_t_int_from_scm_intrinsic) (SCM); typedef int (*scm_t_int_from_scm_intrinsic) (SCM);
typedef void (*scm_t_thread_regs_intrinsic) (scm_thread*, jmp_buf*);
typedef void (*scm_t_scm_scm_noreturn_intrinsic) (SCM, SCM) SCM_NORETURN; typedef void (*scm_t_scm_scm_noreturn_intrinsic) (SCM, SCM) SCM_NORETURN;
typedef void (*scm_t_noreturn_intrinsic) (void) SCM_NORETURN; typedef void (*scm_t_noreturn_intrinsic) (void) SCM_NORETURN;
typedef void (*scm_t_scm_noreturn_intrinsic) (SCM) SCM_NORETURN; typedef void (*scm_t_scm_noreturn_intrinsic) (SCM) SCM_NORETURN;
typedef void (*scm_t_u32_noreturn_intrinsic) (uint32_t) SCM_NORETURN; typedef void (*scm_t_u32_noreturn_intrinsic) (uint32_t) SCM_NORETURN;
typedef SCM (*scm_t_scm_from_thread_u64_intrinsic) (scm_thread*, uint64_t); typedef SCM (*scm_t_scm_from_thread_u64_intrinsic) (scm_thread*, uint64_t);
typedef SCM (*scm_t_scm_from_thread_intrinsic) (scm_thread*); typedef SCM (*scm_t_scm_from_thread_intrinsic) (scm_thread*);
typedef void (*scm_t_thread_regs_u8_scm_sp_ra_intrinsic) (scm_thread*, jmp_buf*, typedef void (*scm_t_thread_u8_scm_sp_ra_intrinsic) (scm_thread*,
uint8_t, SCM, uint8_t, SCM,
const union scm_vm_stack_element*, const union scm_vm_stack_element*,
void*); void*);
#define SCM_FOR_ALL_VM_INTRINSICS(M) \ #define SCM_FOR_ALL_VM_INTRINSICS(M) \
M(scm_from_scm_scm, add, "add", ADD) \ M(scm_from_scm_scm, add, "add", ADD) \
@ -119,10 +116,10 @@ typedef void (*scm_t_thread_regs_u8_scm_sp_ra_intrinsic) (scm_thread*, jmp_buf*,
M(thread, push_interrupt_frame, "push-interrupt-frame", PUSH_INTERRUPT_FRAME) \ M(thread, push_interrupt_frame, "push-interrupt-frame", PUSH_INTERRUPT_FRAME) \
M(scm_from_scm_scm_scmp_sp, foreign_call, "foreign-call", FOREIGN_CALL) \ M(scm_from_scm_scm_scmp_sp, foreign_call, "foreign-call", FOREIGN_CALL) \
M(thread_scm_noreturn, reinstate_continuation_x, "reinstate-continuation!", REINSTATE_CONTINUATION_X) \ M(thread_scm_noreturn, reinstate_continuation_x, "reinstate-continuation!", REINSTATE_CONTINUATION_X) \
M(scm_from_thread_regs, capture_continuation, "capture-continuation", CAPTURE_CONTINUATION) \ M(scm_from_thread, capture_continuation, "capture-continuation", CAPTURE_CONTINUATION) \
M(thread_regs_scm, compose_continuation, "compose-continuation", COMPOSE_CONTINUATION) \ M(thread_scm, compose_continuation, "compose-continuation", COMPOSE_CONTINUATION) \
M(int_from_scm, rest_arg_length, "rest-arg-length", REST_ARG_LENGTH) \ M(int_from_scm, rest_arg_length, "rest-arg-length", REST_ARG_LENGTH) \
M(thread_regs, abort_to_prompt, "abort-to-prompt", ABORT_TO_PROMPT) \ M(thread, abort_to_prompt, "abort-to-prompt", ABORT_TO_PROMPT) \
M(scm_scm_noreturn, throw_, "throw", THROW) \ M(scm_scm_noreturn, throw_, "throw", THROW) \
M(scm_scm_noreturn, throw_with_value, "throw/value", THROW_WITH_VALUE) \ M(scm_scm_noreturn, throw_with_value, "throw/value", THROW_WITH_VALUE) \
M(scm_scm_noreturn, throw_with_value_and_data, "throw/value+data", THROW_WITH_VALUE_AND_DATA) \ M(scm_scm_noreturn, throw_with_value_and_data, "throw/value+data", THROW_WITH_VALUE_AND_DATA) \
@ -133,7 +130,7 @@ typedef void (*scm_t_thread_regs_u8_scm_sp_ra_intrinsic) (scm_thread*, jmp_buf*,
M(thread, apply_non_program, "apply-non-program", APPLY_NON_PROGRAM) \ M(thread, apply_non_program, "apply-non-program", APPLY_NON_PROGRAM) \
M(scm_from_thread_u64, allocate_words, "allocate-words", ALLOCATE_WORDS) \ M(scm_from_thread_u64, allocate_words, "allocate-words", ALLOCATE_WORDS) \
M(scm_from_thread, current_module, "current-module", CURRENT_MODULE) \ M(scm_from_thread, current_module, "current-module", CURRENT_MODULE) \
M(thread_regs_u8_scm_sp_ra, push_prompt, "push-prompt", PUSH_PROMPT) \ M(thread_u8_scm_sp_ra, push_prompt, "push-prompt", PUSH_PROMPT) \
/* Add new intrinsics here; also update scm_bootstrap_intrinsics. */ /* Add new intrinsics here; also update scm_bootstrap_intrinsics. */
enum scm_vm_intrinsic enum scm_vm_intrinsic

View file

@ -272,7 +272,7 @@
((uintptr_t) (ptr) % alignof_type (type) == 0) ((uintptr_t) (ptr) % alignof_type (type) == 0)
static SCM static SCM
VM_NAME (scm_thread *thread, jmp_buf *registers, int resume) VM_NAME (scm_thread *thread, int resume)
{ {
/* Instruction pointer: A pointer to the opcode that is currently /* Instruction pointer: A pointer to the opcode that is currently
running. */ running. */
@ -714,7 +714,7 @@ VM_NAME (scm_thread *thread, jmp_buf *registers, int resume)
vmcont = SCM_PROGRAM_FREE_VARIABLE_REF (FP_REF (0), cont_idx); vmcont = SCM_PROGRAM_FREE_VARIABLE_REF (FP_REF (0), cont_idx);
SYNC_IP (); SYNC_IP ();
CALL_INTRINSIC (compose_continuation, (thread, registers, vmcont)); CALL_INTRINSIC (compose_continuation, (thread, vmcont));
CACHE_REGISTER (); CACHE_REGISTER ();
NEXT (0); NEXT (0);
} }
@ -777,7 +777,7 @@ VM_NAME (scm_thread *thread, jmp_buf *registers, int resume)
SCM cont; SCM cont;
SYNC_IP (); SYNC_IP ();
cont = CALL_INTRINSIC (capture_continuation, (thread, registers)); cont = CALL_INTRINSIC (capture_continuation, (thread));
RESET_FRAME (2); RESET_FRAME (2);
@ -810,7 +810,7 @@ VM_NAME (scm_thread *thread, jmp_buf *registers, int resume)
it continues with the next instruction. */ it continues with the next instruction. */
ip++; ip++;
SYNC_IP (); SYNC_IP ();
CALL_INTRINSIC (abort_to_prompt, (thread, registers)); CALL_INTRINSIC (abort_to_prompt, (thread));
/* If abort_to_prompt returned, that means there were no /* If abort_to_prompt returned, that means there were no
intervening C frames to jump over, so we just continue intervening C frames to jump over, so we just continue
@ -1676,9 +1676,8 @@ VM_NAME (scm_thread *thread, jmp_buf *registers, int resume)
/* Push the prompt onto the dynamic stack. */ /* Push the prompt onto the dynamic stack. */
SYNC_IP (); SYNC_IP ();
CALL_INTRINSIC (push_prompt, CALL_INTRINSIC (push_prompt, (thread, escape_only_p, SP_REF (tag),
(thread, registers, escape_only_p, FP_SLOT (proc_slot), ip + offset));
SP_REF (tag), FP_SLOT (proc_slot), ip + offset));
NEXT (3); NEXT (3);
} }

View file

@ -464,8 +464,7 @@ scm_i_call_with_current_continuation (SCM proc)
#undef VM_USE_HOOKS #undef VM_USE_HOOKS
#undef VM_NAME #undef VM_NAME
typedef SCM (*scm_t_vm_engine) (scm_thread *current_thread, typedef SCM (*scm_t_vm_engine) (scm_thread *current_thread, int resume);
jmp_buf *registers, int resume);
static const scm_t_vm_engine vm_engines[SCM_VM_NUM_ENGINES] = static const scm_t_vm_engine vm_engines[SCM_VM_NUM_ENGINES] =
{ vm_regular_engine, vm_debug_engine }; { vm_regular_engine, vm_debug_engine };
@ -1102,7 +1101,7 @@ reinstate_continuation_x (scm_thread *thread, SCM cont)
} }
static SCM static SCM
capture_continuation (scm_thread *thread, jmp_buf *registers) capture_continuation (scm_thread *thread)
{ {
struct scm_vm *vp = &thread->vm; struct scm_vm *vp = &thread->vm;
SCM vm_cont = SCM vm_cont =
@ -1112,7 +1111,7 @@ capture_continuation (scm_thread *thread, jmp_buf *registers)
SCM_FRAME_RETURN_ADDRESS (vp->fp), SCM_FRAME_RETURN_ADDRESS (vp->fp),
scm_dynstack_capture_all (&thread->dynstack), scm_dynstack_capture_all (&thread->dynstack),
0); 0);
return scm_i_make_continuation (registers, thread, vm_cont); return scm_i_make_continuation (thread, vm_cont);
} }
struct compose_continuation_data struct compose_continuation_data
@ -1139,7 +1138,7 @@ compose_continuation_inner (void *data_ptr)
} }
static void static void
compose_continuation (scm_thread *thread, jmp_buf *registers, SCM cont) compose_continuation (scm_thread *thread, SCM cont)
{ {
struct scm_vm *vp = &thread->vm; struct scm_vm *vp = &thread->vm;
size_t nargs; size_t nargs;
@ -1185,7 +1184,7 @@ compose_continuation (scm_thread *thread, jmp_buf *registers, SCM cont)
if (SCM_DYNSTACK_TAG_TYPE (tag) == SCM_DYNSTACK_TYPE_PROMPT) if (SCM_DYNSTACK_TAG_TYPE (tag) == SCM_DYNSTACK_TYPE_PROMPT)
scm_dynstack_wind_prompt (&thread->dynstack, walk, old_fp_offset, scm_dynstack_wind_prompt (&thread->dynstack, walk, old_fp_offset,
registers); thread->vm.registers);
else else
scm_dynstack_wind_1 (&thread->dynstack, walk); scm_dynstack_wind_1 (&thread->dynstack, walk);
} }
@ -1257,7 +1256,7 @@ scm_i_vm_abort (SCM *tag_and_argv, size_t n)
} }
static void static void
abort_to_prompt (scm_thread *thread, jmp_buf *current_registers) abort_to_prompt (scm_thread *thread)
{ {
struct scm_vm *vp = &thread->vm; struct scm_vm *vp = &thread->vm;
scm_t_dynstack *dynstack = &thread->dynstack; scm_t_dynstack *dynstack = &thread->dynstack;
@ -1292,7 +1291,7 @@ abort_to_prompt (scm_thread *thread, jmp_buf *current_registers)
captured = scm_dynstack_capture (dynstack, SCM_DYNSTACK_NEXT (prompt)); captured = scm_dynstack_capture (dynstack, SCM_DYNSTACK_NEXT (prompt));
cont = capture_delimited_continuation (vp, fp, sp, ip, registers, captured, cont = capture_delimited_continuation (vp, fp, sp, ip, registers, captured,
current_registers); thread->vm.registers);
} }
/* Unwind. */ /* Unwind. */
@ -1316,7 +1315,7 @@ abort_to_prompt (scm_thread *thread, jmp_buf *current_registers)
/* If there are intervening C frames, then jump over them, making a /* If there are intervening C frames, then jump over them, making a
nonlocal exit. Otherwise fall through and let the VM pick up where nonlocal exit. Otherwise fall through and let the VM pick up where
it left off. */ it left off. */
if (current_registers != registers) if (thread->vm.registers != registers)
longjmp (*registers, 1); longjmp (*registers, 1);
} }
@ -1423,7 +1422,7 @@ scm_call_n (SCM proc, SCM *argv, size_t nargs)
} }
thread->vm.registers = &registers; thread->vm.registers = &registers;
ret = vm_engines[vp->engine](thread, &registers, resume); ret = vm_engines[vp->engine](thread, resume);
thread->vm.registers = prev_registers; thread->vm.registers = prev_registers;
return ret; return ret;