[pypy-svn] r22142 - in pypy/dist/pypy: annotation rpython rpython/memory rpython/memory/test
pedronis at codespeak.net
pedronis at codespeak.net
Sat Jan 14 14:41:43 CET 2006
Author: pedronis
Date: Sat Jan 14 14:41:41 2006
New Revision: 22142
Modified:
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/rpython/memory/lladdress.py
pypy/dist/pypy/rpython/memory/test/test_address.py
pypy/dist/pypy/rpython/objectmodel.py
Log:
expererimenting with adding offset/sizeof/itemoffsetof to the lltype model. Annotation for offsetof
and offsetof constants.
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Sat Jan 14 14:41:41 2006
@@ -18,7 +18,7 @@
from pypy.annotation import description
from pypy.interpreter.argument import Arguments, ArgErr
from pypy.rpython.rarithmetic import r_uint, r_ulonglong, r_longlong
-from pypy.rpython.objectmodel import r_dict
+from pypy.rpython.objectmodel import r_dict, Symbolic
from pypy.tool.algo.unionfind import UnionFind
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.ootypesystem import ootype
@@ -302,6 +302,8 @@
if x is sys: # special case constant sys to someobject
return SomeObject()
tp = type(x)
+ if issubclass(tp, Symbolic): # symbolic constants support
+ return x.annotation()
if tp is bool:
result = SomeBool()
elif tp is int:
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Sat Jan 14 14:41:41 2006
@@ -502,6 +502,15 @@
BUILTIN_ANALYZERS[lladdress.raw_memcopy] = raw_memcopy
#_________________________________
+# offsetof/sizeof
+
+def offsetof(TYPE, fldname):
+ return SomeInteger()
+
+BUILTIN_ANALYZERS[lladdress.offsetof] = offsetof
+
+
+#_________________________________
# external functions
Modified: pypy/dist/pypy/rpython/memory/lladdress.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/lladdress.py (original)
+++ pypy/dist/pypy/rpython/memory/lladdress.py Sat Jan 14 14:41:41 2006
@@ -119,3 +119,29 @@
"char": lltype.Char,
"address": Address,
}
+
+# sizeof, offsetof
+
+from pypy.rpython.objectmodel import Symbolic
+
+class OffsetOf(Symbolic):
+
+ def __init__(self, TYPE, fldname):
+ self.TYPE = TYPE
+ self.fldname = fldname
+
+ def annotation(self):
+ from pypy.annotation import model
+ return model.SomeInteger()
+
+ def __repr__(self):
+ return "<OffsetOf %r %r>" % (self.TYPE, self.fldname)
+
+def sizeof(TYPE, n=None):
+ pass
+
+def offsetof(TYPE, fldname):
+ return OffsetOf(TYPE, fldname)
+
+def itemoffsetof(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 Sat Jan 14 14:41:41 2006
@@ -112,6 +112,21 @@
assert not f(0)
assert not f(-1)
+ def test_simple_offsetof(self):
+ from pypy.rpython.lltypesystem import lltype
+ from pypy.rpython.memory.lladdress import offsetof
+ S = lltype.GcStruct(('x', lltype.Bool), ('y', lltype.Signed))
+ def f():
+ return offsetof(S, 'x') + offsetof(S, 'y')
+ a = RPythonAnnotator()
+ s = a.build_types(f, [])
+ assert s.knowntype == int
+ coff = offsetof(S, 'y')
+ def f():
+ return coff
+ a = RPythonAnnotator()
+ s = a.build_types(f, [])
+ assert s.knowntype == int
class TestAddressRTyping(object):
def test_null(self):
Modified: pypy/dist/pypy/rpython/objectmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/objectmodel.py (original)
+++ pypy/dist/pypy/rpython/objectmodel.py Sat Jan 14 14:41:41 2006
@@ -3,6 +3,11 @@
RPython-compliant way.
"""
+class Symbolic(object):
+
+ def annotation(self):
+ return None
+
import new
import weakref
More information about the Pypy-commit
mailing list