[pypy-svn] r16181 - in pypy/dist/pypy/rpython: . test
pedronis at codespeak.net
pedronis at codespeak.net
Fri Aug 19 21:08:50 CEST 2005
Author: pedronis
Date: Fri Aug 19 21:08:49 2005
New Revision: 16181
Modified:
pypy/dist/pypy/rpython/rclass.py
pypy/dist/pypy/rpython/test/test_nongc.py
Log:
fixed is/_alloc_flavor_ bug
Modified: pypy/dist/pypy/rpython/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/rclass.py (original)
+++ pypy/dist/pypy/rpython/rclass.py Fri Aug 19 21:08:49 2005
@@ -632,12 +632,15 @@
return NotImplemented
def rtype_is_((r_ins1, r_ins2), hop):
+ if r_ins1.needsgc != r_ins2.needsgc:
+ # obscure logic, the is can be true only if both are None
+ v_ins1, v_ins2 = hop.inputargs(r_ins1.common_repr(), r_ins2.common_repr())
+ return hop.gendirectcall(ll_both_none, v_ins1, v_ins2)
+ nogc = not (r_ins1.needsgc and r_ins2.needsgc)
if r_ins1.classdef is None or r_ins2.classdef is None:
basedef = None
- nogc = not (r_ins1.needsgc and r_ins2.needsgc)
else:
basedef = r_ins1.classdef.commonbase(r_ins2.classdef)
- nogc = False
r_ins = getinstancerepr(r_ins1.rtyper, basedef, nogc=nogc)
return pairtype(Repr, Repr).rtype_is_(pair(r_ins, r_ins), hop)
@@ -647,6 +650,9 @@
v = rpair.rtype_eq(hop)
return hop.genop("bool_not", [v], resulttype=Bool)
+def ll_both_none(ins1, ins2):
+ return not ins1 and not ins2
+
# ____________________________________________________________
def rtype_new_instance(rtyper, cls, llops):
Modified: pypy/dist/pypy/rpython/test/test_nongc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_nongc.py (original)
+++ pypy/dist/pypy/rpython/test/test_nongc.py Fri Aug 19 21:08:49 2005
@@ -108,13 +108,13 @@
res = interpret(f, [0])
assert res == 0
-
def test_is():
class A:
_alloc_flavor_ = "raw"
pass
class B(A): pass
- class C: pass
+ class C:
+ _alloc_flavor_ = "raw"
def f(i):
a = A()
b = B()
@@ -137,17 +137,54 @@
assert s.knowntype == int
rtyper = RPythonTyper(a)
rtyper.specialize()
-## res = interpret(f, [0])
-## assert res == 0x0004
-## res = interpret(f, [1])
-## assert res == 0x0020
-## res = interpret(f, [2])
-## assert res == 0x0100
-## res = interpret(f, [3])
-## assert res == 0x0200
+ res = interpret(f, [0])
+ assert res == 0x0004
+ res = interpret(f, [1])
+ assert res == 0x0020
+ res = interpret(f, [2])
+ assert res == 0x0100
+ res = interpret(f, [3])
+ assert res == 0x0200
+def test_is_mixing():
+ class A:
+ _alloc_flavor_ = "raw"
+ pass
+ class B(A): pass
+ class C:
+ pass
+ def f(i):
+ a = A()
+ b = B()
+ c = C()
+ d = None
+ e = None
+ if i == 0:
+ d = a
+ elif i == 1:
+ d = b
+ elif i == 2:
+ e = c
+ return (0x0001*(a is b) | 0x0002*(a is c) | 0x0004*(a is d) |
+ 0x0008*(a is e) | 0x0010*(b is c) | 0x0020*(b is d) |
+ 0x0040*(b is e) | 0x0080*(c is d) | 0x0100*(c is e) |
+ 0x0200*(d is e))
+ a = RPythonAnnotator()
+ #does not raise:
+ s = a.build_types(f, [int])
+ assert s.knowntype == int
+ rtyper = RPythonTyper(a)
+ rtyper.specialize()
+ res = interpret(f, [0])
+ assert res == 0x0004
+ res = interpret(f, [1])
+ assert res == 0x0020
+ res = interpret(f, [2])
+ assert res == 0x0100
+ res = interpret(f, [3])
+ assert res == 0x0200
-def test_rtype__nongc_object():
+def test_rtype_nongc_object():
from pypy.rpython.memory.lladdress import address
class TestClass(object):
_alloc_flavor_ = "raw"
More information about the Pypy-commit
mailing list