[pypy-svn] r22551 - in pypy/dist/pypy/rpython: l3interp l3interp/test lltypesystem
mwh at codespeak.net
mwh at codespeak.net
Mon Jan 23 19:43:13 CET 2006
Author: mwh
Date: Mon Jan 23 19:43:06 2006
New Revision: 22551
Modified:
pypy/dist/pypy/rpython/l3interp/l3interp.py
pypy/dist/pypy/rpython/l3interp/test/test_convert.py
pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py
pypy/dist/pypy/rpython/lltypesystem/llmemory.py
Log:
(arre,mwh)
Note a deficiency in l3interp.convertgraph().
A test and implementation for getfield_ptr and what was necessary to
l3interp this on the llmemory style of address.
Modified: pypy/dist/pypy/rpython/l3interp/l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/l3interp.py (original)
+++ pypy/dist/pypy/rpython/l3interp/l3interp.py Mon Jan 23 19:43:06 2006
@@ -193,6 +193,11 @@
o = self.getoffset()
self.stack_int.append((p + o).signed[0])
+ def op_getfield_ptr(self):
+ p = self.getptr()
+ o = self.getoffset()
+ self.stack_ptr.append((p + o).address[0])
+
def op_setfield_int(self):
p = self.getptr()
o = self.getoffset()
Modified: pypy/dist/pypy/rpython/l3interp/test/test_convert.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/test/test_convert.py (original)
+++ pypy/dist/pypy/rpython/l3interp/test/test_convert.py Mon Jan 23 19:43:06 2006
@@ -76,3 +76,13 @@
assert isinstance(result, l3interp.L3Integer)
assert result.intval == 2
+def dont_test_call():
+ def f():
+ return 2
+ def g():
+ return f()
+ l3graph = l3ify(g, [])
+ result = l3interp.l3interpret(l3graph, [], [], [])
+ assert isinstance(result, l3interp.L3Integer)
+ assert result.intval == g()
+
Modified: pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py (original)
+++ pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py Mon Jan 23 19:43:06 2006
@@ -194,3 +194,47 @@
+def test_getfield_complex():
+ class C:
+ def __init__(self, x):
+ self.x = x
+ one = C(1)
+ two = C(2)
+
+ class D:
+ def __init__(self, c1, c2):
+ self.c1 = c1
+ self.c2 = c2
+
+ d1 = D(one, two)
+ d2 = D(two, one)
+
+ def f(n, m):
+ if n:
+ if m:
+ return d1.c1.x
+ else:
+ return d1.c2.x
+ else:
+ if m:
+ return d2.c1.x
+ else:
+ return d2.c2.x
+
+ l3graph = l3ify(f, [int, int])
+
+ def entry_point(x, y):
+ value = l3interp.l3interpret(l3graph, [x, y], [], [])
+ assert isinstance(value, l3interp.L3Integer)
+ return value.intval
+
+ for x in 0, 1:
+ for y in 0, 1:
+ assert entry_point(x, y) == f(x, y)
+
+ fn = translate(entry_point, [int, int])
+
+ for x in 0, 1:
+ for y in 0, 1:
+ assert fn(x, y) == f(x, y)
+
Modified: pypy/dist/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/llmemory.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/llmemory.py Mon Jan 23 19:43:06 2006
@@ -63,14 +63,36 @@
ob = self.addr.ob
for n in self.addr.offset.fldnames:
ob = getattr(ob, n)
- # XXX will need to do pointers differently!
- assert lltype.typeOf(ob) == self.TYPE
- return ob
+ return self.vet(ob)
+
+ def __setitem__(self, index, value):
+ assert index == 0
+ ob = self.addr.ob
+ for n in self.addr.offset.fldnames[:-1]:
+ ob = getattr(ob, n)
+ fld = self.addr.offset.fldnames[-1]
+ assert lltype.typeOf(value) == self.TYPE
+ assert lltype.typeOf(ob).TO._flds[fld] == self.TYPE
+ setattr(ob, fld, value)
class _signed_fakeaccessor(_fakeaccessor):
TYPE = lltype.Signed
+ def vet(self, value):
+ assert lltype.typeOf(value) == self.TYPE
+ return value
+
+class _address_fakeaccessor(_fakeaccessor):
+ TYPE = None
+
+ def vet(self, value):
+ # XXX is this the right check for "Ptr-ness" ?
+ assert isinstance(value, lltype._ptr)
+ return fakeaddress(value)
+
+
fakeaddress.signed = property(_signed_fakeaccessor)
+fakeaddress.address = property(_address_fakeaccessor)
Address = lltype.Primitive("Address", fakeaddress(None))
More information about the Pypy-commit
mailing list