[pypy-svn] r66632 - in pypy/branch/io-lang/pypy/lang/io: . test
david at codespeak.net
david at codespeak.net
Sat Jul 25 21:10:52 CEST 2009
Author: david
Date: Sat Jul 25 21:10:48 2009
New Revision: 66632
Modified:
pypy/branch/io-lang/pypy/lang/io/object.py
pypy/branch/io-lang/pypy/lang/io/test/test_object.py
Log:
Some work on control flow, support for break in for loops
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 Sat Jul 25 21:10:48 2009
@@ -92,6 +92,9 @@
for i in range(start, stop, step):
w_context.slots[key] = W_Number(space, i)
t = body.eval(space, w_context, w_context)
+ if not space.is_normal_status():
+ space.normal_status()
+ break
return t
@register_method('Object', 'appendProto', unwrap_spec=[object, object])
@@ -106,4 +109,14 @@
if len(w_message.arguments) == 2:
w_receiver = w_message.arguments[1].eval(space, w_context, w_context)
- return w_msg.eval(space, w_receiver, w_receiver)
\ No newline at end of file
+ return w_msg.eval(space, w_receiver, w_receiver)
+
+
+ at register_method('Object', 'break')
+def object_break(space, w_target, w_message, w_context):
+ w_result = space.w_nil
+ if len(w_message.arguments) > 0:
+ w_result = w_message.arguments[0].eval(space, w_context, w_context)
+ space.break_status(w_result)
+ return w_target
+
\ 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 Sat Jul 25 21:10:48 2009
@@ -87,6 +87,11 @@
assert len(res.items) == 4
results = [t.value for t in res.items]
results == [0, 3, 6, 9]
+
+def test_object_for_returns_nil():
+ inp = """for(x, 1, 2, nil)"""
+ res, space = interpret(inp)
+ assert res == space.w_nil
def test_object_leaks():
inp = """a:= list();
@@ -116,4 +121,17 @@
1 doMessage(m, 2)"""
res, space = interpret(inp)
- assert res.value == 125
\ No newline at end of file
+ assert res.value == 125
+
+def test_object_break():
+ inp = """for(x, 7, 1000, break)
+ x
+ """
+ res, _ = interpret(inp)
+ assert res.value == 7
+
+def test_object_break_return_value():
+ inp = """for(x, 7, 1000, break(-1))
+ """
+ res, _ = interpret(inp)
+ assert res.value == -1
\ No newline at end of file
More information about the Pypy-commit
mailing list