[pypy-commit] pypy dynamic-specialized-tuple: merged erase-aw-mem

alex_gaynor noreply at buildbot.pypy.org
Tue Mar 13 09:15:36 CET 2012


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: dynamic-specialized-tuple
Changeset: r53436:48a426aeecee
Date: 2012-03-13 01:07 -0700
http://bitbucket.org/pypy/pypy/changeset/48a426aeecee/

Log:	merged erase-aw-mem

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
@@ -6,11 +6,14 @@
 
 from pypy.annotation import model as annmodel
 from pypy.annotation.bookkeeper import getbookkeeper
-from pypy.rpython.annlowlevel import hlstr, llstr, llhelper
+from pypy.rpython.annlowlevel import (hlstr, llstr, llhelper,
+    cast_instance_to_base_ptr)
+from pypy.rpython.rclass import getinstancerepr
 from pypy.rpython.extregistry import ExtRegistryEntry
 from pypy.rpython.lltypesystem import rffi, lltype, llmemory
 from pypy.rpython.lltypesystem.rstr import STR, string_repr
 from pypy.rpython.rmodel import Repr
+from pypy.tool.pairtype import pairtype
 
 
 INT = "i"
@@ -70,13 +73,18 @@
     def specialize_call(self, hop):
         return hop.r_result.rtyper_new(hop)
 
+class UntypedStoragePrebuiltEntry(ExtRegistryEntry):
+    _type_ = UntypedStorage
+
+    def compute_annotation(self):
+        return SomeUntypedStorage()
 
 class SomeUntypedStorage(annmodel.SomeObject):
     def _check_idx(self, s_idx):
         assert annmodel.SomeInteger().contains(s_idx)
 
     def rtyper_makerepr(self, rtyper):
-        return UntypedStorageRepr()
+        return UntypedStorageRepr(rtyper)
 
     def method_getlength(self):
         return annmodel.SomeInteger()
@@ -111,6 +119,12 @@
         self._check_idx(s_idx)
         assert isinstance(s_obj, annmodel.SomeInstance)
 
+class __extend__(pairtype(SomeUntypedStorage, SomeUntypedStorage)):
+    def union((self, other)):
+        return SomeUntypedStorage()
+
+
+
 UNTYPEDSTORAGE = lltype.GcStruct("untypedstorage",
     ("shape", lltype.Ptr(STR)),
     ("data", lltype.Array(llmemory.Address)),
@@ -157,6 +171,9 @@
     lowleveltype = lltype.Ptr(UNTYPEDSTORAGE)
     lltype.attachRuntimeTypeInfo(lowleveltype.TO, customtraceptr=trace_untypedstorage_ptr)
 
+    def __init__(self, rtyper):
+        self.rtyper = rtyper
+
     def _read_index(self, hop):
         v_arr = hop.inputarg(self, arg=0)
         v_idx = hop.inputarg(lltype.Signed, arg=1)
@@ -172,6 +189,19 @@
         c_name = hop.inputconst(lltype.Void, "data")
         hop.genop("setinteriorfield", [v_arr, c_name, v_idx, v_value])
 
+    def convert_const(self, value):
+        storage = self.ll_new(llstr(value.shape))
+        for idx, (char, obj) in enumerate(zip(value.shape, value.storage)):
+            if char == INT:
+                storage.data[idx] = rffi.cast(llmemory.Address, obj)
+            elif char == INSTANCE:
+                bk = self.rtyper.annotator.bookkeeper
+                classdef = bk.getuniqueclassdef(type(obj))
+                instancerepr = getinstancerepr(self.rtyper, classdef)
+                ptr = instancerepr.convert_const(obj)
+                storage.data[idx] = llmemory.cast_ptr_to_adr(ptr)
+        return storage
+
     def rtyper_new(self, hop):
         [v_shape] = hop.inputargs(string_repr)
         hop.exception_cannot_occur()
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
@@ -116,4 +116,22 @@
             return storage.getshape()
 
         llres = self.interpret(f, [])
-        assert hlstr(llres) == "ooi"
\ No newline at end of file
+        assert hlstr(llres) == "ooi"
+
+    def test_const(self):
+        class A(object):
+            def __init__(self, v):
+                self.v = v
+        storage = rerased_raw.UntypedStorage("io")
+        storage.setint(0, 1)
+        storage.setinstance(1, A(20))
+        def f(i):
+            A(i)
+            if i:
+                local_storage = rerased_raw.UntypedStorage("ii")
+            else:
+                local_storage = storage
+            return local_storage.getint(0) + local_storage.getinstance(1, A).v
+
+        res = self.interpret(f, [0])
+        assert res == 21


More information about the pypy-commit mailing list