[pypy-svn] r22457 - in pypy/dist/pypy: annotation rpython rpython/lltypesystem rpython/memory rpython/memory/test

mwh at codespeak.net mwh at codespeak.net
Thu Jan 19 18:18:02 CET 2006


Author: mwh
Date: Thu Jan 19 18:17:59 2006
New Revision: 22457

Modified:
   pypy/dist/pypy/annotation/model.py
   pypy/dist/pypy/rpython/lltypesystem/lltype.py
   pypy/dist/pypy/rpython/memory/lladdress.py
   pypy/dist/pypy/rpython/memory/test/test_address.py
   pypy/dist/pypy/rpython/objectmodel.py
   pypy/dist/pypy/rpython/raddress.py
   pypy/dist/pypy/rpython/rbuiltin.py
Log:
allow rtyping of calls to the offsetof function.


Modified: pypy/dist/pypy/annotation/model.py
==============================================================================
--- pypy/dist/pypy/annotation/model.py	(original)
+++ pypy/dist/pypy/annotation/model.py	Thu Jan 19 18:17:59 2006
@@ -522,6 +522,7 @@
     (SomeChar(), lltype.Char),
     (SomeUnicodeCodePoint(), lltype.UniChar),
     (SomeAddress(), lladdress.Address),
+    (SomeOffset(), lladdress.Offset),
 ]
 
 def annotation_to_lltype(s_val, info=None):

Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lltype.py	Thu Jan 19 18:17:59 2006
@@ -1,6 +1,7 @@
 import weakref
 import py
 from pypy.rpython.rarithmetic import r_uint, r_ulonglong, r_longlong
+from pypy.rpython.objectmodel import Symbolic
 from pypy.tool.uid import Hashable
 from pypy.tool.tls import tlsobject
 from types import NoneType
@@ -500,6 +501,8 @@
         if tp is unicode:
             assert len(val) == 1
             return UniChar
+        if issubclass(tp, Symbolic):
+            return val.lltype()
         raise TypeError("typeOf(%r object)" % (tp.__name__,))
 
 class InvalidCast(TypeError):

Modified: pypy/dist/pypy/rpython/memory/lladdress.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lladdress.py	(original)
+++ pypy/dist/pypy/rpython/memory/lladdress.py	Thu Jan 19 18:17:59 2006
@@ -134,9 +134,14 @@
         from pypy.annotation import model
         return model.SomeOffset()
 
+    def lltype(self):
+        return Offset
+
     def __repr__(self):
         return "<OffsetOf %r %r>" % (self.TYPE, self.fldname)
 
+Offset = lltype.Primitive("Offset", OffsetOf(lltype.Void, ''))
+
 def sizeof(TYPE, n=None):
     pass
 

Modified: pypy/dist/pypy/rpython/memory/test/test_address.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_address.py	(original)
+++ pypy/dist/pypy/rpython/memory/test/test_address.py	Thu Jan 19 18:17:59 2006
@@ -217,6 +217,27 @@
         graph = graphof(a.translator, f)
         assert graph.startblock.operations[0].result.concretetype == Address
 
+
+    def test_simple_offsetof(self):
+        from pypy.rpython.lltypesystem import lltype
+        from pypy.rpython.memory.lladdress import offsetof
+        S = lltype.GcStruct('S', ('x', lltype.Bool), ('y', lltype.Signed))
+        def f():
+            return offsetof(S, 'x') + offsetof(S, 'y')
+        a = RPythonAnnotator()
+        s = a.build_types(f, [])
+        rtyper = RPythonTyper(a)
+        rtyper.specialize() #does not raise
+
+        coff = offsetof(S, 'y')
+        def f():
+            return coff
+        a = RPythonAnnotator()
+        s = a.build_types(f, [])
+        rtyper = RPythonTyper(a)
+        rtyper.specialize() #does not raise
+
+
 class TestAddressInLLInterp(object):
     def test_null(self):
         def f():

Modified: pypy/dist/pypy/rpython/objectmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/objectmodel.py	(original)
+++ pypy/dist/pypy/rpython/objectmodel.py	Thu Jan 19 18:17:59 2006
@@ -8,6 +8,9 @@
     def annotation(self):
         return None
 
+    def lltype(self):
+        return None
+
 import new
 import weakref
 

Modified: pypy/dist/pypy/rpython/raddress.py
==============================================================================
--- pypy/dist/pypy/rpython/raddress.py	(original)
+++ pypy/dist/pypy/rpython/raddress.py	Thu Jan 19 18:17:59 2006
@@ -1,7 +1,7 @@
 # rtyping of memory address operations
 from pypy.annotation.pairtype import pairtype
 from pypy.annotation import model as annmodel
-from pypy.rpython.memory.lladdress import NULL, Address
+from pypy.rpython.memory.lladdress import NULL, Address, Offset
 from pypy.rpython.rmodel import Repr, IntegerRepr
 from pypy.rpython.lltypesystem import lltype
 
@@ -110,3 +110,20 @@
         v_addr1, v_addr2 = hop.inputargs(Address, Address)
         return hop.genop('adr_ge', [v_addr1, v_addr2], resulttype=lltype.Bool)
 
+
+class __extend__(annmodel.SomeOffset):
+    def rtyper_makerepr(self, rtyper):
+        return offset_repr
+    
+    def rtyper_makekey(self):
+        return self.__class__,
+
+class OffsetRepr(Repr):
+    lowleveltype = Offset
+
+offset_repr = OffsetRepr()
+
+class __extend__(pairtype(OffsetRepr, OffsetRepr)):
+    def rtype_add((r_offset1, r_offset2), hop):
+        v_offset1, v_offset2 = hop.inputargs(Offset, Offset)
+        return hop.genop('offset_add', [v_offset1, v_offset2], resulttype=Offset)

Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/rbuiltin.py	Thu Jan 19 18:17:59 2006
@@ -378,6 +378,13 @@
 BUILTIN_TYPER[lladdress.raw_free] = rtype_raw_free
 BUILTIN_TYPER[lladdress.raw_memcopy] = rtype_raw_memcopy
 
+def rtype_offsetof(hop):
+    from pypy.rpython.memory.lladdress import Offset
+    TYPE, field = hop.inputargs(lltype.Void, lltype.Void)
+    return hop.inputconst(Offset, lladdress.offsetof(TYPE.value, field.value))
+
+BUILTIN_TYPER[lladdress.offsetof] = rtype_offsetof
+
 # _________________________________________________________________
 # non-gc objects
 



More information about the Pypy-commit mailing list