guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] 06/27: return-values opcode resets the frame


From: Andy Wingo
Subject: [Guile-commits] 06/27: return-values opcode resets the frame
Date: Wed, 11 Nov 2015 11:39:08 +0000

wingo pushed a commit to branch master
in repository guile.

commit 7aee3c74f5f31c6f386c75506f43b42c786a41b4
Author: Andy Wingo <address@hidden>
Date:   Wed Oct 28 10:47:18 2015 +0000

    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 e44f211..420671a 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
 
address@hidden Instruction {} return-values x24:@var{_}
address@hidden 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 d5f6857..45faa14 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 86c9d30..838fd4d 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))))))
 



reply via email to

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