[pypy-svn] r65309 - in pypy/branch/io-lang/pypy/lang/io: . test
david at codespeak.net
david at codespeak.net
Tue May 19 14:21:44 CEST 2009
Author: david
Date: Tue May 19 14:21:42 2009
New Revision: 65309
Added:
pypy/branch/io-lang/pypy/lang/io/call.py
pypy/branch/io-lang/pypy/lang/io/message.py
pypy/branch/io-lang/pypy/lang/io/test/test_call.py
pypy/branch/io-lang/pypy/lang/io/test/test_message.py
Modified:
pypy/branch/io-lang/pypy/lang/io/model.py
pypy/branch/io-lang/pypy/lang/io/object.py
pypy/branch/io-lang/pypy/lang/io/objspace.py
pypy/branch/io-lang/pypy/lang/io/register.py
pypy/branch/io-lang/pypy/lang/io/test/test_method.py
pypy/branch/io-lang/pypy/lang/io/test/test_object.py
Log:
methods for Call and Message objects, corrected evaluation of method args and create call object for when a method is called. Add message slot to Object
Added: pypy/branch/io-lang/pypy/lang/io/call.py
==============================================================================
--- (empty file)
+++ pypy/branch/io-lang/pypy/lang/io/call.py Tue May 19 14:21:42 2009
@@ -0,0 +1,9 @@
+from pypy.lang.io.register import register_method
+from pypy.lang.io.model import W_Message
+
+ at register_method('Call', 'argAt')
+def call_arg_at(space, w_target, w_message, w_context):
+ return space.w_message.slots['argAt'].apply(
+ space,
+ w_target.slots['message'],
+ w_message, w_context)
\ No newline at end of file
Added: pypy/branch/io-lang/pypy/lang/io/message.py
==============================================================================
--- (empty file)
+++ pypy/branch/io-lang/pypy/lang/io/message.py Tue May 19 14:21:42 2009
@@ -0,0 +1,13 @@
+from pypy.lang.io.register import register_method
+from pypy.lang.io.model import W_Message
+
+ at register_method('Message', 'argAt', unwrap_spec=[object, int])
+def message_arg_at(space, w_message, arg_num):
+ if arg_num < len(w_message.arguments):
+ return w_message.arguments[arg_num]
+ return space.w_nil
+
+# @register_method('Message', 'setIsActivatable', unwrap_spec=[object, bool])
+# def message_setIsActivatable(space, w_target, setting):
+# w_target.activateable = setting
+# return w_target
\ No newline at end of file
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 May 19 14:21:42 2009
@@ -92,7 +92,7 @@
self.literal_value = parse_literal(space, name)
self.arguments = arguments
self.next = next
- W_Object.__init__(self, space)
+ W_Object.__init__(self, space, [space.w_message])
def __repr__(self):
return "Message(%r, %r, %r)" % (self.name, self.arguments, self.next)
@@ -129,17 +129,17 @@
def call(self, space, w_receiver, w_message, w_context):
w_locals = self.space.w_locals.clone()
+ w_call = self.space.w_call.clone()
assert w_locals is not None
- args = list(self.arguments)
+ assert w_call is not None
- 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
+ args = list(self.arguments)
+ n_params = len(w_message.arguments)
+ for i in range(len(args)):
+ if i < n_params:
+ w_locals.slots[args[i]] = w_message.arguments[i].eval(space, w_receiver, w_context)
+ else:
+ w_locals.slots[args[i]] = space.w_nil
if self.activateable:
w_locals.protos = [w_receiver]
@@ -147,7 +147,9 @@
else:
w_locals.protos = [w_context]
w_locals.slots['self'] = w_context
-
+
+ w_locals.slots['call'] = w_call
+ w_call.slots['message'] = w_message
return self.body.eval(space, w_locals, w_context)
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 14:21:42 2009
@@ -57,3 +57,8 @@
@register_method('Object', '', unwrap_spec=[object, object])
def w_object_(space, w_target, w_arg):
return w_arg
+
+
+ at register_method('Object', 'message')
+def object_message(space, w_target, w_message, w_context):
+ return w_message.arguments[0]
\ No newline at end of file
Modified: pypy/branch/io-lang/pypy/lang/io/objspace.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/objspace.py (original)
+++ pypy/branch/io-lang/pypy/lang/io/objspace.py Tue May 19 14:21:42 2009
@@ -6,7 +6,8 @@
import pypy.lang.io.object
import pypy.lang.io.block
import pypy.lang.io.list
-
+import pypy.lang.io.call
+import pypy.lang.io.message
class ObjSpace(object):
"""docstring for ObjSpace"""
def __init__(self):
@@ -19,24 +20,34 @@
self.w_true = W_Object(self, [self.w_object])
self.w_false = W_Object(self, [self.w_object])
self.w_nil = W_Object(self, [self.w_object])
- self.w_block = W_Block(self, [], W_Message(self, 'nil', []), False, [self.w_object])
self.w_list = W_List(self, [self.w_object])
+ self.w_call = W_Object(self)
+
self.init_w_object()
self.init_w_protos()
self.init_w_list()
-
+
+ self.init_w_message()
+
+ self.w_block = W_Block(self, [], W_Message(self, 'nil', []), False, [self.w_object])
self.init_w_block()
self.init_w_lobby()
self.init_w_number()
+
self.init_w_core()
-
+ self.init_w_call()
+
+ def init_w_call(self):
+ for key, function in cfunction_definitions['Call'].items():
+ self.w_call.slots[key] = W_CFunction(self, function)
+
def init_w_protos(self):
self.w_protos.protos.append(self.w_core)
self.w_protos.slots['Core'] = self.w_core
@@ -58,6 +69,7 @@
self.w_core.slots['false'] = self.w_false
self.w_core.slots['nil'] = self.w_nil
self.w_core.slots['List'] = self.w_list
+ self.w_core.slots['Call'] = self.w_call
def init_w_number(self):
self.w_number = instantiate(W_Number)
@@ -67,6 +79,14 @@
for key, function in cfunction_definitions['Number'].items():
self.w_number.slots[key] = W_CFunction(self, function)
+ def init_w_message(self):
+ self.w_message = instantiate(W_Message)
+ W_Object.__init__(self.w_message, self)
+ self.w_message.protos = [self.w_object]
+ self.w_message.name = "Unnamed"
+ for key, function in cfunction_definitions['Message'].items():
+ self.w_message.slots[key] = W_CFunction(self, function)
+
def init_w_lobby(self):
self.w_lobby.protos.append(self.w_protos)
self.w_object.protos.append(self.w_lobby)
Modified: pypy/branch/io-lang/pypy/lang/io/register.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/register.py (original)
+++ pypy/branch/io-lang/pypy/lang/io/register.py Tue May 19 14:21:42 2009
@@ -24,6 +24,11 @@
args += (x, )
elif typ is str:
args += (x.value, )
+ elif typ is bool:
+ if x is space.w_true:
+ args += (True, )
+ else:
+ args += (False, )
else:
raise ValueError, 'Unknown unwrap spec'
Added: pypy/branch/io-lang/pypy/lang/io/test/test_call.py
==============================================================================
--- (empty file)
+++ pypy/branch/io-lang/pypy/lang/io/test/test_call.py Tue May 19 14:21:42 2009
@@ -0,0 +1,8 @@
+from pypy.lang.io.parserhack import interpret
+from pypy.lang.io.model import W_Message
+import py
+
+def test_message_arg_at():
+ inp = 'a := method(x, y, z, call); a(1,2,3) argAt(1)'
+ res, space = interpret(inp)
+ assert res.name == '2'
\ No newline at end of file
Added: pypy/branch/io-lang/pypy/lang/io/test/test_message.py
==============================================================================
--- (empty file)
+++ pypy/branch/io-lang/pypy/lang/io/test/test_message.py Tue May 19 14:21:42 2009
@@ -0,0 +1,27 @@
+from pypy.lang.io.parserhack import interpret
+from pypy.lang.io.model import W_Message, W_Block
+import py
+
+
+def test_message_protos():
+ inp = "a := block(1)\na"
+ res,space = interpret(inp)
+
+ assert res.body.protos == [space.w_message]
+ assert space.w_message.protos == [space.w_object]
+
+def test_message_arg_at():
+ inp = 'a := message(foo(2,3,4)); a argAt(1)'
+ res, space = interpret(inp)
+ assert res.name == '3'
+
+# def test_setIsActivatable():
+# inp = "a := block(1);a setIsActivateable(true); a"
+# res,space = interpret(inp)
+#
+# assert res.value == 1
+#
+# inp = "a := method(1);a setIsActivateable(false); a"
+# res,space = interpret(inp)
+#
+# assert isinstance(res, W_Block)
\ No newline at end of file
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 May 19 14:21:42 2009
@@ -71,4 +71,36 @@
def test_block_modified_binding():
inp = 'c := Object clone; b := 42; c setSlot("a", block(x, b)); b := 1; c a call(3)'
res, space = interpret(inp)
- assert res.value == 1
\ No newline at end of file
+ assert res.value == 1
+
+def test_block_call_slot():
+ py.test.skip()
+ inp = """
+ Object do(
+ /*doc Object inlineMethod
+ Creates a method which is executed directly in a receiver (no Locals object is created).
+ <br/>
+ <pre>
+ Io> m := inlineMethod(x := x*2)
+ Io> x := 1
+ ==> 1
+ Io> m
+ ==> 2
+ Io> m
+ ==> 4
+ Io> m
+ ==> 8
+ </pre>
+ */
+ inlineMethod := method(call message argAt(0) setIsActivatable(true))
+ )
+ m := inlineMethod(x := x*2)
+ x := 1
+ m
+ m
+ """
+ # from A0_List.io
+ res, space = interpret(inp)
+ assert space.w_object.slots['inlineMethod'] is not None
+ assert res.value == 4
+
\ 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 Tue May 19 14:21:42 2009
@@ -1,5 +1,5 @@
from pypy.lang.io.parserhack import parse, interpret
-from pypy.lang.io.model import W_Object
+from pypy.lang.io.model import W_Object, W_Message
import py.test
@@ -38,3 +38,9 @@
inp2 = 'Object ?a'
res, space = interpret(inp2)
assert res is space.w_nil
+
+def test_object_message():
+ inp = 'message(foo)'
+ res, space = interpret(inp)
+ assert isinstance(res, W_Message)
+ assert res.name == 'foo'
\ No newline at end of file
More information about the Pypy-commit
mailing list