[pypy-svn] r66676 - in pypy/branch/io-lang/pypy/lang/io: . test

david at codespeak.net david at codespeak.net
Wed Jul 29 18:46:39 CEST 2009


Author: david
Date: Wed Jul 29 18:46:39 2009
New Revision: 66676

Modified:
   pypy/branch/io-lang/pypy/lang/io/model.py
   pypy/branch/io-lang/pypy/lang/io/test/test_map.py
Log:
control flow for Map foreach

Modified: pypy/branch/io-lang/pypy/lang/io/model.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/model.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/model.py	Wed Jul 29 18:46:39 2009
@@ -142,6 +142,12 @@
             w_context.slots[key_name] = item.key
             w_context.slots[value_name] = item.value
             t = w_body.eval(space, w_context, w_context)
+            if not space.is_normal_status():
+                if space.is_continue_status():
+                    space.normal_status()
+                else:
+                    space.normal_status()
+                    break
         return t 
         
     def keys(self):
@@ -199,6 +205,7 @@
             assert w_method is not None, 'Method "%s" not found in "%s"' % (self.name, w_receiver.__class__)
             w_result = w_method.apply(space, w_receiver, self, w_context)
             if not space.is_normal_status():
+                print 'Returning non default value'
                 return space.w_return_value
         if self.next:
             #TODO: optimize

Modified: pypy/branch/io-lang/pypy/lang/io/test/test_map.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/test/test_map.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/test/test_map.py	Wed Jul 29 18:46:39 2009
@@ -105,6 +105,33 @@
     value = sorted([(x.items[0].value, x.items[1].value) for x in res.items])
     assert value == [('1', 12345), ('2', 99), ('3', 3), ('4', 234)]
 
+def test_map_foreach_continue():
+    inp = """b := Map clone do(
+        atPut("1", 12345) 
+        atPut("2", 99) 
+        atPut("3", 3) 
+        atPut("4", 234)
+    )
+    c := list()
+    b foreach(key, value, if(value == 99, continue); c append(list(key, value))); c"""
+    res,space = interpret(inp)
+    value = sorted([(x.items[0].value, x.items[1].value) for x in res.items])
+    assert value == [('1', 12345), ('3', 3), ('4', 234)]
+
+def test_map_foreach_break():
+    inp = """b := Map clone do(
+        atPut("1", 12345) 
+        atPut("2", 99) 
+        atPut("3", 3) 
+        atPut("4", 234)
+    )
+    c := list()
+    b foreach(key, value, break(99); c append(list(key, value)));"""
+    res,space = interpret(inp)
+    assert space.w_lobby.slots['c'].items == []
+    assert res.value == 99
+    
+
 def test_map_foreach_leaks():
     inp = """b := Map clone do(
         atPut("1", 12345) 
@@ -167,4 +194,4 @@
   inp = """Map with("a", 1, "b", 2) asObject"""
   res, space = interpret(inp)
   assert res.slots['a'].value == 1
-  assert res.slots['b'].value == 2
+  assert res.slots['b'].value == 2
\ No newline at end of file



More information about the Pypy-commit mailing list