[pypy-commit] pypy dynamic-specialized-tuple: progress in supporting prebuilt untyped storage in the C backend

fijal noreply at buildbot.pypy.org
Mon Apr 23 17:50:47 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: dynamic-specialized-tuple
Changeset: r54679:21c67be4174e
Date: 2012-04-23 17:49 +0200
http://bitbucket.org/pypy/pypy/changeset/21c67be4174e/

Log:	progress in supporting prebuilt untyped storage in the C backend

diff --git a/pypy/rlib/rerased_raw.py b/pypy/rlib/rerased_raw.py
--- a/pypy/rlib/rerased_raw.py
+++ b/pypy/rlib/rerased_raw.py
@@ -127,6 +127,7 @@
 UNTYPEDSTORAGE = lltype.GcStruct("untypedstorage",
     ("shape", lltype.Ptr(STR)),
     ("data", lltype.Array(llmemory.Address)),
+    hints={'untyped_storage': True},
     rtti=True,
 )
 
@@ -298,3 +299,16 @@
     @classmethod
     def ll_getlength(cls, arr):
         return len(arr.shape.chars)
+
+def ll_enumerate_elements(storage):
+    for i, elem in enumerate(storage.shape.chars):
+        if elem in [INSTANCE, STRING, UNICODE]:
+            yield storage.data[i].ptr
+        elif elem == INT:
+            yield rffi.cast(lltype.Signed, storage.data[i])
+        elif elem == FLOAT:
+            yield rffi.cast(lltype.Float, storage.data[i])
+        elif elem == BOOL:
+            yield rffi.cast(lltype.Bool, storage.data[i])
+        else:
+            assert False
diff --git a/pypy/rlib/test/test_rerased_raw.py b/pypy/rlib/test/test_rerased_raw.py
--- a/pypy/rlib/test/test_rerased_raw.py
+++ b/pypy/rlib/test/test_rerased_raw.py
@@ -184,5 +184,19 @@
         res = self.interpret(f, [0])
         assert res == 21
 
+    def test_enumerate_elements(self):
+        def f():
+            storage = rerased_raw.UntypedStorage("sibf")
+            storage.setint(1, 13)
+            storage.setstr(0, "abc")
+            storage.setfloat(3, 3.5)
+            storage.setbool(2, True)
+            return storage
+
+        llres = self.interpret(f, [])
+        lst = list(rerased_raw.ll_enumerate_elements(llres))
+        assert hlstr(lst[0]) == "abc"
+        assert lst[1:] == [13, True, 3.5]
+
 class TestUntypedStorageLLtype(LLRtypeMixin, BaseTestUntypedStorage):
     pass
diff --git a/pypy/translator/c/node.py b/pypy/translator/c/node.py
--- a/pypy/translator/c/node.py
+++ b/pypy/translator/c/node.py
@@ -13,6 +13,7 @@
 from pypy.rlib import exports
 from pypy.rlib.rfloat import isfinite
 from pypy.rlib.rstackovf import _StackOverflow
+from pypy.rlib.rerased_raw import xxx
 from pypy.translator.c import extfunc
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from py.builtin import BaseException
@@ -576,6 +577,14 @@
 
     def enum_dependencies(self):
         T = self.getTYPE()
+        if T._hints.get('untyped_storage', False):
+            arrayfld = T._arrayfld
+            shapefld = [fld for fld in T._flds if fld != arrayfld][0]
+            shape = getattr(self.obj, shapefld)
+            yield shape
+            for elem in shape.chars:
+                import pdb
+                pdb.set_trace()
         for name in T._names:
             yield getattr(self.obj, name)
 


More information about the pypy-commit mailing list