[pypy-svn] r65275 - in pypy/branch/pyjitpl5/pypy/rpython/ootypesystem: . test
antocuni at codespeak.net
antocuni at codespeak.net
Sat May 16 10:29:40 CEST 2009
Author: antocuni
Date: Sat May 16 10:29:38 2009
New Revision: 65275
Modified:
pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rbuiltin.py
pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py
Log:
teach the rtyper how to handle ootype.instanceof
Modified: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rbuiltin.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rbuiltin.py (original)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/rbuiltin.py Sat May 16 10:29:38 2009
@@ -36,6 +36,13 @@
return hop.genop('subclassof', vlist,
resulttype = ootype.Bool)
+def rtype_instanceof(hop):
+ INSTANCE = hop.args_v[1].value
+ v_inst = hop.inputarg(hop.args_r[0], arg=0)
+ c_cls = hop.inputconst(ootype.Void, INSTANCE)
+ return hop.genop('instanceof', [v_inst, c_cls],
+ resulttype=ootype.Bool)
+
def rtype_runtimenew(hop):
vlist = hop.inputargs(rootype.ooclass_repr)
return hop.genop('runtimenew', vlist,
@@ -123,6 +130,7 @@
BUILTIN_TYPER[ootype.null] = rtype_null
BUILTIN_TYPER[ootype.classof] = rtype_classof
BUILTIN_TYPER[ootype.subclassof] = rtype_subclassof
+BUILTIN_TYPER[ootype.instanceof] = rtype_instanceof
BUILTIN_TYPER[ootype.runtimenew] = rtype_runtimenew
BUILTIN_TYPER[ootype.ooidentityhash] = rtype_ooidentityhash
BUILTIN_TYPER[ootype.ooupcast] = rtype_ooupcast
Modified: pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py (original)
+++ pypy/branch/pyjitpl5/pypy/rpython/ootypesystem/test/test_oortype.py Sat May 16 10:29:38 2009
@@ -489,3 +489,19 @@
res = interpret(fn, [1], type_system='ootype')
assert res == 2
+
+def test_instanceof():
+ A = Instance('A', ootype.ROOT, {})
+ B = Instance('B', A, {})
+
+ def fn(x):
+ if x:
+ obj = ooupcast(A, new(B))
+ else:
+ obj = new(A)
+ return instanceof(obj, B)
+
+ res = interpret(fn, [0], type_system='ootype')
+ assert not res
+ res = interpret(fn, [1], type_system='ootype')
+ assert res
More information about the Pypy-commit
mailing list