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

david at codespeak.net david at codespeak.net
Thu Jul 23 12:36:33 CEST 2009


Author: david
Date: Thu Jul 23 12:36:32 2009
New Revision: 66534

Modified:
   pypy/branch/io-lang/pypy/lang/io/object.py
   pypy/branch/io-lang/pypy/lang/io/test/test_object.py
Log:
For method on Object

Modified: pypy/branch/io-lang/pypy/lang/io/object.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/object.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/object.py	Thu Jul 23 12:36:32 2009
@@ -72,3 +72,24 @@
     import pdb
     pdb.set_trace()
     return w_target
+
+ at register_method('Object', 'for')
+def object_for(space, w_target, w_message, w_context):
+   argcount = len(w_message.arguments)
+   assert argcount >= 4 and argcount <=5
+
+   body = w_message.arguments[-1]
+   start = int(w_message.arguments[1].name)
+   stop = int(w_message.arguments[2].name)
+   if argcount == 4:
+      step = 1
+   else:
+      step = int(w_message.arguments[3].name)
+   
+      
+   key = w_message.arguments[0].name
+
+   for i in range(start, stop, step):
+      w_context.slots[key] = W_Number(space, i)
+      t = body.eval(space, w_context, w_context)
+   return t
\ No newline at end of file

Modified: pypy/branch/io-lang/pypy/lang/io/test/test_object.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/test/test_object.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/test/test_object.py	Thu Jul 23 12:36:32 2009
@@ -63,4 +63,14 @@
     assert res.value == -1
     
     inp = '-"a"'
-    py.test.raises(Exception, "interpret(inp)")
\ No newline at end of file
+    py.test.raises(Exception, "interpret(inp)")
+    
+def test_object_for():
+   inp = """a:= list();
+   for(x, 0, 10, 3, a append(x));
+   a"""
+   res, space = interpret(inp)
+   
+   assert len(res.items) == 4
+   results = [t.value for t in res.items]
+   results == [0, 3, 6, 9]
\ No newline at end of file



More information about the Pypy-commit mailing list