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

david at codespeak.net david at codespeak.net
Tue May 19 13:09:32 CEST 2009


Author: david
Date: Tue May 19 13:09:30 2009
New Revision: 65308

Modified:
   pypy/branch/io-lang/pypy/lang/io/object.py
   pypy/branch/io-lang/pypy/lang/io/test/test_object.py
Log:
add hasSlot and ? slots to 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	Tue May 19 13:09:30 2009
@@ -13,6 +13,19 @@
     except KeyError:
         return space.w_nil
 
+ at register_method('Object', 'hasSlot', unwrap_spec=[object, str])
+def w_object_has_slot(space, w_target, name):
+    if w_target.lookup(name) is None:
+        return space.w_false
+    return space.w_true
+
+ at register_method('Object', '?')
+def w_object_question_mark(space, w_target, w_message, w_context):
+    name = w_message.arguments[0].name
+    if w_object_has_slot(space, w_target, name) is space.w_false:
+        return space.w_nil
+    return w_message.arguments[0].eval(space, w_target, w_context)
+    
 @register_method('Object', 'method')
 def w_object_method(space, w_target, w_message, w_context):
     w_body = w_message.arguments[-1]

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 13:09:30 2009
@@ -18,4 +18,23 @@
 def test_object_anon_slot():
     inp = 'Object getSlot("+")("foo")'
     res, space = interpret(inp)
-    assert res.value == 'foo'
\ No newline at end of file
+    assert res.value == 'foo'
+
+def test_object_has_slot():
+    inp = 'Object hasSlot("foo")'
+    res, space = interpret(inp)
+    assert res is space.w_false
+    
+    inp2 = 'Object hasSlot("clone")'
+    res, space = interpret(inp2)
+    assert res is space.w_true
+        
+def test_object_question_mark_simple():
+    inp = 'Object do(a := 1); Object ?a'
+    res, space = interpret(inp)
+    assert res is not space.w_nil
+    assert res.value == 1
+    
+    inp2 = 'Object ?a'
+    res, space = interpret(inp2)
+    assert res is space.w_nil



More information about the Pypy-commit mailing list