[Quipu-dev] quipu/quipu: Fix closures over let forms

Back to archive index

scmno****@osdn***** scmno****@osdn*****
Tue Jun 19 02:24:19 JST 2018


changeset 5cf600fc7c5e in quipu/quipu
details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=5cf600fc7c5e
user: Agustina Arzille <avarz****@riseu*****>
date: Mon Jun 18 14:24:10 2018 -0300
description: Fix closures over let forms

diffstat:

 compiler.cpp |  28 +++++++++++-----------------
 1 files changed, 11 insertions(+), 17 deletions(-)

diffs (81 lines):

diff -r 6f9cbcb4479e -r 5cf600fc7c5e compiler.cpp
--- a/compiler.cpp	Sun Jun 17 21:15:58 2018 +0000
+++ b/compiler.cpp	Mon Jun 18 14:24:10 2018 -0300
@@ -844,7 +844,7 @@
         this->emit (ixs[(vp->flagged_p (symbol::special_flag)) ? 4 : 2], s);
     }
   else if (depth >= (int)this->frames.size ())
-    {
+    { // Outside this function's scope.
       this->rflags |= flg_outer_ref;
       this->emit (ixs[1], intobj (loc),
         intobj (depth - (int)this->frames.size ()));
@@ -2129,6 +2129,9 @@
 
       ret = as_array(seq)->len;
     }
+  else if (table_p (seq))
+    for (table::iterator it (interp, seq); it.valid (); it.adv (), ++ret)
+      interp->push (*it.key);
   else if (tree_p (seq))
     for (tree::iterator it (interp, seq); it.valid (); it.adv (), ++ret)
       interp->push (it.get_key ());
@@ -2410,10 +2413,10 @@
         as_int (stack[interp->cur_frame - 3]) - 1];
       r_stkend(1) = retval;
 
-      // TODO: Improve for 'let' (use cur_frame - 3?)
-      set_lastf (interp, fn, lastf);
+      lastf = (fn & EXTRA_BIT) ? as_int (fn) : interp->cur_frame;
       nargs = as_int (stack[lastf - 3]);
       bp = lastf - (interpreter::frame_size + nargs);
+      fn = stack[bp - 1];
 
       ip = as_bvector(fct_bcode (fn))->data +
         as_int (stack[interp->cur_frame - 2]);
@@ -2589,11 +2592,11 @@
       NEXT_OP;
 
     OP_(LOADC00):
-      U_PUSH (xaref (stack[bp + nargs], 0));
+      U_PUSH (xaref (stack[interp->cur_frame - 5], 0));
       NEXT_OP;
 
     OP_(LOADC01):
-      U_PUSH (xaref (stack[bp + nargs], 1));
+      U_PUSH (xaref (stack[interp->cur_frame - 5], 1));
       NEXT_OP;
 
     OP_(LOADAP0):
@@ -2731,20 +2734,11 @@
     OP_(MKFRAMEL):
       sx = !bcode_long_p (*(ip - 1)) ? (int8_t)*ip++ : (int32_t)fetch32 (ip);
 
-      *interp->stkend++ = fn | EXTRA_BIT;
+      *interp->stkend++ = intobj (lastf) | EXTRA_BIT;
       for (int32_t si = 0; si < sx; ++si)
         *interp->stkend++ = UNBOUND;
 
-      if (interp->dynframe_captured ())
-        { // Capture environment.
-          array *ap = as_array (alloc_array (interp, sx + 1, NIL));
-          ap->data[ap->len - 1] = stack[interp->cur_frame - 5];
-          r_stkend(sx) = interp->alval;
-          interp->push_frame (interp->alval, sx, 0);
-        }
-      else
-        interp->push_frame (NIL, sx, 0);
-
+      interp->push_frame (stack[interp->cur_frame - 5], sx, 0);
       NEXT_OP;
 
     OP_(UNWIND):
@@ -2765,7 +2759,7 @@
           array *ap = as_array (alloc_array (interp, sx + 1, NIL));
           int nbp = interp->cur_frame - interpreter::frame_size - sx;
           copy_objs (ap->data, &stack[nbp], sx + 1);
-          stack[nbp] = stack[interp->cur_frame - 5] = interp->alval;
+          stack[interp->cur_frame - 5] = interp->alval;
           interp->dynframe_set_captured ();
         }
 




More information about the Quipu-dev mailing list
Back to archive index