1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-02 13:00:26 +02:00

Add bind-optionals instruction

* doc/ref/vm.texi (Function Prologue Instructions): Document new
  instruction.
* libguile/jit.c (compile_bind_optionals): New compiler.
* libguile/vm-engine.c (VM_NAME): New interpreter.
* module/system/vm/assembler.scm (opt-prelude): Emit bind-optionals as
  appropriate.
* module/system/vm/disassembler.scm (define-stack-effect-parser)
  (code-annotation): Handle bind-optionals.
This commit is contained in:
Andy Wingo 2019-06-06 16:20:20 +02:00
parent 12d6e43176
commit 9fd978ed7e
5 changed files with 73 additions and 9 deletions

View file

@ -2005,6 +2005,37 @@ compile_bind_rest (scm_jit_state *j, uint32_t dst)
jit_patch_here (j->jit, k);
}
static void
compile_bind_optionals (scm_jit_state *j, uint32_t dst)
{
ASSERT_HAS_REGISTER_STATE (FP_IN_REGISTER | SP_IN_REGISTER);
ASSERT(j->frame_size == -1);
jit_gpr_t saved_frame_size = T1_PRESERVED;
jit_subr (j->jit, saved_frame_size, FP, SP);
jit_reloc_t no_optionals = jit_bgei
(j->jit, saved_frame_size, dst * sizeof (union scm_vm_stack_element));
emit_alloc_frame (j, T0, dst);
jit_gpr_t walk = saved_frame_size;
jit_subr (j->jit, walk, FP, saved_frame_size);
jit_reloc_t done = jit_bler (j->jit, walk, SP);
jit_movi (j->jit, T0, SCM_UNPACK (SCM_UNDEFINED));
void *head = jit_address (j->jit);
jit_subi (j->jit, walk, walk, sizeof (union scm_vm_stack_element));
jit_str (j->jit, walk, T0);
jit_patch_there (j->jit, jit_bner (j->jit, walk, SP), head);
jit_patch_here (j->jit, done);
jit_patch_here (j->jit, no_optionals);
ASSERT(j->frame_size == -1);
}
static void
compile_allocate_words (scm_jit_state *j, uint16_t dst, uint16_t nwords)
{

View file

@ -3231,7 +3231,28 @@ VM_NAME (scm_thread *thread)
VM_DEFINE_OP (153, f64_set, "f64-set!", OP1 (X8_S8_S8_S8))
PTR_SET (double, F64);
VM_DEFINE_OP (154, unused_154, NULL, NOP)
/* bind-optionals nargs:24
*
* Expand the current frame to have NARGS locals, filling in any fresh
* values with SCM_UNDEFINED.
*/
VM_DEFINE_OP (154, bind_optionals, "bind-optionals", DOP1 (X8_F24))
{
uint32_t nlocals, nargs;
UNPACK_24 (op, nlocals);
nargs = FRAME_LOCALS_COUNT ();
if (nargs < nlocals)
{
ALLOC_FRAME (nlocals);
while (nargs < nlocals)
FP_SET (nargs++, SCM_UNDEFINED);
}
NEXT (1);
}
VM_DEFINE_OP (155, unused_155, NULL, NOP)
VM_DEFINE_OP (156, unused_156, NULL, NOP)
VM_DEFINE_OP (157, unused_157, NULL, NOP)