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

david at codespeak.net david at codespeak.net
Tue Apr 28 21:35:21 CEST 2009


Author: david
Date: Tue Apr 28 21:35:20 2009
New Revision: 64792

Modified:
   pypy/branch/io-lang/pypy/lang/io/model.py
   pypy/branch/io-lang/pypy/lang/io/test/test_method.py
Log:
support parameters in method calls

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	Tue Apr 28 21:35:20 2009
@@ -93,8 +93,26 @@
         W_Object.__init__(self, space)
         
     def apply(self, space, w_receiver, w_message, w_context):
-        assert not self.arguments
-        return self.body.eval(space, w_receiver, w_context)
+        # TODO: move the call logic to a call method to use with blocks also
+        # TODO: store if the block is activateable (a method) or not
+        # TODO: create and populate call object
+
+        w_locals = self.space.w_locals.clone()
+        assert w_locals is not None
+        args = list(self.arguments)
+        
+        for arg in w_message.arguments:
+            try:
+                w_locals.slots[args.pop(0)] = arg.eval(space, w_receiver, w_context)
+            except IndexError:
+                break
+                
+        for arg_name in args:
+            w_locals.slots[arg_name] = space.w_nil
+        
+        w_locals.protos = [w_receiver]
+        w_locals.slots['self'] = w_receiver
+        return self.body.eval(space, w_locals, w_context)
         
         
 def parse_hex(string):

Modified: pypy/branch/io-lang/pypy/lang/io/test/test_method.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/test/test_method.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/test/test_method.py	Tue Apr 28 21:35:20 2009
@@ -14,3 +14,22 @@
     res,space = interpret(inp)
     assert res.value == 1
     
+def test_call_method_with_args():
+    inp = "a := method(x, x+1)\na(2)"
+    res,space = interpret(inp)
+    assert res.value == 3
+    
+def test_call_method_without_all_args():
+    inp = "a := method(x, y, z, 42)\na(2)"
+    res,space = interpret(inp)
+    assert res.value == 42
+    
+def test_unspecified_args_are_nil():
+    inp = "a := method(x, y, z, z)\na(2)"
+    res,space = interpret(inp)
+    assert res == space.w_nil
+    
+def test_superfluous_args_are_ignored():
+    inp = "a := method(x, y, z, z)\na(1,2,3,4,5,6,6,7)"
+    res,space = interpret(inp)
+    assert res.value == 3
\ No newline at end of file



More information about the Pypy-commit mailing list