Author: Carl Friedrich Bolz <[email protected]>
Branch: reflex-support
Changeset: r45581:948ee9c5e9ab
Date: 2011-07-13 17:58 +0200
http://bitbucket.org/pypy/pypy/changeset/948ee9c5e9ab/
Log: (cfbolz, arigo): write a test that runs the jit on cppyy directly
without translating the full interpreter
diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py
--- a/pypy/jit/codewriter/support.py
+++ b/pypy/jit/codewriter/support.py
@@ -37,9 +37,9 @@
return a.typeannotation(t)
def annotate(func, values, inline=None, backendoptimize=True,
- type_system="lltype"):
+ type_system="lltype", listcomp=False):
# build the normal ll graphs for ll_function
- t = TranslationContext()
+ t = TranslationContext(list_comprehension_operations=listcomp)
annpolicy = AnnotatorPolicy()
annpolicy.allow_someobjects = False
a = t.buildannotator(policy=annpolicy)
diff --git a/pypy/jit/metainterp/test/support.py
b/pypy/jit/metainterp/test/support.py
--- a/pypy/jit/metainterp/test/support.py
+++ b/pypy/jit/metainterp/test/support.py
@@ -42,7 +42,7 @@
enable_opts = ALL_OPTS_DICT
func._jit_unroll_safe_ = True
- rtyper = support.annotate(func, values, type_system=type_system)
+ rtyper = support.annotate(func, values, type_system=type_system,
listcomp=kwds.get("listcomp", False))
graphs = rtyper.annotator.translator.graphs
testself.all_graphs = graphs
result_kind = history.getkind(graphs[0].getreturnvar().concretetype)[0]
diff --git a/pypy/module/_rawffi/interp_rawffi.py
b/pypy/module/_rawffi/interp_rawffi.py
--- a/pypy/module/_rawffi/interp_rawffi.py
+++ b/pypy/module/_rawffi/interp_rawffi.py
@@ -92,7 +92,7 @@
def unpack_simple_shape(space, w_shape):
# 'w_shape' must be either a letter or a tuple (struct, 1).
- if space.is_true(space.isinstance(w_shape, space.w_str)):
+ if space.isinstance_w(w_shape, space.w_str):
letter = space.str_w(w_shape)
return letter2tp(space, letter)
else:
diff --git a/pypy/module/cppyy/converter.py b/pypy/module/cppyy/converter.py
--- a/pypy/module/cppyy/converter.py
+++ b/pypy/module/cppyy/converter.py
@@ -87,6 +87,8 @@
self.size = array_size
def from_memory(self, space, w_obj, offset):
+ if hasattr(space, "fake"):
+ raise NotImplementedError
# read access, so no copy needed
address_value = self._get_raw_address(space, w_obj, offset)
address = rffi.cast(rffi.ULONG, address_value)
diff --git a/pypy/module/cppyy/executor.py b/pypy/module/cppyy/executor.py
--- a/pypy/module/cppyy/executor.py
+++ b/pypy/module/cppyy/executor.py
@@ -32,6 +32,8 @@
typecode = 'P'
def execute(self, space, func, cppthis, num_args, args):
+ if hasattr(space, "fake"):
+ raise NotImplementedError
lresult = capi.c_call_l(func.cpptype.handle, func.method_index,
cppthis, num_args, args)
address = rffi.cast(rffi.ULONG, lresult)
arr = space.interp_w(W_Array, unpack_simple_shape(space,
space.wrap(self.typecode)))
@@ -246,6 +248,7 @@
return interp_cppyy.W_CPPInstance(space, self.cpptype, ptr_result,
False)
def execute_libffi(self, space, libffifunc, argchain):
+ from pypy.module.cppyy import interp_cppyy
result = libffifunc.call(argchain, rffi.VOIDP)
return interp_cppyy.W_CPPInstance(space, self.cpptype, result, False)
diff --git a/pypy/module/cppyy/test/test_cppyy.py
b/pypy/module/cppyy/test/test_cppyy.py
--- a/pypy/module/cppyy/test/test_cppyy.py
+++ b/pypy/module/cppyy/test/test_cppyy.py
@@ -51,7 +51,7 @@
assert res == 4
res = t.invoke(t.get_overload("staticAddOneToInt"), -1)
assert res == 0
- maxint32 = int(math.pow(2,31)-1)
+ maxint32 = int(2 ** 31 - 1)
res = t.invoke(t.get_overload("staticAddOneToInt"), maxint32-1)
assert res == maxint32
res = t.invoke(t.get_overload("staticAddOneToInt"), maxint32)
diff --git a/pypy/module/cppyy/test/test_pythonify.py
b/pypy/module/cppyy/test/test_pythonify.py
--- a/pypy/module/cppyy/test/test_pythonify.py
+++ b/pypy/module/cppyy/test/test_pythonify.py
@@ -52,7 +52,7 @@
assert res == 4
res = example01_class.staticAddOneToInt(-1)
assert res == 0
- maxint32 = int(math.pow(2,31)-1)
+ maxint32 = int(2 ** 31 - 1)
res = example01_class.staticAddOneToInt(maxint32-1)
assert res == maxint32
res = example01_class.staticAddOneToInt(maxint32)
diff --git a/pypy/module/cppyy/test/test_zjit.py
b/pypy/module/cppyy/test/test_zjit.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/cppyy/test/test_zjit.py
@@ -0,0 +1,122 @@
+from pypy.jit.metainterp.test.support import LLJitMixin
+from pypy.rlib.objectmodel import specialize
+from pypy.rlib import rarithmetic
+from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root
+
+from pypy.module.cppyy import interp_cppyy
+
+class FakeBase(W_Root):
+ typename = None
+
+class FakeInt(FakeBase):
+ typename = "int"
+ def __init__(self, val):
+ self.val = val
+class FakeFloat(FakeBase):
+ typename = "float"
+ def __init__(self, val):
+ self.val = val
+class FakeString(FakeBase):
+ typename = "str"
+ def __init__(self, val):
+ self.val = val
+class FakeType(FakeBase):
+ typename = "type"
+ def __init__(self, name):
+ self.name = name
+ def getname(self, space, name):
+ return self.name
+
+
+
+
+class FakeSpace(object):
+ fake = True
+
+ w_ValueError = FakeType("ValueError")
+ w_TypeError = FakeType("TypeError")
+ w_AttributeError = FakeType("AttributeError")
+ w_ReferenceError = FakeType("ReferenceError")
+
+ w_None = None
+ w_str = FakeType("str")
+ w_int = FakeType("int")
+ w_float = FakeType("float")
+
+ def __init__(self):
+ self.fromcache = InternalSpaceCache(self).getorbuild
+
+ def issequence_w(self, w_obj):
+ return True
+
+ @specialize.argtype(1)
+ def wrap(self, obj):
+ if isinstance(obj, int):
+ return FakeInt(obj)
+ if isinstance(obj, float):
+ return FakeFloat(obj)
+ if isinstance(obj, str):
+ return FakeString(obj)
+ assert 0
+
+ def float_w(self, w_obj):
+ assert isinstance(w_obj, FakeFloat)
+ return w_obj.val
+
+ def interp_w(self, RequiredClass, w_obj, can_be_None=False):
+ if can_be_None and w_obj is None:
+ return None
+ if not isinstance(w_obj, RequiredClass):
+ raise TypeError
+ return w_obj
+ interp_w._annspecialcase_ = 'specialize:arg(1)'
+
+ def interpclass_w(self, w_obj):
+ return w_obj
+
+ def exception_match(self, typ, sub):
+ return typ is sub
+
+ def int_w(self, w_obj):
+ assert isinstance(w_obj, FakeInt)
+ return w_obj.val
+
+ def uint_w(self, w_obj):
+ assert isinstance(w_obj, FakeInt)
+ return rarithmetic.r_uint(w_obj.val)
+
+
+ def str_w(self, w_obj):
+ assert isinstance(w_obj, FakeString)
+ return w_obj.val
+
+ c_int_w = int_w
+
+ def isinstance_w(self, w_obj, w_type):
+ assert isinstance(w_obj, FakeBase)
+ return w_obj.typename == w_type.name
+
+ def type(self, w_obj):
+ return FakeType("fake")
+
+ def findattr(self, w_obj, w_name):
+ return None
+
+ def _freeze_(self):
+ return True
+
+class TestFastPathJIT(LLJitMixin):
+ def test_simple(self):
+ space = FakeSpace()
+ def f():
+ lib = interp_cppyy.load_lib(space, "./example01Dict.so")
+ cls = interp_cppyy.type_byname(space, "example01")
+ inst = cls.construct([FakeInt(0)])
+ addDataToInt = cls.get_overload("addDataToInt")
+ assert isinstance(inst, interp_cppyy.W_CPPInstance)
+ inst.invoke(addDataToInt, [FakeInt(41)])
+ return 7
+ f()
+ space = FakeSpace()
+ result = self.interp_operations(f, [], listops=True, backendopt=True,
listcomp=True)
+
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit