def test_float_ops(): cpu = FakeCPU() for opnum, boxargs, rettype, retvalue in get_float_tests(cpu): res = _execute_arglist(cpu, None, opnum, boxargs) if rettype == 'float': res = longlong.getrealfloat(res) assert res == retvalue
def do(self, opnum, argboxes, descr=None): self.fakemetainterp._got_exc = None op = ResOperation(opnum, argboxes, descr) result = _execute_arglist(self.cpu, self.fakemetainterp, opnum, argboxes, descr) if result is not None: c_result = wrap_constant(result) op.copy_value_from(c_result) self.loop.operations.append(op) return op
def do(self, opnum, argboxes, descr=None): self.fakemetainterp._got_exc = None op = ResOperation(opnum, argboxes, descr) if opnum != rop.ZERO_PTR_FIELD: result = _execute_arglist(self.cpu, self.fakemetainterp, opnum, argboxes, descr) if result is not None: c_result = wrap_constant(result) op.copy_value_from(c_result) else: import ctypes addr = self.cpu.cast_gcref_to_int(argboxes[0].getref_base()) offset = argboxes[1].getint() assert (offset % ctypes.sizeof(ctypes.c_long)) == 0 ptr = ctypes.cast(addr, ctypes.POINTER(ctypes.c_long)) ptr[offset / ctypes.sizeof(ctypes.c_long)] = 0 self.loop.operations.append(op) return op
def do(self, opnum, argboxes, descr=None): self.fakemetainterp._got_exc = None op = ResOperation(opnum, argboxes, descr) argboxes = map(constbox, argboxes) result = _execute_arglist(self.cpu, self.fakemetainterp, opnum, argboxes, descr) if result is not None: if lltype.typeOf(result) == lltype.Signed: op._example_int = result elif isinstance(result, bool): op._example_int = int(result) elif lltype.typeOf(result) == longlong.FLOATSTORAGE: op._example_float = result elif isinstance(result, float): op._example_float = longlong.getfloatstorage(result) else: assert lltype.typeOf(result) == llmemory.GCREF op._example_ref = result self.loop.operations.append(op) return op
def test_execute_nonspec(): cpu = FakeCPU() descr = FakeDescr() # cases with a descr # arity == -1 argboxes = [InputArgInt(321), ConstInt(123)] box = _execute_arglist(cpu, FakeMetaInterp(), rop.CALL_F, argboxes, FakeCallDescr()) assert longlong.getrealfloat(box) == 42.5 # arity == 0 box = _execute_arglist(cpu, None, rop.NEW, [], descr) assert box.fakeargs == ('new', descr) # arity == 1 box1 = InputArgRef() box = _execute_arglist(cpu, None, rop.ARRAYLEN_GC, [box1], descr) assert box == 55 # arity == 2 box2 = boxfloat(222.2) fielddescr = FakeFieldDescr() _execute_arglist(cpu, None, rop.SETFIELD_GC, [box1, box2], fielddescr) assert cpu.fakesetfield == (box1.getref_base(), box2.getfloatstorage(), fielddescr) # arity == 3 box3 = InputArgInt(33) arraydescr = FakeArrayDescr() _execute_arglist(cpu, None, rop.SETARRAYITEM_GC, [box1, box3, box2], arraydescr) assert cpu.fakesetarrayitem == (box1.getref_base(), box3.getint(), box2.getfloatstorage(), arraydescr) # cases without descr # arity == 1 box = _execute_arglist(cpu, None, rop.INT_INVERT, [box3]) assert box == ~33 # arity == 2 box = _execute_arglist(cpu, None, rop.INT_LSHIFT, [box3, InputArgInt(3)]) assert box == 33 << 3 # arity == 3 _execute_arglist(cpu, None, rop.STRSETITEM, [box1, InputArgInt(3), box3]) assert cpu.fakestrsetitem == (box1.getref_base(), 3, box3.getint())
def test_int_ops(): cpu = FakeCPU() for opnum, boxargs, retvalue in get_int_tests(): r = _execute_arglist(cpu, None, opnum, boxargs) assert r == retvalue