[pypy-svn] r66702 - in pypy/branch/io-lang/pypy/lang/io: . test
david at codespeak.net
david at codespeak.net
Thu Jul 30 16:57:59 CEST 2009
Author: david
Date: Thu Jul 30 16:57:59 2009
New Revision: 66702
Modified:
pypy/branch/io-lang/pypy/lang/io/object.py
pypy/branch/io-lang/pypy/lang/io/test/test_object.py
Log:
setSlotWithType 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 30 16:57:59 2009
@@ -6,6 +6,12 @@
w_target.slots[name] = w_value
return w_value
+ at register_method('Object', 'setSlotWithType', unwrap_spec=[object, str, object])
+def w_object_set_slot_with_type(space, w_target, name, w_value):
+ w_object_set_slot(space, w_target, name, w_value)
+ w_object_set_slot(space, w_value, "type", space.w_immutable_sequence.clone_and_init(name))
+ return w_value
+
@register_method('Object', 'getSlot', unwrap_spec=[object, str])
def w_object_get_slot(space, w_target, name):
try:
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 30 16:57:59 2009
@@ -1,5 +1,5 @@
from pypy.lang.io.parserhack import parse, interpret
-from pypy.lang.io.model import W_Object, W_Message, W_Number
+from pypy.lang.io.model import W_Object, W_Message, W_Number, W_ImmutableSequence
import py.test
@@ -212,4 +212,13 @@
inp = 'stopStatus(return 42)'
res, space = interpret(inp)
- assert res is space.w_return
\ No newline at end of file
+ assert res is space.w_return
+
+def test_set_slot_with_type():
+ inp = """a := Object clone
+ setSlotWithType("foo", a)
+ """
+ res, space = interpret(inp)
+ assert isinstance(res.slots['type'], W_ImmutableSequence)
+ assert res.slots['type'].value == 'foo'
+ assert space.w_lobby.slots['foo'] == res
\ No newline at end of file
More information about the Pypy-commit
mailing list