def test_classical(): parse_equals("MOVE ro[0] 1", MOVE(MemoryReference("ro", 0), 1)) parse_equals("MOVE ro[0] 0", MOVE(MemoryReference("ro", 0), 0)) parse_equals("NOT ro[0]", NOT(MemoryReference("ro", 0))) parse_equals("AND ro[0] 1", AND(MemoryReference("ro", 0), 1)) parse_equals("IOR ro[0] 1", IOR(MemoryReference("ro", 0), 1)) parse_equals("MOVE ro[0] 1", MOVE(MemoryReference("ro", 0), 1)) parse_equals("XOR ro[0] 1", XOR(MemoryReference("ro", 0), 1)) parse_equals("ADD mem[0] 1.2", ADD(MemoryReference("mem", 0), 1.2)) parse_equals("SUB mem[0] 1.2", SUB(MemoryReference("mem", 0), 1.2)) parse_equals("MUL mem[0] 1.2", MUL(MemoryReference("mem", 0), 1.2)) parse_equals("DIV mem[0] 1.2", DIV(MemoryReference("mem", 0), 1.2)) parse_equals("ADD mem[0] -1.2", ADD(MemoryReference("mem", 0), -1.2)) parse_equals("SUB mem[0] -1.2", SUB(MemoryReference("mem", 0), -1.2)) parse_equals("MUL mem[0] -1.2", MUL(MemoryReference("mem", 0), -1.2)) parse_equals("DIV mem[0] -1.2", DIV(MemoryReference("mem", 0), -1.2)) parse_equals( "EQ comp[1] ro[3] ro[2]", EQ(MemoryReference("comp", 1), MemoryReference("ro", 3), MemoryReference("ro", 2)), ) parse_equals( "LT comp[1] ro[3] ro[2]", LT(MemoryReference("comp", 1), MemoryReference("ro", 3), MemoryReference("ro", 2)), ) parse_equals( "LE comp[1] ro[3] ro[2]", LE(MemoryReference("comp", 1), MemoryReference("ro", 3), MemoryReference("ro", 2)), ) parse_equals( "GT comp[1] ro[3] ro[2]", GT(MemoryReference("comp", 1), MemoryReference("ro", 3), MemoryReference("ro", 2)), ) parse_equals( "GE comp[1] ro[3] ro[2]", GE(MemoryReference("comp", 1), MemoryReference("ro", 3), MemoryReference("ro", 2)), ) parse_equals("EQ comp[1] ro[3] 0", EQ(MemoryReference("comp", 1), MemoryReference("ro", 3), 0)) parse_equals("LT comp[1] ro[3] 1", LT(MemoryReference("comp", 1), MemoryReference("ro", 3), 1)) parse_equals("LE comp[1] ro[3] 2", LE(MemoryReference("comp", 1), MemoryReference("ro", 3), 2)) parse_equals("GT comp[1] ro[3] 3", GT(MemoryReference("comp", 1), MemoryReference("ro", 3), 3)) parse_equals("GE comp[1] ro[3] 4", GE(MemoryReference("comp", 1), MemoryReference("ro", 3), 4)) parse_equals( "EQ comp[1] ro[3] 0.0", EQ(MemoryReference("comp", 1), MemoryReference("ro", 3), 0.0) ) parse_equals( "LT comp[1] ro[3] 1.1", LT(MemoryReference("comp", 1), MemoryReference("ro", 3), 1.1) ) parse_equals( "LE comp[1] ro[3] 2.2", LE(MemoryReference("comp", 1), MemoryReference("ro", 3), 2.2) ) parse_equals( "GT comp[1] ro[3] 3.3", GT(MemoryReference("comp", 1), MemoryReference("ro", 3), 3.3) ) parse_equals( "GE comp[1] ro[3] 4.4", GE(MemoryReference("comp", 1), MemoryReference("ro", 3), 4.4) )
def test_ternary_classicals(): p = Program() p.inst( LOAD(MemoryReference("ro", 0), "ro", MemoryReference("n", 0)), STORE("ro", MemoryReference("n", 0), MemoryReference("ro", 0)), STORE("ro", MemoryReference("n", 0), 0), STORE("ro", MemoryReference("n", 0), 0.1), EQ(MemoryReference("ro", 0), MemoryReference("ro", 1), 0), EQ(MemoryReference("ro", 0), MemoryReference("ro", 1), 0.0), EQ(MemoryReference("ro", 0), MemoryReference("ro", 1), MemoryReference("ro", 0)), GE(MemoryReference("ro", 0), MemoryReference("ro", 1), 1), GE(MemoryReference("ro", 0), MemoryReference("ro", 1), 1.1), GE(MemoryReference("ro", 0), MemoryReference("ro", 1), MemoryReference("ro", 1)), GT(MemoryReference("ro", 0), MemoryReference("ro", 1), 2), GT(MemoryReference("ro", 0), MemoryReference("ro", 1), 2.2), GT(MemoryReference("ro", 0), MemoryReference("ro", 1), MemoryReference("ro", 2)), LE(MemoryReference("ro", 0), MemoryReference("ro", 1), 3), LE(MemoryReference("ro", 0), MemoryReference("ro", 1), 3.3), LE(MemoryReference("ro", 0), MemoryReference("ro", 1), MemoryReference("ro", 3)), LT(MemoryReference("ro", 0), MemoryReference("ro", 1), 4), LT(MemoryReference("ro", 0), MemoryReference("ro", 1), 4.4), LT(MemoryReference("ro", 0), MemoryReference("ro", 1), MemoryReference("ro", 4)), ) assert (p.out() == "LOAD ro[0] ro n[0]\n" "STORE ro n[0] ro[0]\n" "STORE ro n[0] 0\n" "STORE ro n[0] 0.1\n" "EQ ro[0] ro[1] 0\n" "EQ ro[0] ro[1] 0.0\n" "EQ ro[0] ro[1] ro[0]\n" "GE ro[0] ro[1] 1\n" "GE ro[0] ro[1] 1.1\n" "GE ro[0] ro[1] ro[1]\n" "GT ro[0] ro[1] 2\n" "GT ro[0] ro[1] 2.2\n" "GT ro[0] ro[1] ro[2]\n" "LE ro[0] ro[1] 3\n" "LE ro[0] ro[1] 3.3\n" "LE ro[0] ro[1] ro[3]\n" "LT ro[0] ro[1] 4\n" "LT ro[0] ro[1] 4.4\n" "LT ro[0] ro[1] ro[4]\n")
def test_ternary_classicals(): p = Program() p.inst(LOAD(MemoryReference("ro", 0), "ro", MemoryReference("n", 0)), STORE("ro", MemoryReference("n", 0), MemoryReference("ro", 0)), EQ(MemoryReference("ro", 0), MemoryReference("ro", 1), MemoryReference("ro", 2)), GT(MemoryReference("ro", 0), MemoryReference("ro", 1), MemoryReference("ro", 2)), GE(MemoryReference("ro", 0), MemoryReference("ro", 1), MemoryReference("ro", 2)), LE(MemoryReference("ro", 0), MemoryReference("ro", 1), MemoryReference("ro", 2)), LT(MemoryReference("ro", 0), MemoryReference("ro", 1), MemoryReference("ro", 2))) assert p.out() == 'LOAD ro[0] ro n[0]\n' \ 'STORE ro n[0] ro[0]\n' \ 'EQ ro[0] ro[1] ro[2]\n' \ 'GT ro[0] ro[1] ro[2]\n' \ 'GE ro[0] ro[1] ro[2]\n' \ 'LE ro[0] ro[1] ro[2]\n' \ 'LT ro[0] ro[1] ro[2]\n'