Author: Stephan <step...@stzal.com>
Branch: 
Changeset: r71:41578daab3b5
Date: 2011-05-18 15:37 +0200
http://bitbucket.org/pypy/lang-js/changeset/41578daab3b5/

Log:    fixed continue in while loop

diff --git a/js/jscode.py b/js/jscode.py
--- a/js/jscode.py
+++ b/js/jscode.py
@@ -61,11 +61,6 @@
         self.startlooplabel.append(num)
         return num
 
-    def emit_startloop_label(self):
-        num = self.emit_label()
-        self.startlooplabel.append(num)
-        return num
-
     def prealocate_label(self):
         num = self.label_count
         self.label_count += 1
@@ -100,6 +95,12 @@
             raise ThrowException(W_String("Continue outside loop"))
         self.emit('JUMP', self.updatelooplabel[-1])
 
+    def continue_at_label(self, label):
+        self.updatelooplabel.append(label)
+
+    def done_continue(self):
+        self.updatelooplabel.pop()
+
     def emit(self, operation, *args):
         opcode = getattr(opcodes, operation)(*args)
         self.opcodes.append(opcode)
diff --git a/js/operations.py b/js/operations.py
--- a/js/operations.py
+++ b/js/operations.py
@@ -821,12 +821,14 @@
 class While(WhileBase):
     def emit(self, bytecode):
         startlabel = bytecode.emit_startloop_label()
+        bytecode.continue_at_label(startlabel)
         self.condition.emit(bytecode)
         endlabel = bytecode.prealocate_endloop_label()
         bytecode.emit('JUMP_IF_FALSE', endlabel)
         self.body.emit(bytecode)
         bytecode.emit('JUMP', startlabel)
         bytecode.emit_endloop_label(endlabel)
+        bytecode.done_continue()
 
 class ForVarIn(Statement):
     def __init__(self, pos, vardecl, lobject, body):
diff --git a/js/test/test_interp.py b/js/test/test_interp.py
--- a/js/test/test_interp.py
+++ b/js/test/test_interp.py
@@ -725,3 +725,52 @@
     yield assertv, 'var i = {x:0}; i.x&=1;', 0
     yield assertv, 'var i = {x:1}; i.x&=0;', 0
     yield assertv, 'var i = {x:1}; i.x&=1;', 1
+
+def test_loop_continue():
+    yield assertv, """
+      i = 0;
+      n = 0;
+      while (i < 3) {
+         i++;
+         if (i == 1)
+            continue;
+         n += i;
+      }
+      n;
+    """, 5
+    yield assertv, """
+      i = 0;
+      n = 0;
+      while (i < 3) {
+         i++;
+         if (i == 1)
+            continue;
+         for(j = 0; j < 10; j++) {
+           if (j == 5)
+               continue;
+           n += j;
+         }
+      }
+      n;
+    """, 80
+    yield assertv, """
+      i = 0;
+      n = 0;
+      while (i < 3) {
+         i++;
+         if (i == 1)
+            continue;
+         for(j = 0; j < 10; j++) {
+           if (j == 5)
+               continue;
+           k = 0;
+           while(k < 10) {
+             k++;
+             if (k % 2 == 0)
+                continue;
+             n += j;
+           }
+         }
+      }
+      n;
+    """, 400
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to