[pypy-svn] r55923 - in pypy/branch/oo-jit/pypy: jit/rainbow/test jit/timeshifter rpython/ootypesystem
antocuni at codespeak.net
antocuni at codespeak.net
Tue Jun 17 15:17:24 CEST 2008
Author: antocuni
Date: Tue Jun 17 15:17:22 2008
New Revision: 55923
Modified:
pypy/branch/oo-jit/pypy/jit/rainbow/test/test_interpreter.py
pypy/branch/oo-jit/pypy/jit/timeshifter/oop.py
pypy/branch/oo-jit/pypy/jit/timeshifter/vlist.py
pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py
Log:
port some array tests to ootype
Modified: pypy/branch/oo-jit/pypy/jit/rainbow/test/test_interpreter.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/rainbow/test/test_interpreter.py (original)
+++ pypy/branch/oo-jit/pypy/jit/rainbow/test/test_interpreter.py Tue Jun 17 15:17:22 2008
@@ -733,50 +733,6 @@
assert res == 42
self.check_insns({'int_add': 1})
- def test_simple_array(self):
- A = lltype.GcArray(lltype.Signed,
- hints={'immutable': True})
- def ll_function(a):
- return a[0] * a[1]
-
- def int_array(string):
- items = [int(x) for x in string.split(',')]
- n = len(items)
- a1 = lltype.malloc(A, n)
- for i in range(n):
- a1[i] = items[i]
- return a1
- ll_function.convert_arguments = [int_array]
-
- res = self.interpret(ll_function, ["6,7"], [])
- assert res == 42
- self.check_insns({'getarrayitem': 2, 'int_mul': 1})
- res = self.interpret(ll_function, ["8,3"], [0])
- assert res == 24
- self.check_insns({})
-
- def test_arraysize(self):
- A = lltype.GcArray(lltype.Signed)
- def ll_function(a):
- return len(a)
-
- def int_array(string):
- items = [int(x) for x in string.split(',')]
- n = len(items)
- a1 = lltype.malloc(A, n)
- for i in range(n):
- a1[i] = items[i]
- return a1
- ll_function.convert_arguments = [int_array]
-
- res = self.interpret(ll_function, ["6,7"], [])
- assert res == 2
- self.check_insns({'getarraysize': 1})
- res = self.interpret(ll_function, ["8,3,3,4,5"], [0])
- assert res == 5
- self.check_insns({})
-
-
def test_simple_struct_malloc(self):
py.test.skip("blue containers: to be reimplemented")
S = lltype.GcStruct('helloworld', ('hello', lltype.Signed),
@@ -2043,7 +1999,6 @@
return isinstance(obj, B)
res = self.interpret(fn, [True], [], policy=StopAtXPolicy(g))
assert res
- #self.check_insns({})
def test_manymanyvars(self):
@@ -2139,6 +2094,49 @@
class TestLLType(SimpleTests):
type_system = "lltype"
+ def test_simple_array(self):
+ A = lltype.GcArray(lltype.Signed,
+ hints={'immutable': True})
+ def ll_function(a):
+ return a[0] * a[1]
+
+ def int_array(string):
+ items = [int(x) for x in string.split(',')]
+ n = len(items)
+ a1 = lltype.malloc(A, n)
+ for i in range(n):
+ a1[i] = items[i]
+ return a1
+ ll_function.convert_arguments = [int_array]
+
+ res = self.interpret(ll_function, ["6,7"], [])
+ assert res == 42
+ self.check_insns({'getarrayitem': 2, 'int_mul': 1})
+ res = self.interpret(ll_function, ["8,3"], [0])
+ assert res == 24
+ self.check_insns({})
+
+ def test_arraysize(self):
+ A = lltype.GcArray(lltype.Signed)
+ def ll_function(a):
+ return len(a)
+
+ def int_array(string):
+ items = [int(x) for x in string.split(',')]
+ n = len(items)
+ a1 = lltype.malloc(A, n)
+ for i in range(n):
+ a1[i] = items[i]
+ return a1
+ ll_function.convert_arguments = [int_array]
+
+ res = self.interpret(ll_function, ["6,7"], [])
+ assert res == 2
+ self.check_insns({'getarraysize': 1})
+ res = self.interpret(ll_function, ["8,3,3,4,5"], [0])
+ assert res == 5
+ self.check_insns({})
+
def test_degenerated_before_return(self):
S = lltype.GcStruct('S', ('n', lltype.Signed))
T = lltype.GcStruct('T', ('s', S), ('n', lltype.Float))
@@ -2311,6 +2309,49 @@
class TestOOType(OOTypeMixin, SimpleTests):
+ def test_simple_array(self):
+ A = ootype.Array(lltype.Signed,
+ _hints={'immutable': True})
+ def ll_function(a):
+ return a.ll_getitem_fast(0) * a.ll_getitem_fast(1)
+
+ def int_array(string):
+ items = [int(x) for x in string.split(',')]
+ n = len(items)
+ a1 = ootype.oonewarray(A, n)
+ for i in range(n):
+ a1.ll_setitem_fast(i, items[i])
+ return a1
+ ll_function.convert_arguments = [int_array]
+
+ res = self.interpret(ll_function, ["6,7"], [])
+ assert res == 42
+ self.check_insns({'oosend': 2, 'int_mul': 1})
+ res = self.interpret(ll_function, ["8,3"], [0])
+ assert res == 24
+ self.check_insns({})
+
+ def test_arraysize(self):
+ A = ootype.Array(lltype.Signed)
+ def ll_function(a):
+ return a.ll_length()
+
+ def int_array(string):
+ items = [int(x) for x in string.split(',')]
+ n = len(items)
+ a1 = ootype.oonewarray(A, n)
+ for i in range(n):
+ a1.ll_setitem_fast(i, items[i])
+ return a1
+ ll_function.convert_arguments = [int_array]
+
+ res = self.interpret(ll_function, ["6,7"], [])
+ assert res == 2
+ self.check_insns({'oosend': 1})
+ res = self.interpret(ll_function, ["8,3,3,4,5"], [0])
+ assert res == 5
+ self.check_insns({})
+
def test_degenerated_before_return(self):
S = ootype.Instance('S', ootype.ROOT, {'x': ootype.Signed})
T = ootype.Instance('T', S, {'y': ootype.Float})
Modified: pypy/branch/oo-jit/pypy/jit/timeshifter/oop.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/timeshifter/oop.py (original)
+++ pypy/branch/oo-jit/pypy/jit/timeshifter/oop.py Tue Jun 17 15:17:22 2008
@@ -130,10 +130,13 @@
self.do_call = do_call
+ def isfoldable(self, deepfrozen):
+ return deepfrozen
+
def residual_call(self, jitstate, argboxes, deepfrozen=False):
builder = jitstate.curbuilder
args_gv = []
- fold = deepfrozen
+ fold = self.isfoldable(deepfrozen)
for argsrc in self.residualargsources:
gv_arg = argboxes[argsrc].getgenvar(jitstate)
args_gv.append(gv_arg)
@@ -292,10 +295,26 @@
self.residualargsources = range(len(self.OOPARGTYPES))
self.typename = self.SELFTYPE.oopspec_name
methname = meth._name.lstrip('_')
- methname = methname.lstrip('ll_')
+ assert methname.startswith('ll_')
+ methname = methname[3:]
self.method = 'oop_%s_method_%s' % (self.typename, methname)
self.is_method = True
+ self.methtoken = RGenOp.methToken(self.SELFTYPE, meth._name)
+
+ self.foldable = False
+ if isinstance(self.SELFTYPE, ootype.Array):
+ if self.SELFTYPE._hints.get('immutable', False):
+ self.foldable = True
+ if getattr(meth, '_callable', None) and \
+ getattr(meth._callable, 'foldable', False):
+ self.foldable = True
+
+ def generate_call(self, builder, args_gv):
+ gv_self, args_gv = args_gv[0], args_gv[1:]
+ return builder.genop_oosend(self.methtoken, gv_self, args_gv)
+ def isfoldable(self, deepfrozen):
+ return deepfrozen or self.foldable
class SendOopSpecDesc_list(SendOopSpecDesc):
pass
Modified: pypy/branch/oo-jit/pypy/jit/timeshifter/vlist.py
==============================================================================
--- pypy/branch/oo-jit/pypy/jit/timeshifter/vlist.py (original)
+++ pypy/branch/oo-jit/pypy/jit/timeshifter/vlist.py Tue Jun 17 15:17:22 2008
@@ -518,8 +518,6 @@
else:
oopspecdesc.residual_call(jitstate, [selfbox, indexbox, itembox])
-oop_list_method_setitem_fast = oop_list_setitem
-
def oop_list_delitem(jitstate, oopspecdesc, deepfrozen, selfbox, indexbox):
content = selfbox.content
if isinstance(content, VirtualList) and indexbox.is_constant():
@@ -530,3 +528,8 @@
oopspecdesc.residual_exception(jitstate, IndexError)
else:
oopspecdesc.residual_call(jitstate, [selfbox, indexbox])
+
+
+oop_list_method_getitem_fast = oop_list_getitem
+oop_list_method_setitem_fast = oop_list_setitem
+oop_list_method_length = oop_list_len
Modified: pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/branch/oo-jit/pypy/rpython/ootypesystem/ootype.py Tue Jun 17 15:17:22 2008
@@ -587,8 +587,9 @@
oopspec_new = 'new(length)'
oopspec_new_argnames = ('length',)
- def __init__(self, ITEMTYPE=None):
+ def __init__(self, ITEMTYPE=None, _hints = {}):
self.ITEM = ITEMTYPE
+ self._hints = frozendict(_hints)
self._null = _null_array(self)
if ITEMTYPE is not None:
self._init_methods()
@@ -1540,12 +1541,15 @@
def ll_length(self):
# NOT_RPYTHON
return len(self._array)
+ ll_length.oopargcheck = lambda a: bool(a)
+ ll_length.foldable = True
def ll_getitem_fast(self, index):
# NOT_RPYTHON
assert typeOf(index) == Signed
assert index >= 0
return self._array[index]
+ ll_getitem_fast.oopargcheck = lambda a, index: bool(a)
def ll_setitem_fast(self, index, item):
# NOT_RPYTHON
@@ -1553,6 +1557,7 @@
assert typeOf(index) == Signed
assert index >= 0
self._array[index] = item
+ ll_setitem_fast.oopargcheck = lambda a, index, item: bool(a)
class _null_array(_null_mixin(_array), _array):
More information about the Pypy-commit
mailing list