Esempio n. 1
0
def test_two_simple_loops_break():
    vm = VM(
        LoopStack([
            LoopTree.LEAF(16),
            LoopTree.LEAF(16),
        ]),
        num_locals=1,
        ram_size=0,
    )
    ins = Block([
        InsLoopSpecified(
            Block([
                InsArith([0], False, ArithMode.CHECKED, lambda n: n + 1),
                InsLocalSet(0),
                InsConst(BeltNum(DataType.I8, Integer(3))),
                InsRel(a_idx=0,
                       b_idx=1,
                       is_signed=False,
                       op=lambda a, b: a < b),
                InsBrIf(condition_idx=0, br_depth=1),
                InsLocalGet(0),
            ])),
        InsLoopSpecified(
            Block([
                InsArith([0], False, ArithMode.CHECKED, lambda n: n + 1),
                InsLocalSet(0),
                InsConst(BeltNum(DataType.I8, Integer(7))),
                InsRel(a_idx=0,
                       b_idx=1,
                       is_signed=False,
                       op=lambda a, b: a < b),
                InsBrIf(condition_idx=0, br_depth=1),
                InsLocalGet(0),
            ])),
    ])
    ins.run(vm)
    belt = [vm.belt().get_num(i).value.expect_int() for i in range(Belt.SIZE)]
    assert belt == [1, 7, 8, 7, 0, 7, 7, 6, 0, 7, 6, 5, 0, 7, 5, 4]
    assert vm.local(0).value.expect_int() == 8
Esempio n. 2
0
 def run(self, vm: VM) -> Optional['Break']:
     vm.belt().push(vm.local(self._local_idx))
     return None