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

david at codespeak.net david at codespeak.net
Thu Aug 13 22:21:53 CEST 2009


Author: david
Date: Thu Aug 13 22:21:52 2009
New Revision: 66814

Modified:
   pypy/branch/io-lang/pypy/lang/io/object.py
   pypy/branch/io-lang/pypy/lang/io/test/test_io_extensions.py
   pypy/branch/io-lang/pypy/lang/io/test/test_object.py
Log:
methods doString newSlot and updateSlot 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 Aug 13 22:21:52 2009
@@ -166,4 +166,30 @@
         w_message.arguments[0].eval(space, w_context, w_context)
     w = space.stop_status
     space.normal_status()
-    return w
\ No newline at end of file
+    return w
+    
+ at register_method('Object', 'doString', unwrap_spec=[object, str])
+def object_do_string(space, w_target, code):
+    # XXX Replace this when the actual parser is done
+    from parserhack import parse
+    ast = parse(code, space)
+    return ast.eval(space, w_target, w_target)
+    
+    
+# XXX replace with the original one in A2_Object.io when it works
+ at register_method('Object', 'newSlot', unwrap_spec=[object, str, object])
+def object_new_slot(space, w_target, name, w_value):
+    from pypy.lang.io.model import W_CFunction
+    w_target.slots[name] = w_value
+    def setSlot(space, w_target, w_message, w_context):
+        w_target.slots[name] = w_message.arguments[0].eval(space, w_context, w_context)
+        return w_target
+    w_target.slots['set%s' % (name[0].capitalize() + name[1:])] = W_CFunction(space, setSlot)
+    
+ at register_method('Object', 'updateSlot', unwrap_spec=[object, str, object])
+def object_update_slot(space, w_target, slotname, w_value):
+    assert w_target.lookup(slotname) is not None
+
+    w_target.slots[slotname] = w_value
+    return w_value
+    

Modified: pypy/branch/io-lang/pypy/lang/io/test/test_io_extensions.py
==============================================================================
--- pypy/branch/io-lang/pypy/lang/io/test/test_io_extensions.py	(original)
+++ pypy/branch/io-lang/pypy/lang/io/test/test_io_extensions.py	Thu Aug 13 22:21:52 2009
@@ -1,6 +1,6 @@
 from pypy.lang.io.parserhack import interpret
 import py
-from pypy.lang.io.model import W_Object, W_List
+from pypy.lang.io.model import W_Object, W_List, W_Block
 
 def test_map_asObject():
     inp = 'Map clone atPut("1", 12345) atPut("2", 99) atPut("3", 3) atPut("4", 234) asObject'
@@ -16,11 +16,31 @@
     assert isinstance(res, W_Object)
     assert res.protos == [space.w_object]
     
-def test_map_as_lsit():
-    py.test.skip('Depends on Map map wich itself depends on corroutines')
+def test_map_as_lit():
+    py.test.skip("Depends on ==")
     inp = 'Map clone atPut("1", 12345) atPut("2", 99) atPut("3", 3) atPut("4", 234) asList'
     res, space = interpret(inp)
     assert isinstance(res, W_List)
     l = [(ll.items[0].value, ll.items[1].value) for ll in res.items]
     assert l == [('1', 12345), ('2', 99), ('3', 3), ('4', 234)]
     
+def test_new_slot():
+    inp = """timers ::= 1"""
+    res, space = interpret(inp)
+    assert space.w_lobby.slots['timers'].value == 1
+    # assert isinstance(space.w_lobby.slots['setTimers'], W_Block)
+    
+def test_new_slot_complex():
+    inp = """a := Object clone 
+    a do(
+        timers ::= 1
+    )
+    a setTimers(99)
+    a timers"""
+    
+    res, space = interpret(inp)
+    assert res.value == 99
+    a = space.w_lobby.slots['a']
+    assert 'timers' in a.slots
+    assert 'setTimers' in a.slots
+    # assert isinstance(a.slots['setTimers'], W_Block)
\ 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 Aug 13 22:21:52 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, W_ImmutableSequence
+from pypy.lang.io.model import W_Object, W_Message, W_Number,  W_ImmutableSequence, W_Block
 import py.test
 
 
@@ -221,4 +221,37 @@
     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
+    assert space.w_lobby.slots['foo'] == res
+    
+def test_doString():
+    inp = """doString("1")"""
+    res, space = interpret(inp)
+    assert res.value == 1
+
+def test_doString_method():
+    inp = """
+    doString("method(" .. "foo" .. " = call evalArgAt(0); self)")"""
+    res, space = interpret(inp)
+    print res
+    assert isinstance(res, W_Block)
+def test_doString_method2():
+    py.test.skip()
+    inp = """
+    foo := 234
+    name := "foo"
+    setSlot("set" .. name asCapitalized,
+		doString("method(" .. name .. " = call evalArgAt(0); self)"))
+    setFoo(1)"""
+    res, space = interpret(inp)
+    assert res.slots['foo'].value == 1
+def test_object_update_slot():
+    inp = """
+    a := 3
+    a = 5
+    """
+    res, space = interpret(inp)
+    assert res.value == 5
+    assert space.w_lobby.slots['a'].value == 5
+def test_object_update_slot_raises():
+    inp = 'qwer = 23'
+    py.test.raises(Exception, 'interpret(inp)')
\ No newline at end of file



More information about the Pypy-commit mailing list