Assemble source → bytecode → decode produces the same program as parsing source directly.
()
| 24 | |
| 25 | |
| 26 | def test_bytecode_round_trip(): |
| 27 | """Assemble source → bytecode → decode produces the same program as parsing source directly.""" |
| 28 | source = "PUSH 7\nPUSH 5\nADD\nSTOW r0\nPUSH 0\nOUTPUT r0\nHALT\n" |
| 29 | bytecode = assemble_source(source) |
| 30 | |
| 31 | from_asm = program_from_xqasm(source) |
| 32 | from_bc = program_from_bytecode(bytecode) |
| 33 | |
| 34 | assert len(from_asm) == len(from_bc) |
| 35 | for i, (a, b) in enumerate(zip(from_asm.instructions, from_bc.instructions)): |
| 36 | assert a.opcode == b.opcode, f"instruction {i}: opcode mismatch {a.opcode} != {b.opcode}" |
| 37 | assert a.operands == b.operands, f"instruction {i}: operands mismatch {a.operands} != {b.operands}" |
| 38 | |
| 39 | |
| 40 | def _make_xqbc(code: bytes) -> bytes: |
nothing calls this directly
no test coverage detected