[pypy-svn] rev 1480 - in pypy/trunk/src/pypy/objspace/flow: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Sep 30 19:13:17 CEST 2003
Author: arigo
Date: Tue Sep 30 19:12:58 2003
New Revision: 1480
Modified:
pypy/trunk/src/pypy/objspace/flow/objspace.py
pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py
Log:
for loops seem to work
Modified: pypy/trunk/src/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/objspace.py Tue Sep 30 19:12:58 2003
@@ -1,7 +1,7 @@
# ______________________________________________________________________
import sys, operator
import pypy
-from pypy.interpreter.baseobjspace import ObjSpace
+from pypy.interpreter.baseobjspace import ObjSpace, NoValue
from pypy.interpreter.pycode import PyCode
from pypy.interpreter.error import OperationError
from pypy.objspace.flow.wrapper import *
@@ -87,6 +87,11 @@
return g
# ____________________________________________________________
+ def do_operation(self, name, *args_w):
+ spaceop = SpaceOperation(name, args_w, W_Variable())
+ self.executioncontext.crnt_ops.append(spaceop)
+ return spaceop.result
+
def is_true(self, w_obj):
try:
obj = self.unwrap(w_obj)
@@ -97,6 +102,15 @@
context = self.getexecutioncontext()
return context.guessbool(w_obj)
+ def next(self, w_iter):
+ w_tuple = self.do_operation("next_and_flag", w_iter)
+ w_flag = self.do_operation("getitem", w_tuple, W_Constant(1))
+ context = self.getexecutioncontext()
+ if context.guessbool(w_flag):
+ return self.do_operation("getitem", w_tuple, W_Constant(0))
+ else:
+ raise NoValue
+
# ______________________________________________________________________
def make_op(name, symbol, arity, specialnames):
@@ -129,9 +143,7 @@
else:
return self.wrap(result)
- spaceop = SpaceOperation(name, args_w, W_Variable())
- self.executioncontext.crnt_ops.append(spaceop)
- return spaceop.result
+ return self.do_operation(name, *args_w)
setattr(FlowObjSpace, name, generic_operator)
Modified: pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py Tue Sep 30 19:12:58 2003
@@ -76,5 +76,13 @@
" return total\n",
'f')
+ def test_simple_for(self):
+ x = self.codetest("def f(lst):\n"
+ " total = 0\n"
+ " for i in lst:\n"
+ " total += i\n"
+ " return total\n",
+ 'f')
+
if __name__ == '__main__':
test.main()
More information about the Pypy-commit
mailing list