Author: Maciej Fijalkowski <[email protected]>
Branch: optresult
Changeset: r74655:f82fe958c290
Date: 2014-11-24 10:53 +0200
http://bitbucket.org/pypy/pypy/changeset/f82fe958c290/
Log: fix test_executor
diff --git a/rpython/jit/backend/test/runner_test.py
b/rpython/jit/backend/test/runner_test.py
--- a/rpython/jit/backend/test/runner_test.py
+++ b/rpython/jit/backend/test/runner_test.py
@@ -5,9 +5,9 @@
BasicFinalDescr,
JitCellToken, TargetToken,
ConstInt, ConstPtr,
- ConstFloat)
+ ConstFloat, Const)
from rpython.jit.metainterp.resoperation import ResOperation, rop,
InputArgInt,\
- InputArgFloat
+ InputArgFloat, opname
from rpython.jit.metainterp.typesystem import deref
from rpython.jit.codewriter.effectinfo import EffectInfo
from rpython.jit.tool.oparser import parse
@@ -53,11 +53,11 @@
self.cpu.compile_loop(inputargs, operations, looptoken)
args = []
for box in inputargs:
- if isinstance(box, BoxInt):
+ if box.type == 'i':
args.append(box.getint())
- elif isinstance(box, BoxPtr):
+ elif box.type == 'r':
args.append(box.getref_base())
- elif isinstance(box, BoxFloat):
+ elif box.type == 'f':
args.append(box.getfloatstorage())
else:
raise NotImplementedError(box)
@@ -67,11 +67,11 @@
else:
self.guard_failed = True
if result_type == 'int':
- return BoxInt(self.cpu.get_int_value(deadframe, 0))
+ return self.cpu.get_int_value(deadframe, 0)
elif result_type == 'ref':
- return BoxPtr(self.cpu.get_ref_value(deadframe, 0))
+ return self.cpu.get_ref_value(deadframe, 0)
elif result_type == 'float':
- return BoxFloat(self.cpu.get_float_value(deadframe, 0))
+ return self.cpu.get_float_value(deadframe, 0)
elif result_type == 'void':
return None
else:
@@ -79,23 +79,12 @@
def _get_single_operation_list(self, opnum, result_type, valueboxes,
descr):
+ op0 = ResOperation(opnum, valueboxes)
if result_type == 'void':
- result = None
- elif result_type == 'int':
- result = BoxInt()
- elif result_type == 'ref':
- result = BoxPtr()
- elif result_type == 'float':
- result = BoxFloat()
+ op1 = ResOperation(rop.FINISH, [], descr=BasicFinalDescr(0))
else:
- raise ValueError(result_type)
- if result is None:
- results = []
- else:
- results = [result]
- operations = [ResOperation(opnum, valueboxes, result),
- ResOperation(rop.FINISH, results, None,
- descr=BasicFinalDescr(0))]
+ op1 = ResOperation(rop.FINISH, [op0], descr=BasicFinalDescr(0))
+ operations = [op0, op1]
if operations[0].is_guard():
operations[0].setfailargs([])
if not descr:
@@ -104,7 +93,7 @@
operations[0].setdescr(descr)
inputargs = []
for box in valueboxes:
- if isinstance(box, Box) and box not in inputargs:
+ if not isinstance(box, Const) and box not in inputargs:
inputargs.append(box)
return inputargs, operations
@@ -413,16 +402,13 @@
for opnum, boxargs, retvalue in get_int_tests():
print opnum
res = self.execute_operation(opnum, boxargs, 'int')
- assert res.value == retvalue
+ assert res == retvalue
def test_float_operations(self):
from rpython.jit.metainterp.test.test_executor import get_float_tests
for opnum, boxargs, rettype, retvalue in get_float_tests(self.cpu):
res = self.execute_operation(opnum, boxargs, rettype)
- if isinstance(res, BoxFloat):
- assert res.getfloat() == retvalue
- else:
- assert res.value == retvalue
+ assert res == retvalue
def test_ovf_operations(self, reversed=False):
minint = -sys.maxint-1
diff --git a/rpython/jit/metainterp/executor.py
b/rpython/jit/metainterp/executor.py
--- a/rpython/jit/metainterp/executor.py
+++ b/rpython/jit/metainterp/executor.py
@@ -481,8 +481,8 @@
return wrap_constant(_execute_nonspec(cpu, metainterp, opnum, argboxes,
descr, type))
[email protected](5)
-def _execute_nonspec(cpu, metainterp, opnum, argboxes, descr=None, type='i'):
[email protected](2)
+def _execute_nonspec(cpu, metainterp, opnum, argboxes, descr=None):
arity = resoperation.oparity[opnum]
assert arity == -1 or len(argboxes) == arity
if resoperation.opwithdescr[opnum]:
diff --git a/rpython/jit/metainterp/resoperation.py
b/rpython/jit/metainterp/resoperation.py
--- a/rpython/jit/metainterp/resoperation.py
+++ b/rpython/jit/metainterp/resoperation.py
@@ -320,6 +320,7 @@
return self._resfloat
getvalue = getfloatstorage
+ getfloat = getfloatstorage
def setfloatstorage(self, floatval):
self._resfloat = floatval
diff --git a/rpython/jit/metainterp/test/test_executor.py
b/rpython/jit/metainterp/test/test_executor.py
--- a/rpython/jit/metainterp/test/test_executor.py
+++ b/rpython/jit/metainterp/test/test_executor.py
@@ -1,9 +1,10 @@
import py
import sys, random
from rpython.rlib.rarithmetic import r_uint, intmask
-from rpython.jit.metainterp.executor import execute
+from rpython.jit.metainterp.executor import execute, wrap_constant
from rpython.jit.metainterp.executor import execute_varargs, _execute_nonspec
-from rpython.jit.metainterp.resoperation import rop, opname, opclasses
+from rpython.jit.metainterp.resoperation import rop, opname, opclasses,\
+ InputArgInt, InputArgFloat, InputArgRef
from rpython.jit.metainterp.history import ConstInt, ConstPtr, ConstFloat
from rpython.jit.metainterp.history import AbstractDescr
from rpython.jit.metainterp import history
@@ -63,7 +64,7 @@
self.fakestrsetitem = (string, index, newvalue)
def boxfloat(x):
- return BoxFloat(longlong.getfloatstorage(x))
+ return InputArgFloat(longlong.getfloatstorage(x))
def constfloat(x):
return ConstFloat(longlong.getfloatstorage(x))
@@ -72,18 +73,18 @@
def test_execute():
cpu = FakeCPU()
descr = FakeDescr()
- box = execute(cpu, None, rop.INT_ADD, None, BoxInt(40), ConstInt(2))
- assert box.value == 42
+ box = execute(cpu, None, rop.INT_ADD, None, InputArgInt(40), ConstInt(2))
+ assert box == 42
box = execute(cpu, None, rop.NEW, descr)
- assert box.value.fakeargs == ('new', descr)
+ assert box.fakeargs == ('new', descr)
def test_execute_varargs():
cpu = FakeCPU()
descr = FakeCallDescr()
- argboxes = [BoxInt(99999), BoxInt(321), constfloat(2.25), ConstInt(123),
- BoxPtr(), boxfloat(5.5)]
- box = execute_varargs(cpu, FakeMetaInterp(), rop.CALL, argboxes, descr)
- assert box.getfloat() == 42.5
+ argboxes = [InputArgInt(99999), InputArgInt(321), constfloat(2.25),
ConstInt(123),
+ InputArgRef(), boxfloat(5.5)]
+ box = execute_varargs(cpu, FakeMetaInterp(), rop.CALL_F, argboxes, descr)
+ assert box == 42.5
assert cpu.fakecalled == (99999, [321, 123],
[ConstPtr.value],
[longlong.getfloatstorage(2.25),
@@ -95,39 +96,40 @@
descr = FakeDescr()
# cases with a descr
# arity == -1
- argboxes = [BoxInt(321), ConstInt(123)]
- box = execute_nonspec(cpu, FakeMetaInterp(), rop.CALL,
- argboxes, FakeCallDescr())
- assert box.getfloat() == 42.5
+ argboxes = [InputArgInt(321), ConstInt(123)]
+ box = _execute_nonspec(cpu, FakeMetaInterp(), rop.CALL_F,
+ argboxes, FakeCallDescr())
+ assert box == 42.5
# arity == 0
- box = execute_nonspec(cpu, None, rop.NEW, [], descr)
- assert box.value.fakeargs == ('new', descr)
+ box = _execute_nonspec(cpu, None, rop.NEW, [], descr)
+ assert box.fakeargs == ('new', descr)
# arity == 1
- box1 = BoxPtr()
- box = execute_nonspec(cpu, None, rop.ARRAYLEN_GC, [box1], descr)
- assert box.value == 55
+ box1 = InputArgRef()
+ box = _execute_nonspec(cpu, None, rop.ARRAYLEN_GC, [box1], descr)
+ assert box == 55
# arity == 2
box2 = boxfloat(222.2)
fielddescr = FakeFieldDescr()
- execute_nonspec(cpu, None, rop.SETFIELD_GC, [box1, box2], fielddescr)
- assert cpu.fakesetfield == (box1.value, box2.value, fielddescr)
+ _execute_nonspec(cpu, None, rop.SETFIELD_GC, [box1, box2], fielddescr)
+ assert cpu.fakesetfield == (box1.getref_base(), box2.getfloat(),
+ fielddescr)
# arity == 3
- box3 = BoxInt(33)
+ box3 = InputArgInt(33)
arraydescr = FakeArrayDescr()
- execute_nonspec(cpu, None, rop.SETARRAYITEM_GC, [box1, box3, box2],
+ _execute_nonspec(cpu, None, rop.SETARRAYITEM_GC, [box1, box3, box2],
arraydescr)
- assert cpu.fakesetarrayitem == (box1.value, box3.value, box2.value,
- arraydescr)
+ assert cpu.fakesetarrayitem == (box1.getref_base(), box3.getint(),
+ box2.getfloat(), arraydescr)
# cases without descr
# arity == 1
- box = execute_nonspec(cpu, None, rop.INT_INVERT, [box3])
- assert box.value == ~33
+ box = _execute_nonspec(cpu, None, rop.INT_INVERT, [box3])
+ assert box == ~33
# arity == 2
- box = execute_nonspec(cpu, None, rop.INT_LSHIFT, [box3, BoxInt(3)])
- assert box.value == 33 << 3
+ box = _execute_nonspec(cpu, None, rop.INT_LSHIFT, [box3, InputArgInt(3)])
+ assert box == 33 << 3
# arity == 3
- execute_nonspec(cpu, None, rop.STRSETITEM, [box1, BoxInt(3), box3])
- assert cpu.fakestrsetitem == (box1.value, 3, box3.value)
+ _execute_nonspec(cpu, None, rop.STRSETITEM, [box1, InputArgInt(3), box3])
+ assert cpu.fakestrsetitem == (box1.getref_base(), 3, box3.getint())
# ints
@@ -230,21 +232,21 @@
list(_int_binary_operations()) +
list(_int_comparison_operations()) +
list(_int_unary_operations())):
- yield opnum, [BoxInt(x) for x in args], retvalue
+ yield opnum, [InputArgInt(x) for x in args], retvalue
if len(args) > 1:
assert len(args) == 2
- yield opnum, [BoxInt(args[0]), ConstInt(args[1])], retvalue
- yield opnum, [ConstInt(args[0]), BoxInt(args[1])], retvalue
+ yield opnum, [InputArgInt(args[0]), ConstInt(args[1])], retvalue
+ yield opnum, [ConstInt(args[0]), InputArgInt(args[1])], retvalue
if args[0] == args[1]:
- commonbox = BoxInt(args[0])
+ commonbox = InputArgInt(args[0])
yield opnum, [commonbox, commonbox], retvalue
def test_int_ops():
cpu = FakeCPU()
for opnum, boxargs, retvalue in get_int_tests():
- box = execute_nonspec(cpu, None, opnum, boxargs)
- assert box.getint() == retvalue
+ r = _execute_nonspec(cpu, None, opnum, boxargs)
+ assert r == retvalue
# floats
@@ -296,30 +298,25 @@
boxargs = []
for x in args:
if isinstance(x, float):
- boxargs.append(boxfloat(x))
+ boxargs.append(InputArgFloat(x))
else:
- boxargs.append(BoxInt(x))
+ boxargs.append(InputArgInt(x))
yield opnum, boxargs, rettype, retvalue
if len(args) > 1:
assert len(args) == 2
- yield opnum, [boxargs[0], boxargs[1].constbox()], rettype, retvalue
- yield opnum, [boxargs[0].constbox(), boxargs[1]], rettype, retvalue
+ yield opnum, [boxargs[0], wrap_constant(boxargs[1].getvalue())],
rettype, retvalue
+ yield opnum, [wrap_constant(boxargs[0].getvalue()), boxargs[1]],
rettype, retvalue
if (isinstance(args[0], float) and
isinstance(args[1], float) and
args[0] == args[1]):
- commonbox = boxfloat(args[0])
+ commonbox = InputArgFloat(args[0])
yield opnum, [commonbox, commonbox], rettype, retvalue
def test_float_ops():
cpu = FakeCPU()
for opnum, boxargs, rettype, retvalue in get_float_tests(cpu):
- box = execute_nonspec(cpu, None, opnum, boxargs)
- if rettype == 'float':
- assert box.getfloat() == retvalue
- elif rettype == 'int':
- assert box.getint() == retvalue
- else:
- assert 0, "rettype is %r" % (rettype,)
+ res = _execute_nonspec(cpu, None, opnum, boxargs)
+ assert res == retvalue
def make_args_for_op(op, a, b):
n=opname[op]
@@ -350,7 +347,7 @@
arg1, arg2 = make_args_for_op(op1, a, b)
box1 = execute(cpu, None, op1, None, arg1, arg2)
box2 = execute(cpu, None, op2, None, arg1, arg2)
- assert box1.value == (not box2.value)
+ assert box1 == (not box2)
def test_opboolreflex():
cpu = FakeCPU()
@@ -364,4 +361,4 @@
arg1, arg2 = make_args_for_op(op1, a, b)
box1 = execute(cpu, None, op1, None, arg1, arg2)
box2 = execute(cpu, None, op2, None, arg2, arg1)
- assert box1.value == box2.value
+ assert box1 == box2
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit