[pypy-svn] rev 972 - in pypy/trunk/src/pypy/objspace/ann: . test
gvanrossum at codespeak.net
gvanrossum at codespeak.net
Mon Jun 23 10:33:18 CEST 2003
Author: gvanrossum
Date: Mon Jun 23 10:33:18 2003
New Revision: 972
Modified:
pypy/trunk/src/pypy/objspace/ann/objspace.py
pypy/trunk/src/pypy/objspace/ann/test/test_objspace.py
Log:
Got for loop working!!!
Modified: pypy/trunk/src/pypy/objspace/ann/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/ann/objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/ann/objspace.py Mon Jun 23 10:33:18 2003
@@ -32,6 +32,8 @@
if isinstance(c, (types.TypeType, Exception)):
setattr(self, 'w_' + c.__name__, self.wrap(c))
self.w_builtins = self.wrap(__builtin__)
+ # XXX This should be done differently:
+ self.w_KeyError = self.wrap(KeyError)
# Service methods whose interface is in the abstract base class
@@ -103,6 +105,15 @@
# Methods implementing Python operations
# (Many missing ones are added by make_op() below)
+ def is_(self, w_left, w_right):
+ if w_left is w_right:
+ return self.w_True
+ if isinstance(w_left, W_Constant) and isinstance(w_right, W_Constant):
+ # XXX Is this really safe?
+ if w_left.value is w_right.value:
+ return self.w_True
+ return W_Integer()
+
def add(self, w_left, w_right):
try:
left = self.unwrap(w_left)
@@ -142,9 +153,29 @@
else:
return W_Anything()
+ def iter(self, w_iterable):
+ if isinstance(w_iterable, W_Constant):
+ value = w_iterable.value
+ try:
+ it = iter(value)
+ except:
+ raise OperationError(self.wrap(AttributeError),
+ self.wrap(AttributeError("__iter__")))
+ return W_Anything()
+
+ def next(self, w_iterator):
+ if hasattr(w_iterator, "force"):
+ if w_iterator.force:
+ return W_Anything()
+ raise NoValue
+ raise IndeterminateCondition(w_iterator)
+
def call(self, w_func, w_args, w_kwds):
- func = self.unwrap(w_func) # Would be bad it it was W_Anything
- code = func.func_code
+ func = self.unwrap(w_func) # XXX What if this fails?
+ try:
+ code = func.func_code
+ except AttributeError:
+ return W_Anything()
bytecode = self.bytecodecache.get(code)
if bytecode is None:
bytecode = PyByteCode()
Modified: pypy/trunk/src/pypy/objspace/ann/test/test_objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/ann/test/test_objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/ann/test/test_objspace.py Mon Jun 23 10:33:18 2003
@@ -95,6 +95,15 @@
'f', [self.space.wrap(5)])
self.assertEquals(type(x), W_Integer)
+ def test_for(self):
+ x = self.codetest("def f(i):\n"
+ " for x in range(i):\n"
+ " i = i-1\n"
+ " return i\n",
+ 'f', [W_Integer()])
+ self.assertEquals(type(x), W_Integer)
+
+
def dont_test_global(self):
# XXX This will never work, because we don't handle mutating globals
x = self.codetest("def f(i, j):\n"
More information about the Pypy-commit
mailing list