def test_nested_loop(): ast = parse(',[<[-]>].') c = Compiler(ast) b = c.compile() exp = [chr(bytecodes.BF_READ), chr(bytecodes.BF_JUMP_IF_ZERO)] + c.encode4(24) + [chr(bytecodes.BF_DCR_DP), chr(bytecodes.BF_JUMP_IF_ZERO)] + c.encode4(18) + [chr(bytecodes.BF_DCR_D), chr(bytecodes.BF_JUMP_UNLESS_ZERO)] + c.encode4(12) + [chr(bytecodes.BF_INCR_DP), chr(bytecodes.BF_JUMP_UNLESS_ZERO)] + c.encode4(6) + [chr(bytecodes.BF_ECHO)] print b print exp assert len(b) == len(exp) assert b == exp
def test_compile_loop(): ast = parse('[-]') c = Compiler(ast) b = c.compile() exp = [chr(bytecodes.BF_JUMP_IF_ZERO)] + c.encode4(11) + [chr(bytecodes.BF_DCR_D)] + [chr(bytecodes.BF_JUMP_UNLESS_ZERO)] + c.encode4(5) assert b == exp