[pypy-svn] r26845 - in pypy/dist/pypy/rpython/lltypesystem: . test
arigo at codespeak.net
arigo at codespeak.net
Sat May 6 10:41:18 CEST 2006
Author: arigo
Date: Sat May 6 10:41:17 2006
New Revision: 26845
Modified:
pypy/dist/pypy/rpython/lltypesystem/rtagged.py
pypy/dist/pypy/rpython/lltypesystem/test/test_rtagged.py
Log:
Fix and test for TaggedInstanceRepr.convert_const().
Modified: pypy/dist/pypy/rpython/lltypesystem/rtagged.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rtagged.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/rtagged.py Sat May 6 10:41:17 2006
@@ -5,6 +5,7 @@
from pypy.rpython.lltypesystem.rclass import MissingRTypeAttribute
from pypy.rpython.lltypesystem.rclass import ll_issubclass_const
from pypy.rpython.rmodel import TyperError, inputconst
+from pypy.rpython.objectmodel import UnboxedValue
class TaggedInstanceRepr(InstanceRepr):
@@ -52,11 +53,11 @@
return v_instance, False # don't call __init__
def convert_const(self, value):
- if value is None:
- return self.null_instance()
- else:
+ if isinstance(value, UnboxedValue):
number = value.getvalue()
return ll_int_to_unboxed(self.lowleveltype, number)
+ else:
+ return InstanceRepr.convert_const(self, value)
def getvalue_from_unboxed(self, llops, vinst):
assert not self.is_parent
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_rtagged.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_rtagged.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_rtagged.py Sat May 6 10:41:17 2006
@@ -66,17 +66,35 @@
def test_prebuilt():
c = C(111)
- def fn(n):
+ b = B(939393)
+
+ def makeint(n):
if n < 0:
x = c
- else:
+ elif n > 0:
x = C(n)
- return x.smallint
+ else:
+ x = b
+ return x
+
+ def fn(n):
+ x = makeint(n)
+ if isinstance(x, B):
+ return 'B', x.normalint
+ elif isinstance(x, C):
+ return 'C', x.smallint
+ else:
+ return 'A', 0
res = interpret(fn, [12])
- assert res == 12
+ assert res.item0 == 'C'
+ assert res.item1 == 12
res = interpret(fn, [-1])
- assert res == 111
+ assert res.item0 == 'C'
+ assert res.item1 == 111
+ res = interpret(fn, [0])
+ assert res.item0 == 'B'
+ assert res.item1 == 939393
def test_C_or_None():
def g(x):
More information about the Pypy-commit
mailing list