Пример #1
0
 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()
Пример #2
0
 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
Пример #3
0
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,)
Пример #4
0
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, )
Пример #5
0
 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
Пример #6
0
 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()
Пример #7
0
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)
Пример #8
0
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
Пример #9
0
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
Пример #10
0
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)