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

david at codespeak.net david at codespeak.net
Tue May 19 12:22:54 CEST 2009


Author: david
Date: Tue May 19 12:22:54 2009
New Revision: 65306

Added:
   pypy/branch/io-lang/pypy/lang/io/test/test_object.py
Modified:
   pypy/branch/io-lang/pypy/lang/io/object.py
Log:
Add do slot to Object to evaluate a set of messages in the context of the reciever

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	Tue May 19 12:22:54 2009
@@ -35,4 +35,8 @@
 def w_object_list(space, w_target, w_message, w_context):
     w_items = [x.eval(space, w_target, w_context) for x in w_message.arguments]
     return space.w_list.clone_and_init(space, w_items)
-    
\ No newline at end of file
+    
+ at register_method('Object', 'do')
+def w_object_do(space, w_target, w_message, w_context):
+    w_message.arguments[0].eval(space, w_target, w_context)
+    return w_target
\ No newline at end of file

Added: pypy/branch/io-lang/pypy/lang/io/test/test_object.py
==============================================================================
--- (empty file)
+++ pypy/branch/io-lang/pypy/lang/io/test/test_object.py	Tue May 19 12:22:54 2009
@@ -0,0 +1,16 @@
+from pypy.lang.io.parserhack import parse, interpret
+from pypy.lang.io.model import W_Object
+import py.test
+
+
+def test_object_do():
+    inp = '4 do(a := 23)'
+    res, space = interpret(inp)
+    assert res.slots['a'].value == 23
+    assert res.value == 4
+    
+def test_object_do_multiple_slots():
+    inp = 'Object do(a := 23; b := method(a + 5); a := 1); Object b'
+    res, space = interpret(inp)
+    assert res.value == 6
+    assert space.w_object.slots['a'].value == 1
\ No newline at end of file



More information about the Pypy-commit mailing list