[pypy-commit] pypy dynamic-specialized-tuple: consts with more types

alex_gaynor noreply at buildbot.pypy.org
Tue Apr 24 03:12:29 CEST 2012


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: dynamic-specialized-tuple
Changeset: r54705:5716a96a3c7f
Date: 2012-04-23 21:12 -0400
http://bitbucket.org/pypy/pypy/changeset/5716a96a3c7f/

Log:	consts with more types

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
@@ -7,7 +7,7 @@
 from pypy.annotation import model as annmodel
 from pypy.annotation.bookkeeper import getbookkeeper
 from pypy.rlib import longlong2float
-from pypy.rpython.annlowlevel import (hlstr, llstr, llhelper,
+from pypy.rpython.annlowlevel import (hlstr, llstr, llunicode, llhelper,
     cast_instance_to_base_ptr)
 from pypy.rpython.rclass import getinstancerepr
 from pypy.rpython.extregistry import ExtRegistryEntry
@@ -214,6 +214,14 @@
         for idx, (char, obj) in enumerate(zip(value.shape, value.storage)):
             if char == INT:
                 storage.data[idx] = rffi.cast(llmemory.Address, obj)
+            elif char == BOOL:
+                storage.data[idx] = rffi.cast(llmemory.Address, obj)
+            elif char == FLOAT:
+                storage.data[idx] = rffi.cast(llmemory.Address, longlong2float.float2longlong(obj))
+            elif char == STRING:
+                storage.data[idx] = llmemory.cast_ptr_to_adr(llstr(obj))
+            elif char == UNICODE:
+                storage.data[idx] = llmemory.cast_ptr_to_adr(llunicode(obj))
             elif char == INSTANCE:
                 bk = self.rtyper.annotator.bookkeeper
                 classdef = bk.getuniqueclassdef(type(obj))
@@ -308,7 +316,7 @@
         elif elem == INT:
             yield i, rffi.cast(lltype.Signed, storage.data.items[i])
         elif elem == FLOAT:
-            yield i, longlong2float.longlong2float(rffi.cast(lltype.Signed, storage.data.items[i]))
+            yield i, rffi.cast(lltype.Signed, storage.data.items[i])
         elif elem == BOOL:
             yield i, rffi.cast(lltype.Bool, storage.data.items[i])
         else:
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
@@ -1,6 +1,6 @@
 import py
 
-from pypy.rlib import rerased_raw
+from pypy.rlib import rerased_raw, longlong2float
 from pypy.rpython.annlowlevel import hlstr
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin
 
@@ -184,6 +184,24 @@
         res = self.interpret(f, [0])
         assert res == 21
 
+    def test_const_types(self):
+        storage = rerased_raw.UntypedStorage("bfsu")
+        storage.setbool(0, True)
+        storage.setfloat(1, 2.5)
+        storage.setstr(2, "hello")
+        storage.setunicode(3, u"world!")
+
+        def f(i):
+            if i:
+                local_storage = rerased_raw.UntypedStorage("o")
+            else:
+                local_storage = storage
+            return (local_storage.getbool(0) + local_storage.getfloat(1) +
+                    len(local_storage.getstr(2)) + len(local_storage.getunicode(3)))
+
+        res = self.interpret(f, [0])
+        assert res == 14.5
+
     def test_enumerate_elements(self):
         def f():
             storage = rerased_raw.UntypedStorage("sibf")
@@ -197,7 +215,9 @@
         lst = list(rerased_raw.ll_enumerate_elements(llres))
         assert hlstr(lst[0][1]) == "abc"
         assert lst[0][0] == 0
-        assert lst[1:] == [(1, 13), (2, True), (3, 3.5)]
+        assert lst[1:3] == [(1, 13), (2, True)]
+        assert lst[3][0] == 3
+        assert longlong2float.longlong2float(lst[3][1]) == 3.5
 
 class TestUntypedStorageLLtype(LLRtypeMixin, BaseTestUntypedStorage):
     pass


More information about the pypy-commit mailing list