Parse ``.xqasm`` source via the Rust xqasm crate and wrap the result. This is the single entry point xqvm-py uses to turn assembly text into an executable ``Program``. The actual parsing + assembly is done by ``xqffi.asm.parse_xqasm`` (a pyo3 binding to Rust ``xqasm``); this helper
(source: str, name: str = "")
| 161 | |
| 162 | |
| 163 | def program_from_xqasm(source: str, name: str = "") -> Program: |
| 164 | """Parse ``.xqasm`` source via the Rust xqasm crate and wrap the result. |
| 165 | |
| 166 | This is the single entry point xqvm-py uses to turn assembly text |
| 167 | into an executable ``Program``. The actual parsing + assembly is |
| 168 | done by ``xqffi.asm.parse_xqasm`` (a pyo3 binding to Rust |
| 169 | ``xqasm``); this helper just adapts the wire dict into the Python |
| 170 | dataclass layout the executor expects. |
| 171 | |
| 172 | The ``program_from_xqasm`` / ``Instruction`` / ``Program`` trio |
| 173 | replaces what used to be ``xqvm.assembler.assemble(src).program`` |
| 174 | — xqvm-py no longer ships its own assembler. |
| 175 | """ |
| 176 | from xqffi.asm import parse_xqasm |
| 177 | |
| 178 | wire = parse_xqasm(source) |
| 179 | instructions = [Instruction(Opcode.from_code(code), tuple(ops), int(pc)) for code, ops, pc in wire["instructions"]] |
| 180 | return Program(instructions=instructions, name=name, jump_targets=_build_jump_targets(instructions)) |