def constant_fold(self, op): argboxes = [ self.get_constant_box(op.getarg(i)) for i in range(op.numargs()) ] resbox = execute_nonspec(self.cpu, None, op.getopnum(), argboxes, op.getdescr()) return resbox.constbox()
def do(self, opnum, argboxes, descr=None): self.fakemetainterp._got_exc = None v_result = execute_nonspec(self.cpu, self.fakemetainterp, opnum, argboxes, descr) if isinstance(v_result, Const): v_result = v_result.clonebox() self.loop.operations.append(ResOperation(opnum, argboxes, v_result, descr)) return v_result
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,)
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, )
def do(self, opnum, argboxes, descr=None): self.fakemetainterp._got_exc = None if opnum == rop.ZERO_PTR_FIELD: v_result = None else: v_result = execute_nonspec(self.cpu, self.fakemetainterp, opnum, argboxes, descr) if isinstance(v_result, Const): v_result = v_result.clonebox() self.loop.operations.append( ResOperation(opnum, argboxes, v_result, descr)) return v_result
def constant_fold(self, op): argboxes = [self.get_constant_box(op.getarg(i)) for i in range(op.numargs())] resbox = execute_nonspec(self.cpu, None, op.getopnum(), argboxes, op.getdescr()) return resbox.constbox()
def test_execute_nonspec(): cpu = FakeCPU() 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 # arity == 0 box = execute_nonspec(cpu, None, rop.NEW, [], descr) assert box.value.fakeargs == ('new', descr) # arity == 1 box1 = BoxPtr() box = execute_nonspec(cpu, None, rop.ARRAYLEN_GC, [box1], descr) assert box.value == 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) # arity == 3 box3 = BoxInt(33) arraydescr = FakeArrayDescr() execute_nonspec(cpu, None, rop.SETARRAYITEM_GC, [box1, box3, box2], arraydescr) assert cpu.fakesetarrayitem == (box1.value, box3.value, box2.value, arraydescr) # cases without descr # arity == 1 box = execute_nonspec(cpu, None, rop.INT_INVERT, [box3]) assert box.value == ~33 # arity == 2 box = execute_nonspec(cpu, None, rop.INT_LSHIFT, [box3, BoxInt(3)]) assert box.value == 33 << 3 # arity == 3 execute_nonspec(cpu, None, rop.STRSETITEM, [box1, BoxInt(3), box3]) assert cpu.fakestrsetitem == (box1.value, 3, box3.value)
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
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
def test_execute_nonspec(): cpu = FakeCPU() 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 # arity == 0 box = execute_nonspec(cpu, None, rop.NEW, [], descr) assert box.value.fakeargs == ('new', descr) # arity == 1 box1 = BoxPtr() box = execute_nonspec(cpu, None, rop.ARRAYLEN_GC, [box1], descr) assert box.value == 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) # arity == 3 box3 = BoxInt(33) arraydescr = FakeArrayDescr() execute_nonspec(cpu, None, rop.SETARRAYITEM_GC, [box1, box3, box2], arraydescr) assert cpu.fakesetarrayitem == (box1.value, box3.value, box2.value, arraydescr) # cases without descr # arity == 1 box = execute_nonspec(cpu, None, rop.INT_INVERT, [box3]) assert box.value == ~33 # arity == 2 box = execute_nonspec(cpu, None, rop.INT_LSHIFT, [box3, BoxInt(3)]) assert box.value == 33 << 3 # arity == 3 execute_nonspec(cpu, None, rop.STRSETITEM, [box1, BoxInt(3), box3]) assert cpu.fakestrsetitem == (box1.value, 3, box3.value)