[pypy-svn] r39841 - in pypy/dist/pypy/translator/llvm: . test
rxe at codespeak.net
rxe at codespeak.net
Sat Mar 3 19:35:50 CET 2007
Author: rxe
Date: Sat Mar 3 19:35:49 2007
New Revision: 39841
Modified:
pypy/dist/pypy/translator/llvm/node.py
pypy/dist/pypy/translator/llvm/structnode.py
pypy/dist/pypy/translator/llvm/test/test_lltype.py
Log:
(mwh, rxe) implement get_childref() on FixedSizeArrayNode
Modified: pypy/dist/pypy/translator/llvm/node.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/node.py (original)
+++ pypy/dist/pypy/translator/llvm/node.py Sat Mar 3 19:35:49 2007
@@ -59,9 +59,13 @@
__slots__ = "".split()
def get_ref(self):
- """ Returns a reference as used for operations in blocks. """
+ """ Returns a reference as used for operations in blocks for pbc. """
return self.ref
+ def get_childref(self, index):
+ """ Returns a reference as used for operations in blocks for internals of a pbc. """
+ raise AttributeError("Must be implemented in subclass")
+
def get_pbcref(self, toptr):
""" Returns a reference as a pointer used per pbc. """
return self.ref
Modified: pypy/dist/pypy/translator/llvm/structnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/structnode.py (original)
+++ pypy/dist/pypy/translator/llvm/structnode.py Sat Mar 3 19:35:49 2007
@@ -51,6 +51,11 @@
def __str__(self):
return "<FixedArrayTypeNode %r>" % self.ref
+ def setup(self):
+ fields = self._fields()
+ if fields:
+ self.db.prepare_type(fields[0])
+
def writedatatypedecl(self, codewriter):
codewriter.fixedarraydef(self.ref,
self.struct.length,
@@ -186,24 +191,21 @@
return "%s [\n %s\n ]\n" % (self.get_typerepr(), all_values)
def get_childref(self, index):
- pos = 0
- found = False
- for name in self.structtype._names_without_voids():
- if name == index:
- found = True
- break
- pos += 1
-
- return "getelementptr(%s* %s, int 0, int %s)" %(
+ ptr_type = self.db.repr_type(self.structtype.OF) + '*'
+ to_one_type = self.db.repr_type(lltype.FixedSizeArray(self.structtype.OF, 1)) + '*'
+ ptr = "getelementptr(%s* %s, int 0, int %s)" % (
self.get_typerepr(),
self.get_ref(),
- pos)
+ index)
+ return "cast(%s %s to %s)" % (ptr_type, ptr, to_one_type)
def setup(self):
if isinstance(self.value, lltype._subarray):
- return
- super(FixedSizeArrayNode, self).setup()
-
+ p, c = lltype.parentlink(self.value)
+ if p is not None:
+ self.db.prepare_constant(lltype.typeOf(p), p)
+ else:
+ super(FixedSizeArrayNode, self).setup()
class StructVarsizeNode(StructNode):
""" A varsize struct constant. Can simply contain
Modified: pypy/dist/pypy/translator/llvm/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_lltype.py (original)
+++ pypy/dist/pypy/translator/llvm/test/test_lltype.py Sat Mar 3 19:35:49 2007
@@ -352,6 +352,7 @@
assert res == -1
def test_direct_arrayitems():
+ py.test.skip("wip")
for a in [malloc(GcArray(Signed), 5),
malloc(FixedSizeArray(Signed, 5), immortal=True)]:
a[0] = 0
@@ -372,7 +373,6 @@
finally:
a[n] = saved
- py.test.skip("wip")
fn = compile_function(llf, [int])
res = fn(0)
assert res == 1000 + 10 + 30 + 40
@@ -398,8 +398,21 @@
res = fn(34)
assert res == 34
+def test_prebuilt_simple_subarrays():
+ a2 = malloc(FixedSizeArray(Signed, 5), immortal=True)
+ a2[1] = 42
+ p2 = direct_ptradd(direct_arrayitems(a2), 1)
+ def llf():
+ a2[1] += 100
+ return p2[0]
+
+ fn = compile_function(llf, [])
+ res = fn()
+ assert res == 142
+
def test_prebuilt_subarrays():
- a1 = malloc(GcArray(Signed), 5)
+ py.test.skip("wip")
+ a1 = malloc(GcArray(Signed), 5, zero=True)
a2 = malloc(FixedSizeArray(Signed, 5), immortal=True)
s = malloc(GcStruct('S', ('x', Signed), ('y', Signed)))
a1[3] = 7000
@@ -417,53 +430,7 @@
s.y += 1
return p1[0] + p2[0] + p3[0] + p4[0]
- py.test.skip("wip")
fn = compile_function(llf, [])
res = fn()
assert res == 8765
-def test_pystruct():
- PS1 = PyStruct('PS1', ('head', PyObject), ('x', Signed),
- hints = {'inline_head': True})
- class mytype(object):
- pass
- mytype_ptr = pyobjectptr(mytype)
- def llf():
- p = malloc(PS1, flavor='cpy', extra_args=(mytype_ptr,))
- return cast_pointer(Ptr(PyObject), p)
-
- py.test.skip("wip")
- fn = compile_function(llf)
- res = fn()
- assert type(res).__name__.endswith('mytype')
-
-def test_pystruct_prebuilt():
- py.test.skip("wip")
- PS1 = PyStruct('PS1', ('head', PyObject), ('x', Signed),
- hints = {'inline_head': True})
- class mytype(object):
- pass
-
- def llsetup(phead):
- "Called when the CPython ext module is imported."
- p = cast_pointer(Ptr(PS1), phead)
- p.x = 27
-
- mytype_ptr = pyobjectptr(mytype)
- p = malloc(PS1, flavor='cpy', extra_args=(mytype_ptr,))
- p.x = -5 # overridden by llsetup()
-
- def llf():
- return p.x
-
- def process(t):
- rtyper = t.buildrtyper()
- rtyper.specialize()
- llsetup_ptr = rtyper.annotate_helper_fn(llsetup, [Ptr(PyObject)])
- phead = cast_pointer(Ptr(PyObject), p)
- phead._obj.setup_fnptr = llsetup_ptr
-
- self.process = process
- fn = compile_function(llf)
- res = fn()
- assert res == 27
More information about the Pypy-commit
mailing list