[pypy-svn] r63694 - in pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp: . test
fijal at codespeak.net
fijal at codespeak.net
Mon Apr 6 00:25:01 CEST 2009
Author: fijal
Date: Mon Apr 6 00:24:59 2009
New Revision: 63694
Modified:
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/history.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py
Log:
rename Box/Const.type into numbers. Now we can just check this instead of
dump isinstance. Implement oois, ooisnot, oononnull and ooisnull on non-gc
managed pointers (which sit in ints effectively)
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/executor.py Mon Apr 6 00:24:59 2009
@@ -3,7 +3,7 @@
import py
from pypy.rlib.rarithmetic import ovfcheck, r_uint, intmask
-from pypy.jit.metainterp.history import BoxInt, ConstInt, check_descr
+from pypy.jit.metainterp.history import BoxInt, ConstInt, check_descr, INT, PTR
from pypy.jit.metainterp.resoperation import rop
@@ -106,15 +106,25 @@
return ConstInt(not args[0].getint())
def do_oononnull(cpu, args, descr=None):
+ if args[0].type == INT:
+ return ConstInt(bool(args[0].getint()))
return ConstInt(bool(args[0].getptr_base()))
def do_ooisnull(cpu, args, descr=None):
+ if args[0].type == INT:
+ return ConstInt(not args[0].getint())
return ConstInt(not args[0].getptr_base())
def do_oois(cpu, args, descr=None):
+ if args[0].type == INT:
+ assert args[1].type == INT
+ return ConstInt(args[0].getint() == args[1].getint())
return ConstInt(args[0].getptr_base() == args[1].getptr_base())
def do_ooisnot(cpu, args, descr=None):
+ if args[0].type == INT:
+ assert args[1].type == INT
+ return ConstInt(args[0].getint() != args[1].getint())
return ConstInt(args[0].getptr_base() != args[1].getptr_base())
# ----------
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/history.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/history.py Mon Apr 6 00:24:59 2009
@@ -15,6 +15,9 @@
# ____________________________________________________________
+INT = 0
+PTR = 1
+
def getkind(TYPE):
if TYPE is lltype.Void:
return "void"
@@ -140,7 +143,7 @@
class ConstInt(Const):
- type = 'int'
+ type = INT
def __init__(self, value):
if not we_are_translated():
@@ -176,7 +179,7 @@
CONST_TRUE = ConstInt(1)
class ConstAddr(Const): # only for constants built before translation
- type = 'int'
+ type = INT
def __init__(self, adrvalue, cpu):
"NOT_RPYTHON"
@@ -209,7 +212,7 @@
return self.value
class ConstPtr(Const):
- type = 'ptr'
+ type = PTR
value = lltype.nullptr(llmemory.GCREF.TO)
def __init__(self, value):
@@ -267,12 +270,16 @@
def __str__(self):
if not hasattr(self, '_str'):
- self._str = '%s%d' % (self.type[0], Box._counter)
+ if self.type == INT:
+ t = 'i'
+ else:
+ t = 'p'
+ self._str = '%s%d' % (t, Box._counter)
Box._counter += 1
return self._str
class BoxInt(Box):
- type = 'int'
+ type = INT
def __init__(self, value=0):
if not we_are_translated():
@@ -300,7 +307,7 @@
changevalue_int = __init__
class BoxPtr(Box):
- type = 'ptr'
+ type = PTR
def __init__(self, value=lltype.nullptr(llmemory.GCREF.TO)):
assert lltype.typeOf(value) == llmemory.GCREF
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py Mon Apr 6 00:24:59 2009
@@ -993,11 +993,19 @@
if args:
value = args[0]
if isinstance(lltype.typeOf(value), lltype.Ptr):
- value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
- if num_green_args > 0:
- cls = ConstPtr
+ if lltype.typeOf(value).TO._gckind == 'gc':
+ value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
+ if num_green_args > 0:
+ cls = ConstPtr
+ else:
+ cls = BoxPtr
else:
- cls = BoxPtr
+ adr = llmemory.cast_ptr_to_adr(value)
+ value = self.cpu.cast_adr_to_int(adr)
+ if num_green_args > 0:
+ cls = ConstInt
+ else:
+ cls = BoxInt
else:
if num_green_args > 0:
cls = ConstInt
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py Mon Apr 6 00:24:59 2009
@@ -381,6 +381,20 @@
expected = lltype.cast_opaque_ptr(llmemory.GCREF, x)
assert self.interp_operations(f, [x]) == expected
+ def test_oops_on_nongc(self):
+ from pypy.rpython.lltypesystem import lltype
+
+ TP = lltype.Struct('x')
+ def f(p1, p2):
+ a = p1 is p2
+ b = p1 is not p2
+ c = bool(p1)
+ d = not bool(p2)
+ return a + b + c + d
+ x = lltype.malloc(TP, flavor='raw')
+ expected = f(x, x)
+ assert self.interp_operations(f, [x, x]) == expected
+
class TestOOtype(BasicTests, OOJitMixin):
pass
More information about the Pypy-commit
mailing list