From 7aee3c74f5f31c6f386c75506f43b42c786a41b4 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Wed, 28 Oct 2015 10:47:18 +0000 Subject: [PATCH] return-values opcode resets the frame * libguile/vm-engine.c (return-values): Change to also reset the frame, if nlocals is nonzero. * doc/ref/vm.texi (Procedure Call and Return Instructions): Updated docs. * module/language/cps/compile-bytecode.scm (compile-function): Adapt to call emit-return-values with the right number of arguments. --- doc/ref/vm.texi | 7 ++++--- libguile/vm-engine.c | 12 +++++++++--- module/language/cps/compile-bytecode.scm | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/doc/ref/vm.texi b/doc/ref/vm.texi index e44f21169..420671adc 100644 --- a/doc/ref/vm.texi +++ b/doc/ref/vm.texi @@ -763,12 +763,13 @@ has run, the values can be copied down via @code{mov}, or used in place. Return a value. @end deftypefn -@deftypefn Instruction {} return-values x24:@var{_} +@deftypefn Instruction {} return-values c24:@var{nlocals} Return a number of values from a call frame. This opcode corresponds to an application of @code{values} in tail position. As with tail calls, we expect that the values have already been shuffled down to a -contiguous array starting at slot 1. We also expect the frame has -already been reset. +contiguous array starting at slot 1. If @var{nlocals} is nonzero, reset +the frame to hold that number of locals. Note that a frame reset to 1 +local returns 0 values. @end deftypefn @deftypefn Instruction {} call/cc x24:@var{_} diff --git a/libguile/vm-engine.c b/libguile/vm-engine.c index d5f68578d..45faa1495 100644 --- a/libguile/vm-engine.c +++ b/libguile/vm-engine.c @@ -747,20 +747,26 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp, RETURN_ONE_VALUE (SP_REF (src)); } - /* return-values _:24 + /* return-values nlocals:24 * * Return a number of values from a call frame. This opcode * corresponds to an application of `values' in tail position. As * with tail calls, we expect that the values have already been * shuffled down to a contiguous array starting at slot 1. - * We also expect the frame has already been reset. + * If NLOCALS is not zero, we also reset the frame to hold NLOCALS + * values. */ - VM_DEFINE_OP (9, return_values, "return-values", OP1 (X32)) + VM_DEFINE_OP (9, return_values, "return-values", OP1 (X8_C24)) { union scm_vm_stack_element *old_fp; + scm_t_uint32 nlocals; VM_HANDLE_INTERRUPTS; + UNPACK_24 (op, nlocals); + if (nlocals) + RESET_FRAME (nlocals); + old_fp = vp->fp; ip = SCM_FRAME_RETURN_ADDRESS (vp->fp); vp->fp = SCM_FRAME_DYNAMIC_LINK (vp->fp); diff --git a/module/language/cps/compile-bytecode.scm b/module/language/cps/compile-bytecode.scm index 86c9d307d..838fd4d07 100644 --- a/module/language/cps/compile-bytecode.scm +++ b/module/language/cps/compile-bytecode.scm @@ -124,7 +124,7 @@ (emit-tail-call-label asm (1+ (length args)) k)) (($ $values ()) (emit-reset-frame asm 1) - (emit-return-values asm)) + (emit-return-values asm 1)) (($ $values (arg)) (if (maybe-slot arg) (emit-return asm (from-sp (slot arg))) @@ -138,7 +138,7 @@ ((src . dst) (emit-mov asm (from-sp dst) (from-sp src)))) (lookup-parallel-moves label allocation)) (emit-reset-frame asm (1+ (length args))) - (emit-return-values asm)) + (emit-return-values asm (1+ (length args)))) (($ $primcall 'return (arg)) (emit-return asm (from-sp (slot arg))))))