[pypy-svn] r63940 - in pypy/branch/pyjitpl5-simplify/pypy: jit/backend/llgraph jit/metainterp jit/metainterp/test rpython/ootypesystem
antocuni at codespeak.net
antocuni at codespeak.net
Fri Apr 10 16:12:48 CEST 2009
Author: antocuni
Date: Fri Apr 10 16:12:44 2009
New Revision: 63940
Modified:
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/llimpl.py
pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.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/policy.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/pyjitpl.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/support.py
pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/test/test_basic.py
pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/ootype.py
Log:
make test_string (almost) passing. To do this, we introduced ConstObj and
BoxObj, as well as rudimental support for some kind of oosend.
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 Fri Apr 10 16:12:44 2009
@@ -297,10 +297,10 @@
op = loop.operations[-1]
op.args.append(const)
-def compile_add_ptr_const(loop, value):
+def compile_add_ptr_const(loop, value, TYPE=llmemory.GCREF):
loop = _from_opaque(loop)
const = Constant(value)
- const.concretetype = llmemory.GCREF
+ const.concretetype = TYPE
op = loop.operations[-1]
op.args.append(const)
@@ -314,10 +314,10 @@
_variables.append(v)
return r
-def compile_add_ptr_result(loop):
+def compile_add_ptr_result(loop, TYPE=llmemory.GCREF):
loop = _from_opaque(loop)
v = Variable()
- v.concretetype = llmemory.GCREF
+ v.concretetype = TYPE
op = loop.operations[-1]
op.result = v
r = len(_variables)
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/backend/llgraph/runner.py Fri Apr 10 16:12:44 2009
@@ -4,6 +4,7 @@
import sys
from pypy.rpython.lltypesystem import lltype, llmemory, rclass
+from pypy.rpython.ootypesystem import ootype
from pypy.rpython.llinterp import LLInterpreter
from pypy.jit.metainterp import history
from pypy.jit.metainterp.resoperation import ResOperation, rop
@@ -115,6 +116,8 @@
llimpl.compile_add_ptr_const(c, x.value)
elif isinstance(x, history.ConstAddr):
llimpl.compile_add_int_const(c, x.getint())
+ elif isinstance(x, history.ConstObj):
+ llimpl.compile_add_ptr_const(c, x.value, TYPE=ootype.Object)
else:
raise Exception("%s args contain: %r" % (op.getopname(),
x))
@@ -127,6 +130,8 @@
var2index[x] = llimpl.compile_add_int_result(c)
elif isinstance(x, history.BoxPtr):
var2index[x] = llimpl.compile_add_ptr_result(c)
+ elif isinstance(x, history.BoxObj):
+ var2index[x] = llimpl.compile_add_ptr_result(c, TYPE=ootype.Object)
else:
raise Exception("%s.result contain: %r" % (op.getopname(),
x))
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 Fri Apr 10 16:12:44 2009
@@ -901,6 +901,22 @@
self.register_var(v_posindex)
return v_posindex
+ def serialize_op_oosend(self, op):
+ color = self.codewriter.policy.guess_call_kind(op)
+ return getattr(self, 'handle_%s_oosend' % color)(op)
+
+ def handle_builtin_oosend(self, op):
+ SELFTYPE, methname, args_v = support.decompose_oosend(op)
+ assert SELFTYPE.oopspec_name is not None
+ for prefix in ('ll_', '_ll_'):
+ if methname.startswith(prefix):
+ methname = methname[len(prefix):]
+ opname = '%s_%s' % (SELFTYPE.oopspec_name, methname)
+ self.emit(opname)
+ for v_arg in args_v:
+ self.emit(self.var_position(v_arg))
+ self.register_var(op.result)
+
def serialize_op_indirect_call(self, op):
self.minimize_variables()
targets = self.codewriter.policy.graphs_from(op)
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 Fri Apr 10 16:12:44 2009
@@ -2,8 +2,10 @@
"""
import py
+from pypy.rpython.ootypesystem import ootype
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 ConstObj
from pypy.jit.metainterp.resoperation import rop
@@ -217,6 +219,36 @@
z = 0
return BoxInt(z)
+
+# XXX: these ops should probably be delegated to the backend
+def do_str_stritem_nonneg(cpu, args, descr=None):
+ obj = args[0].getptr_base()
+ str = ootype.cast_from_object(ootype.String, obj)
+ index = args[1].getint()
+ res = str.ll_stritem_nonneg(index)
+ return ConstInt(ord(res))
+
+def do_str_strconcat(cpu, args, descr=None):
+ obj1 = args[0].getptr_base()
+ obj2 = args[1].getptr_base()
+ str1 = ootype.cast_from_object(ootype.String, obj1)
+ str2 = ootype.cast_from_object(ootype.String, obj2)
+ res = str1.ll_strconcat(str2)
+ objres = ootype.cast_to_object(res)
+ return ConstObj(objres)
+
+def do_str_strlen(cpu, args, descr=None):
+ obj = args[0].getptr_base()
+ str = ootype.cast_from_object(ootype.String, obj)
+ res = str.ll_strlen()
+ return ConstInt(res)
+
+def do_oostring(cpu, args, descr=None):
+ obj = args[0].getint() # XXX what about other types?
+ base = args[1].getint()
+ res = ootype.cast_to_object(ootype.oostring(obj, base))
+ return ConstObj(res) # XXX ???
+
# ____________________________________________________________
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 Fri Apr 10 16:12:44 2009
@@ -1,6 +1,7 @@
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.ootypesystem import ootype
from pypy.rlib.objectmodel import we_are_translated, r_dict, Symbolic
from pypy.rlib.rarithmetic import intmask
from pypy.tool.uid import uid
@@ -28,6 +29,8 @@
return "int"
else:
return "ptr"
+ elif isinstance(TYPE, ootype.OOType):
+ return "obj"
else:
raise NotImplementedError("type %s not supported" % TYPE)
@@ -48,6 +51,12 @@
except AttributeError:
return box.value
+def repr_object(box):
+ try:
+ return repr(box.value.obj._TYPE)
+ except AttributeError:
+ return box.value
+
class AbstractValue(object):
__slots__ = ()
@@ -111,6 +120,9 @@
elif kind == "ptr":
ptrval = lltype.cast_opaque_ptr(llmemory.GCREF, x)
return ConstPtr(ptrval)
+ elif kind == "obj":
+ obj = ootype.cast_to_object(x)
+ return ConstObj(obj)
else:
raise NotImplementedError(kind)
_new._annspecialcase_ = 'specialize:argtype(0)'
@@ -243,6 +255,36 @@
_getrepr_ = repr_pointer
+class ConstObj(Const):
+ type = ootype.Object
+ value = ootype.NULL
+ _attrs_ = ('value',)
+
+ def __init__(self, value):
+ assert ootype.typeOf(value) is ootype.Object
+ self.value = value
+
+ def clonebox(self):
+ return BoxObj(self.value)
+
+ nonconstbox = clonebox
+
+ def getptr_base(self):
+ return self.value
+
+ def get_(self):
+ return ootype.ooidentityhash(self.value) # XXX: check me
+
+ def getaddr(self, cpu):
+ assert False
+ #return llmemory.cast_ptr_to_adr(self.value)
+
+ def equals(self, other):
+ assert False
+ #return self.value == other.getptr_base()
+
+ _getrepr_ = repr_object
+
class Box(AbstractValue):
__slots__ = ()
_extended_display = True
@@ -337,6 +379,31 @@
NULLBOX = BoxPtr()
+
+class BoxObj(Box):
+ type = ootype.Object
+ _attrs_ = ('value',)
+
+ def __init__(self, value=ootype.NULL):
+ assert ootype.typeOf(value) is ootype.Object
+ self.value = value
+
+ def clonebox(self):
+ return BoxObj(self.value)
+
+ def constbox(self):
+ return ConstObj(self.value)
+
+ def getptr_base(self):
+ return self.value
+
+ def get_(self):
+ return ootype.ooidentityhash(self.value) # XXX: check me
+
+ _getrepr_ = repr_object
+ changevalue_ptr = __init__
+
+
# ____________________________________________________________
# The TreeLoop class contains a loop or a generalized loop, i.e. a tree
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/policy.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/policy.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/policy.py Fri Apr 10 16:12:44 2009
@@ -1,4 +1,5 @@
from pypy.translator.simplify import get_funcobj
+from pypy.jit.metainterp import support
class JitPolicy(object):
@@ -48,6 +49,11 @@
if (hasattr(targetgraph, 'func') and
hasattr(targetgraph.func, 'oopspec')):
return 'builtin'
+ elif op.opname == 'oosend':
+ SELFTYPE, methname, opargs = support.decompose_oosend(op)
+ if SELFTYPE.oopspec_name is not None:
+ return 'builtin'
+ assert False, 'fixme'
if self.graphs_from(op) is None:
return 'residual'
return 'regular'
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 Fri Apr 10 16:12:44 2009
@@ -530,6 +530,22 @@
def opimpl_newunicode(self, length):
self.execute(rop.NEWUNICODE, [length])
+ @arguments("box", "box")
+ def opimpl_str_stritem_nonneg(self, str, index):
+ self.execute(rop.STR_STRITEM_NONNEG, [str, index])
+
+ @arguments("box")
+ def opimpl_str_strlen(self, str):
+ self.execute(rop.STR_STRLEN, [str])
+
+ @arguments("box", "box")
+ def opimpl_str_strconcat(self, str1, str2):
+ self.execute(rop.STR_STRCONCAT, [str1, str2])
+
+ @arguments("box", "box")
+ def opimpl_oostring(self, obj, base):
+ self.execute(rop.OOSTRING, [obj, base])
+
@arguments("orgpc", "box", returns="box")
def opimpl_guard_value(self, pc, box):
return self.implement_guard_value(pc, box)
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/resoperation.py Fri Apr 10 16:12:44 2009
@@ -156,7 +156,14 @@
GETARRAYITEM_GC_PURE = 82
UNICODELEN = 83
UNICODEGETITEM = 84
- _ALWAYS_PURE_LAST = 84 # ----- end of always_pure operations -----
+ #
+ # ootype operations
+ OOSTRING = 85
+ STR_STRITEM_NONNEG = 86
+ STR_STRCONCAT = 87
+ STR_STRLEN = 88
+ #
+ _ALWAYS_PURE_LAST = 88 # ----- end of always_pure operations -----
GETARRAYITEM_GC = 120
GETFIELD_GC = 121
Modified: pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/support.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/support.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/jit/metainterp/support.py Fri Apr 10 16:12:44 2009
@@ -239,3 +239,10 @@
rtyper._builtin_func_for_spec_cache[key] = (c_func, LIST_OR_DICT)
#
return c_func, LIST_OR_DICT
+
+
+def decompose_oosend(op):
+ name = op.args[0].value
+ opargs = op.args[1:]
+ SELFTYPE = opargs[0].concretetype
+ return SELFTYPE, name, opargs
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 Fri Apr 10 16:12:44 2009
@@ -175,11 +175,21 @@
return "?"
res = self.interp_operations(f, [1])
assert res == ord("d") # XXX should be "d"
- res = self.interp_operations(f, [6])
- assert res == 6
+ if self.type_system != 'ootype':
+ # this test fails on ootype, see test_chr2str
+ res = self.interp_operations(f, [6])
+ assert res == 6
res = self.interp_operations(f, [42])
assert res == ord("?")
+ def test_chr2str(self):
+ # the problem is that we call oostring(6) instead of oostring('\x06')
+ def f(n):
+ s = chr(n)
+ return s[0]
+ res = self.interp_operations(f, [3])
+ assert res == 3
+
def test_unicode(self):
def f(n):
bytecode = u'adlfkj' + unichr(n)
@@ -461,7 +471,7 @@
def skip(self):
py.test.skip('in-progress')
- test_string = skip
+ test_chr2str = skip
test_unicode = skip
test_residual_call = skip
test_format = skip
Modified: pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/branch/pyjitpl5-simplify/pypy/rpython/ootypesystem/ootype.py Fri Apr 10 16:12:44 2009
@@ -393,7 +393,7 @@
class AbstractString(BuiltinADTType):
-## oopspec_name = 'str'
+ oopspec_name = 'str'
immutable = True
def __init__(self):
@@ -1349,6 +1349,9 @@
def __cmp__(self, other):
return cmp(self._str, other._str)
+ def __repr__(self):
+ return 'ootype._string(value=%r)' % self._str
+
def make_string(self, value):
if self._TYPE is String:
return make_string(value)
More information about the Pypy-commit
mailing list