Ejemplo n.º 1
0
def test_execute():
    cpu = FakeCPU()
    descr = FakeDescr()
    box = execute(cpu, rop.INT_ADD, None, BoxInt(40), ConstInt(2))
    assert box.value == 42
    box = execute(cpu, rop.NEW, descr)
    assert box.args == ('new', descr)
Ejemplo n.º 2
0
    def _really_force(self):
        op = self.source_op
        assert op is not None
        # ^^^ This case should not occur any more (see test_bug_3).
        #
        if not we_are_translated():
            op.name = 'FORCE ' + self.source_op.name

        if self._is_immutable_and_filled_with_constants():
            box = self.optimizer.constant_fold(op)
            self.make_constant(box)
            for ofs, value in self._fields.iteritems():
                subbox = value.force_box()
                assert isinstance(subbox, Const)
                execute(self.optimizer.cpu, None, rop.SETFIELD_GC,
                        ofs, box, subbox)
            # keep self._fields, because it's all immutable anyway
        else:
            newoperations = self.optimizer.newoperations
            newoperations.append(op)
            self.box = box = op.result
            #
            iteritems = self._fields.iteritems()
            if not we_are_translated(): #random order is fine, except for tests
                iteritems = list(iteritems)
                iteritems.sort(key = lambda (x,y): x.sort_key())
            for ofs, value in iteritems:
                if value.is_null():
                    continue
                subbox = value.force_box()
                op = ResOperation(rop.SETFIELD_GC, [box, subbox], None,
                                  descr=ofs)
                newoperations.append(op)
            self._fields = None
Ejemplo n.º 3
0
 def test_nullity_with_guard(self):
     allops = [rop.INT_IS_TRUE]
     guards = [rop.GUARD_TRUE, rop.GUARD_FALSE]
     p = lltype.cast_opaque_ptr(llmemory.GCREF, lltype.malloc(lltype.GcStruct("x")))
     nullptr = lltype.nullptr(llmemory.GCREF.TO)
     f = BoxInt()
     for op in allops:
         for guard in guards:
             if op == rop.INT_IS_TRUE:
                 bp = BoxInt(1)
                 n = BoxInt(0)
             else:
                 bp = BoxPtr(p)
                 n = BoxPtr(nullptr)
             for b in (bp, n):
                 i1 = BoxInt(1)
                 ops = [
                     ResOperation(rop.SAME_AS, [ConstInt(1)], i1),
                     ResOperation(op, [b], f),
                     ResOperation(guard, [f], None, descr=BasicFailDescr()),
                     ResOperation(rop.FINISH, [ConstInt(0)], None, descr=BasicFailDescr()),
                 ]
                 ops[-2].setfailargs([i1])
                 looptoken = JitCellToken()
                 self.cpu.compile_loop([b], ops, looptoken)
                 self.cpu.execute_token(looptoken, b.value)
                 result = self.cpu.get_latest_value_int(0)
                 if guard == rop.GUARD_FALSE:
                     assert result == execute(self.cpu, None, op, None, b).value
                 else:
                     assert result != execute(self.cpu, None, op, None, b).value
Ejemplo n.º 4
0
    def _really_force(self, optforce):
        op = self.source_op
        assert op is not None
        # ^^^ This case should not occur any more (see test_bug_3).
        #
        if not we_are_translated():
            op.name = 'FORCE ' + self.source_op.name

        if self._is_immutable_and_filled_with_constants():
            box = optforce.optimizer.constant_fold(op)
            self.make_constant(box)
            for ofs, value in self._fields.iteritems():
                subbox = value.force_box(optforce)
                assert isinstance(subbox, Const)
                execute(optforce.optimizer.cpu, None, rop.SETFIELD_GC,
                        ofs, box, subbox)
            # keep self._fields, because it's all immutable anyway
        else:
            optforce.emit_operation(op)
            self.box = box = op.result
            #
            iteritems = self._fields.iteritems()
            if not we_are_translated(): #random order is fine, except for tests
                iteritems = list(iteritems)
                iteritems.sort(key = lambda (x,y): x.sort_key())
            for ofs, value in iteritems:
                if value.is_null():
                    continue
                subbox = value.force_box(optforce)
                op = ResOperation(rop.SETFIELD_GC, [box, subbox], None,
                                  descr=ofs)

                optforce.emit_operation(op)
Ejemplo n.º 5
0
def test_opboolreflex():
    cpu = FakeCPU()
    for op1, op2 in opboolreflex.items():
        for a in (1,2,3):
            for b in (1,2,3):
                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
Ejemplo n.º 6
0
 def extract_runtime_data(self, cpu, valuebox, resultlist):
     from pypy.jit.metainterp import executor, history, resoperation
     for ofs, subspecnode in self.fields:
         assert isinstance(ofs, history.AbstractDescr)
         fieldbox = executor.execute(cpu, resoperation.rop.GETFIELD_GC,
                                     ofs, valuebox)
         subspecnode.extract_runtime_data(cpu, fieldbox, resultlist)
Ejemplo n.º 7
0
 def extract_runtime_data(self, cpu, valuebox, resultlist):
     from pypy.jit.metainterp import executor, history, resoperation
     for ofs, subspecnode in self.fields:
         assert isinstance(ofs, history.AbstractDescr)
         fieldbox = executor.execute(cpu, resoperation.rop.GETFIELD_GC, ofs,
                                     valuebox)
         subspecnode.extract_runtime_data(cpu, fieldbox, resultlist)
Ejemplo n.º 8
0
 def extract_runtime_data(self, cpu, valuebox, resultlist):
     from pypy.jit.metainterp import executor, history, resoperation
     for i in range(len(self.items)):
         itembox = executor.execute(cpu, resoperation.rop.GETARRAYITEM_GC,
                                    self.arraydescr,
                                    valuebox, history.ConstInt(i))
         subspecnode = self.items[i]
         subspecnode.extract_runtime_data(cpu, itembox, resultlist)
Ejemplo n.º 9
0
 def extract_runtime_data(self, cpu, valuebox, resultlist):
     from pypy.jit.metainterp import executor, history, resoperation
     for i in range(len(self.items)):
         itembox = executor.execute(cpu, resoperation.rop.GETARRAYITEM_GC,
                                    self.arraydescr, valuebox,
                                    history.ConstInt(i))
         subspecnode = self.items[i]
         subspecnode.extract_runtime_data(cpu, itembox, resultlist)
Ejemplo n.º 10
0
 def execute_and_record(self, opnum, descr, *argboxes):
     resbox = executor.execute(self.cpu, None, opnum, descr, *argboxes)
     self.trace.append((opnum,
                        list(argboxes),
                        resbox,
                        descr))
     if resbox is not None:
         self.resboxes.append(resbox)
     return resbox
Ejemplo n.º 11
0
 def execute_and_record(self, opnum, descr, *argboxes):
     resbox = executor.execute(self.cpu, opnum, descr, *argboxes)
     self.trace.append((opnum,
                        list(argboxes),
                        resbox,
                        descr))
     if resbox is not None:
         self.resboxes.append(resbox)
     return resbox
Ejemplo n.º 12
0
 def test_stuff_followed_by_guard(self):
     boxes = [
         (BoxInt(1), BoxInt(0)),
         (BoxInt(0), BoxInt(1)),
         (BoxInt(1), BoxInt(1)),
         (BoxInt(-1), BoxInt(1)),
         (BoxInt(1), BoxInt(-1)),
         (ConstInt(1), BoxInt(0)),
         (ConstInt(0), BoxInt(1)),
         (ConstInt(1), BoxInt(1)),
         (ConstInt(-1), BoxInt(1)),
         (ConstInt(1), BoxInt(-1)),
         (BoxInt(1), ConstInt(0)),
         (BoxInt(0), ConstInt(1)),
         (BoxInt(1), ConstInt(1)),
         (BoxInt(-1), ConstInt(1)),
         (BoxInt(1), ConstInt(-1)),
     ]
     guards = [rop.GUARD_FALSE, rop.GUARD_TRUE]
     all = [
         rop.INT_EQ,
         rop.INT_NE,
         rop.INT_LE,
         rop.INT_LT,
         rop.INT_GT,
         rop.INT_GE,
         rop.UINT_GT,
         rop.UINT_LT,
         rop.UINT_LE,
         rop.UINT_GE,
     ]
     for a, b in boxes:
         for guard in guards:
             for op in all:
                 res = BoxInt()
                 i1 = BoxInt(1)
                 ops = [
                     ResOperation(rop.SAME_AS, [ConstInt(1)], i1),
                     ResOperation(op, [a, b], res),
                     ResOperation(guard, [res], None, descr=BasicFailDescr()),
                     ResOperation(rop.FINISH, [ConstInt(0)], None, descr=BasicFailDescr()),
                 ]
                 ops[-2].setfailargs([i1])
                 inputargs = [i for i in (a, b) if isinstance(i, Box)]
                 looptoken = LoopToken()
                 self.cpu.compile_loop(inputargs, ops, looptoken)
                 for i, box in enumerate(inputargs):
                     self.cpu.set_future_value_int(i, box.value)
                 self.cpu.execute_token(looptoken)
                 result = self.cpu.get_latest_value_int(0)
                 expected = execute(self.cpu, None, op, None, a, b).value
                 if guard == rop.GUARD_FALSE:
                     assert result == expected
                 else:
                     assert result != expected
Ejemplo n.º 13
0
 def test_nullity_with_guard(self):
     allops = [rop.OONONNULL, rop.OOISNULL, rop.INT_IS_TRUE]
     guards = [rop.GUARD_TRUE, rop.GUARD_FALSE]
     p = lltype.cast_opaque_ptr(llmemory.GCREF,
                                lltype.malloc(lltype.GcStruct('x')))
     nullptr = lltype.nullptr(llmemory.GCREF.TO)
     f = BoxInt()
     for op in allops:
         for guard in guards:
             if op == rop.INT_IS_TRUE:
                 bp = BoxInt(1)
                 n = BoxInt(0)
             else:
                 bp = BoxPtr(p)
                 n = BoxPtr(nullptr)
             for b in (bp, n):
                 i1 = BoxInt(1)
                 ops = [
                     ResOperation(rop.SAME_AS, [ConstInt(1)], i1),
                     ResOperation(op, [b], f),
                     ResOperation(guard, [f], None, descr=BasicFailDescr()),
                     ResOperation(rop.FINISH, [ConstInt(0)],
                                  None,
                                  descr=BasicFailDescr()),
                 ]
                 ops[-2].fail_args = [i1]
                 looptoken = LoopToken()
                 self.cpu.compile_loop([b], ops, looptoken)
                 if op == rop.INT_IS_TRUE:
                     self.cpu.set_future_value_int(0, b.value)
                 else:
                     self.cpu.set_future_value_ref(0, b.value)
                 r = self.cpu.execute_token(looptoken)
                 result = self.cpu.get_latest_value_int(0)
                 if guard == rop.GUARD_FALSE:
                     assert result == execute(self.cpu, op, None, b).value
                 else:
                     assert result != execute(self.cpu, op, None, b).value
Ejemplo n.º 14
0
 def test_stuff_followed_by_guard(self):
     boxes = [(BoxInt(1), BoxInt(0)),
              (BoxInt(0), BoxInt(1)),
              (BoxInt(1), BoxInt(1)),
              (BoxInt(-1), BoxInt(1)),
              (BoxInt(1), BoxInt(-1)),
              (ConstInt(1), BoxInt(0)),
              (ConstInt(0), BoxInt(1)),
              (ConstInt(1), BoxInt(1)),
              (ConstInt(-1), BoxInt(1)),
              (ConstInt(1), BoxInt(-1)),
              (BoxInt(1), ConstInt(0)),
              (BoxInt(0), ConstInt(1)),
              (BoxInt(1), ConstInt(1)),
              (BoxInt(-1), ConstInt(1)),
              (BoxInt(1), ConstInt(-1))]
     guards = [rop.GUARD_FALSE, rop.GUARD_TRUE]
     all = [rop.INT_EQ, rop.INT_NE, rop.INT_LE, rop.INT_LT, rop.INT_GT,
            rop.INT_GE, rop.UINT_GT, rop.UINT_LT, rop.UINT_LE, rop.UINT_GE]
     for a, b in boxes:
         for guard in guards:
             for op in all:
                 res = BoxInt()
                 i1 = BoxInt(1)
                 ops = [
                     ResOperation(rop.SAME_AS, [ConstInt(1)], i1),
                     ResOperation(op, [a, b], res),
                     ResOperation(guard, [res], None,
                                  descr=BasicFailDescr()),
                     ResOperation(rop.FINISH, [ConstInt(0)], None,
                                  descr=BasicFailDescr()),
                     ]
                 ops[-2].setfailargs([i1])
                 inputargs = [i for i in (a, b) if isinstance(i, Box)]
                 looptoken = JitCellToken()
                 self.cpu.compile_loop(inputargs, ops, looptoken)
                 inputvalues = [box.value for box in inputargs]
                 self.cpu.execute_token(looptoken, *inputvalues)
                 result = self.cpu.get_latest_value_int(0)
                 expected = execute(self.cpu, None, op, None, a, b).value
                 if guard == rop.GUARD_FALSE:
                     assert result == expected
                 else:
                     assert result != expected
Ejemplo n.º 15
0
 def get_current_constant_fieldvalue(self):
     from pypy.jit.metainterp import executor
     from pypy.jit.metainterp.resoperation import rop
     fieldbox = executor.execute(self.cpu, None, rop.GETFIELD_GC,
                                 self.fielddescr, self.structbox)
     return fieldbox.constbox()
Ejemplo n.º 16
0
 def get_current_constant_fieldvalue(self):
     from pypy.jit.metainterp import executor
     from pypy.jit.metainterp.resoperation import rop
     fieldbox = executor.execute(self.cpu, None, rop.GETFIELD_GC,
                                 self.fielddescr, self.structbox)
     return fieldbox.constbox()