[pypy-svn] r64539 - in pypy/branch/pyjitpl5-simplify/pypy/jit: backend/llgraph metainterp
arigo at codespeak.net
arigo at codespeak.net
Tue Apr 21 18:45:49 CEST 2009
Author: arigo
Date: Tue Apr 21 18:45:48 2009
New Revision: 64539
Modified:
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
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/typesystem.py
Log:
(antocuni, arigo)
Pass test_print, by implementing (and whacking at) classof and
goto_if_exception_mismatch.
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py Tue Apr 21 18:45:48 2009
@@ -109,6 +109,7 @@
'call' : (('ptr', 'varargs'), 'intorptr'),
'call_pure' : (('ptr', 'varargs'), 'intorptr'),
'oosend' : (('varargs',), 'intorptr'),
+ 'oosend_pure' : (('varargs',), 'intorptr'),
'guard_true' : (('bool',), None),
'guard_false' : (('bool',), None),
'guard_value' : (('int', 'int'), None),
@@ -666,13 +667,9 @@
op_call_pure = op_call
def op_oosend(self, descr, obj, *args):
- METH = descr.METH
- obj = ootype.cast_from_object(METH.SELFTYPE, obj)
- meth = getattr(obj, descr.methname)
- res = call_maybe_on_top_of_llinterp(meth, args)
- if isinstance(METH.RESULT, ootype.OOType):
- return ootype.cast_to_object(res)
- return res
+ raise NotImplementedError("oosend for lltype backend??")
+
+ op_oosend_pure = op_oosend
def op_new_array(self, arraydescr, count):
return do_new_array(arraydescr.ofs, count)
@@ -698,7 +695,7 @@
def op_getfield_gc(self, fielddescr, obj):
TYPE = fielddescr.TYPE
fieldname = fielddescr.fieldname
- T = TYPE._lookup_field(fieldname)
+ _, T = TYPE._lookup_field(fieldname)
obj = ootype.cast_from_object(TYPE, obj)
res = getattr(obj, fieldname)
if isinstance(T, ootype.OOType):
@@ -708,7 +705,7 @@
def op_setfield_gc(self, fielddescr, obj, newvalue):
TYPE = fielddescr.TYPE
fieldname = fielddescr.fieldname
- T = TYPE._lookup_field(fieldname)
+ _, T = TYPE._lookup_field(fieldname)
obj = ootype.cast_from_object(TYPE, obj)
if isinstance(ootype.typeOf(newvalue), ootype.OOType):
newvalue = ootype.cast_from_object(T, newvalue)
@@ -716,11 +713,26 @@
def op_call(self, calldescr, func, *args):
sm = ootype.cast_from_object(calldescr.FUNC, func)
- res = call_maybe_on_top_of_llinterp(sm, args)
+ newargs = cast_call_args(calldescr.FUNC.ARGS, args, self.memocast)
+ res = call_maybe_on_top_of_llinterp(sm, newargs)
if isinstance(calldescr.FUNC.RESULT, ootype.OOType):
return ootype.cast_to_object(res)
return res
+ op_call_pure = op_call
+
+ def op_oosend(self, descr, obj, *args):
+ METH = descr.METH
+ obj = ootype.cast_from_object(METH.SELFTYPE, obj)
+ meth = getattr(obj, descr.methname)
+ newargs = cast_call_args(METH.ARGS, args, self.memocast)
+ res = call_maybe_on_top_of_llinterp(meth, newargs)
+ if isinstance(METH.RESULT, ootype.OOType):
+ return ootype.cast_to_object(res)
+ return res
+
+ op_oosend_pure = op_oosend
+
def op_guard_class(self, _, value, expected_class):
value = ootype.cast_from_object(ootype.ROOT, value)
expected_class = ootype.cast_from_object(ootype.Class, expected_class)
@@ -1009,18 +1021,7 @@
ptr = cast_int_to_adr(memocast, f).ptr
FUNC = lltype.typeOf(ptr).TO
ARGS = FUNC.ARGS
- args = []
- nextitem = iter(_call_args).next
- for TYPE in ARGS:
- if TYPE is lltype.Void:
- x = None
- else:
- x = nextitem()
- if isinstance(TYPE, lltype.Ptr) and TYPE.TO._gckind == 'gc':
- x = cast_from_ptr(TYPE, x)
- else:
- x = cast_from_int(TYPE, x, memocast)
- args.append(x)
+ args = cast_call_args(ARGS, _call_args, memocast)
del _call_args[:]
assert len(ARGS) == len(args)
if hasattr(ptr._obj, 'graph'):
@@ -1045,6 +1046,24 @@
x = _do_call_common(f, memocast, lltype.nullptr(llmemory.GCREF.TO))
return cast_to_ptr(x)
+def cast_call_args(ARGS, args, memocast):
+ argsiter = iter(args)
+ args = []
+ for TYPE in ARGS:
+ if TYPE is lltype.Void:
+ x = None
+ else:
+ x = argsiter.next()
+ if isinstance(TYPE, ootype.OOType):
+ x = ootype.cast_from_object(TYPE, x)
+ elif isinstance(TYPE, lltype.Ptr) and TYPE.TO._gckind == 'gc':
+ x = cast_from_ptr(TYPE, x)
+ else:
+ x = cast_from_int(TYPE, x, memocast)
+ args.append(x)
+ assert list(argsiter) == []
+ return args
+
# for ootype meth and staticmeth
def call_maybe_on_top_of_llinterp(meth, args):
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/codewriter.py Tue Apr 21 18:45:48 2009
@@ -700,6 +700,9 @@
self.emit('guard_class', self.var_position(op.args[0]))
self.register_var(op.result)
+ def serialize_op_classof(self, op):
+ self.handle_getfield_typeptr(op)
+
def serialize_op_getarrayitem(self, op):
ARRAY = op.args[0].concretetype.TO
assert ARRAY._gckind == 'gc'
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 Tue Apr 21 18:45:48 2009
@@ -6,7 +6,8 @@
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rlib.rarithmetic import ovfcheck, r_uint, intmask
-from pypy.jit.metainterp.history import BoxInt, ConstInt, check_descr, INT, PTR
+from pypy.jit.metainterp.history import BoxInt, ConstInt, check_descr
+from pypy.jit.metainterp.history import INT, PTR, OBJ
from pypy.jit.metainterp.resoperation import rop
@@ -115,25 +116,47 @@
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()))
+ x = bool(args[0].getint())
+ elif args[0].type == PTR:
+ x = bool(args[0].getptr_base())
+ else:
+ assert args[0].type == OBJ
+ x = bool(args[0].getobj())
+ return ConstInt(x)
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())
+ x = bool(args[0].getint())
+ elif args[0].type == PTR:
+ x = bool(args[0].getptr_base())
+ else:
+ assert args[0].type == OBJ
+ x = bool(args[0].getobj())
+ return ConstInt(not x)
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())
+ tp = args[0].type
+ assert tp == args[1].type
+ if tp == INT:
+ x = args[0].getint() == args[1].getint()
+ elif tp == PTR:
+ x = args[0].getptr_base() == args[1].getptr_base()
+ else:
+ assert tp == OBJ
+ x = args[0].getobj() == args[1].getobj()
+ return ConstInt(x)
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())
+ tp = args[0].type
+ assert tp == args[1].type
+ if tp == INT:
+ x = args[0].getint() != args[1].getint()
+ elif tp == PTR:
+ x = args[0].getptr_base() != args[1].getptr_base()
+ else:
+ assert tp == OBJ
+ x = args[0].getobj() != args[1].getobj()
+ return ConstInt(x)
# ----------
# the following operations just delegate to the cpu:
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 Tue Apr 21 18:45:48 2009
@@ -16,8 +16,9 @@
# ____________________________________________________________
-INT = 0
-PTR = 1
+INT = 'i'
+PTR = 'p'
+OBJ = 'o'
def getkind(TYPE):
if TYPE is lltype.Void:
@@ -276,7 +277,7 @@
_getrepr_ = repr_pointer
class ConstObj(Const):
- type = ootype.Object
+ type = OBJ
value = ootype.NULL
_attrs_ = ('value',)
@@ -403,7 +404,7 @@
class BoxObj(Box):
- type = ootype.Object
+ type = OBJ
_attrs_ = ('value',)
def __init__(self, value=ootype.NULL):
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 Tue Apr 21 18:45:48 2009
@@ -659,11 +659,9 @@
@arguments("constbox", "jumptarget")
def opimpl_goto_if_exception_mismatch(self, vtableref, next_exc_target):
assert isinstance(self.exception_box, Const) # XXX
- adr = vtableref.getaddr(self.metainterp.cpu)
- bounding_class = llmemory.cast_adr_to_ptr(adr, rclass.CLASSTYPE)
- adr = self.exception_box.getaddr(self.metainterp.cpu)
- real_class = llmemory.cast_adr_to_ptr(adr, rclass.CLASSTYPE)
- if not rclass.ll_issubclass(real_class, bounding_class):
+ cpu = self.metainterp.cpu
+ ts = self.metainterp.staticdata.ts
+ if not ts.subclassOf(cpu, self.exception_box, vtableref):
self.pc = next_exc_target
@arguments("int")
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/typesystem.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/typesystem.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/typesystem.py Tue Apr 21 18:45:48 2009
@@ -53,6 +53,14 @@
cls = llmemory.cast_ptr_to_adr(obj.typeptr)
return history.ConstInt(cpu.cast_adr_to_int(cls))
+ def subclassOf(self, cpu, clsbox1, clsbox2):
+ adr = clsbox2.getaddr(cpu)
+ bounding_class = llmemory.cast_adr_to_ptr(adr, rclass.CLASSTYPE)
+ adr = clsbox1.getaddr(cpu)
+ real_class = llmemory.cast_adr_to_ptr(adr, rclass.CLASSTYPE)
+ return rclass.ll_issubclass(real_class, bounding_class)
+
+
class OOTypeHelper(TypeSystemHelper):
name = 'ootype'
@@ -77,5 +85,11 @@
oocls = ootype.classof(obj)
return history.ConstObj(ootype.cast_to_object(oocls))
+ def subclassOf(self, cpu, clsbox1, clsbox2):
+ cls1 = ootype.cast_from_object(ootype.Class, clsbox1.getobj())
+ cls2 = ootype.cast_from_object(ootype.Class, clsbox2.getobj())
+ return ootype.subclassof(cls1, cls2)
+
+
llhelper = LLTypeHelper()
oohelper = OOTypeHelper()
More information about the Pypy-commit
mailing list