MCPcopy Create free account
hub / github.com/QuipNetwork/xquad / test_bytecode_round_trip

Function test_bytecode_round_trip

xqvm_py/tests/test_program.py:26–37  ·  view source on GitHub ↗

Assemble source → bytecode → decode produces the same program as parsing source directly.

()

Source from the content-addressed store, hash-verified

24
25
26def 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
40def _make_xqbc(code: bytes) -> bytes:

Callers

nothing calls this directly

Calls 3

assemble_sourceFunction · 0.90
program_from_xqasmFunction · 0.90
program_from_bytecodeFunction · 0.90

Tested by

no test coverage detected