[pypy-svn] r26853 - in pypy/dist/pypy/translator/c: . test
arigo at codespeak.net
arigo at codespeak.net
Sat May 6 12:13:58 CEST 2006
Author: arigo
Date: Sat May 6 12:13:57 2006
New Revision: 26853
Added:
pypy/dist/pypy/translator/c/test/test_rtagged.py (contents, props changed)
Modified:
pypy/dist/pypy/translator/c/database.py
Log:
GenC support for prebuilt tagged pointers that are actually odd integers.
Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py (original)
+++ pypy/dist/pypy/translator/c/database.py Sat May 6 12:13:57 2006
@@ -168,6 +168,10 @@
return PrimitiveName[T](obj, self)
elif isinstance(T, Ptr):
if obj: # test if the ptr is non-NULL
+ if isinstance(obj._obj, int):
+ # special case for tagged odd-valued pointers
+ return '((%s) %d)' % (cdecl(self.gettype(T), ''),
+ obj._obj)
node = self.getcontainernode(obj._obj)
return node.ptrname
else:
Added: pypy/dist/pypy/translator/c/test/test_rtagged.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/c/test/test_rtagged.py Sat May 6 12:13:57 2006
@@ -0,0 +1,78 @@
+import sys, os
+from pypy.rpython.objectmodel import UnboxedValue
+
+
+class A(object):
+ def meth(self, x):
+ raise NotImplementedError
+
+class B(A):
+ def __init__(self, normalint):
+ self.normalint = normalint
+ def meth(self, x):
+ return self.normalint + x + 2
+
+class C(A, UnboxedValue):
+ __slots__ = 'smallint'
+ def meth(self, x):
+ return self.smallint + x + 3
+
+def makeint(n):
+ try:
+ return C(n)
+ except OverflowError: # 'n' out of range
+ return B(n)
+
+def makeint2(n):
+ if n < 0:
+ x = prebuilt_c
+ elif n > 0:
+ x = C(n)
+ else:
+ x = prebuilt_b
+ return x
+
+prebuilt_c = C(111)
+prebuilt_b = B(939393)
+
+def entry_point(argv):
+ n = 100 + len(argv)
+ assert C(n).getvalue() == n
+
+ x = makeint(42)
+ assert isinstance(x, C)
+ assert x.smallint == 42
+
+ x = makeint(sys.maxint)
+ assert isinstance(x, B)
+ assert x.normalint == sys.maxint
+
+ x = makeint2(12)
+ assert x.meth(1000) == 1015
+
+ x = makeint2(-1)
+ assert x.meth(1000) == 1114
+
+ x = makeint2(0)
+ assert x.meth(1000) == 940395
+
+ os.write(1, "ALL OK\n")
+ return 0
+
+# ____________________________________________________________
+# only with Boehm so far
+
+from pypy.translator.interactive import Translation
+from pypy import conftest
+
+def test_tagged_boehm():
+ t = Translation(entry_point, standalone=True, gc='boehm')
+ try:
+ exename = t.compile_c()
+ finally:
+ if conftest.option.view:
+ t.view()
+ g = os.popen(exename, 'r')
+ data = g.read()
+ g.close()
+ assert data.rstrip().endswith('ALL OK')
More information about the Pypy-commit
mailing list