def test_if_z_tricky_2(self):
     source = c.if_z_tricky(1, 1, 1, c.inc_pos(5), c.inc_pos(6))
     sim = BfSim(source)
     sim.memory[1] = 0
     sim.run(10000)
     self.assertEqual(sim.memory[1], 0)
     self.assertEqual(sim.memory[5], 1)
     self.assertEqual(sim.memory[6], 0)
Пример #2
0
def _if_top_decimal_is_nz_then_override() -> str:
    "TOPの小数部が0以外なら、TOPをSECONDに移動"
    return c.if_z_tricky(
        TOP + IDX_DEC,
        ELEMENT_SIZE,  # work1 = NOW + IDX_DEC
        ELEMENT_SIZE,  # work2 = NEXT + IDX_DEC
        then_statement=c.clear_pos(TOP + IDX_SGN),
        else_statement=c.block_of(
            c.override_data(TOP + IDX_SGN, SECOND + IDX_SGN),
            c.move_data(TOP + IDX_DEC, SECOND + IDX_DEC)))
Пример #3
0
def _dec_both_abs_decimal() -> str:
    "小数部を片方が0になるまで両方をデクリメント"
    count = NOW
    work1 = NOW + 1
    return c.block_of(
        c.copy_data(SECOND + 2, count, work1),
        c.for_loop(
            count,
            c.if_z_tricky(
                TOP + IDX_DEC,
                ELEMENT_SIZE,  # work2 = NOW + IDX_DEC
                ELEMENT_SIZE,  # work3 = NEXT + IDX_DEC
                then_statement=loop_last(count),
                else_statement=c.block_of(c.dec_pos(SECOND + IDX_DEC),
                                          c.dec_pos(TOP + IDX_DEC)))))