Skip to main content

Python reference implementation of the X-Quadratic Virtual Machine (conformance oracle).

Project description

xqvm_py

Status — transitional. xqvm_py is the executable conformance oracle for the XQuad toolchain: every vector under ../conformance/ must produce identical observable state on both this Python reference and the Rust xqvm production runtime. The arrangement is explicitly transitional. Once the Rust runtime is fully battle-tested, xqvm_py may be dropped entirely (with conformance vectors graduating to "Rust must produce exactly these outputs" reference data) or demoted to a prototyping sandbox for trying out new opcodes / VM features in Python before they earn a spec slot. Do not build infrastructure that hard-depends on xqvm_py's existence.

Python reference implementation of the X-Quadratic Virtual Machine. See ../spec/xqvm/SPEC.md for the authoritative technical specification.

Scope

  • Pure-Python executor, state model, opcodes, xqmx (sparse quadratic matrix), vector, and tracer.
  • No assembler or disassembler: the Rust xqasm crate is the only implementation, exposed to Python via xqffi.asm (pyo3). Tests and the CLI shim call xqvm_py.program_from_xqasm to turn .xqasm text into an executable Program.

Layout

xqvm_py/                  <-- this directory IS the package (flat layout)
  __init__.py             re-exports the public surface (Executor, Program, …)
  __main__.py             entry point for `python -m xqvm_py`
  executor.py             fetch-decode-execute loop
  state.py                stack, registers, loop control, jump table
  opcodes.py              Opcode enum + operand metadata
  program.py              Program dataclass + program_from_xqasm()
  xqmx.py                 sparse quadratic matrix (model + sample modes)
  vector.py               typed vec<int> / vec<xqmx>
  errors.py               typed runtime errors
  tracer.py               step-by-step execution tracer
  cli/                    python -m xqvm_py run ...
  tests/                  pytest suite (wheel-excluded)

Quick start

From the xquad workspace root:

uv sync                                       # installs xqvm_py editable + xqffi via maturin
uv run pytest xqvm_py/tests                   # run the full test suite
echo "PUSH 5
PUSH 3
ADD
HALT" > /tmp/prog.xqasm
uv run python -m xqvm_py run /tmp/prog.xqasm  # CLI shim

Programmatic use:

from xqvm_py import Executor, program_from_xqasm

prog = program_from_xqasm("PUSH 10\nPUSH 5\nADD\nSTOW r0\nHALT\n")
executor = Executor()
executor.execute(prog)
print(executor.state.get_register(0))  # 15

Conformance

Behavioural parity with the Rust xqvm crate is enforced by the xquad-conformance Rust test harness at ../conformance/. New VM semantics require a new vector. Divergence between implementations fails CI with no "drift tracking" middle ground.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xqvm_py-0.3.0rc1.tar.gz (51.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xqvm_py-0.3.0rc1-py3-none-any.whl (39.1 kB view details)

Uploaded Python 3

File details

Details for the file xqvm_py-0.3.0rc1.tar.gz.

File metadata

  • Download URL: xqvm_py-0.3.0rc1.tar.gz
  • Upload date:
  • Size: 51.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for xqvm_py-0.3.0rc1.tar.gz
Algorithm Hash digest
SHA256 5b8170d8cd10500ee2c07bc5b3c07899996ba01e2e0dca45c01dfcc213f7c5ec
MD5 c04149d8f7c7caa8da84e15dc7bc039b
BLAKE2b-256 ee6fd1b2a937ff96c11aaf506bb98d7f15831fac67d7a8b87e2780e0525e9b49

See more details on using hashes here.

File details

Details for the file xqvm_py-0.3.0rc1-py3-none-any.whl.

File metadata

  • Download URL: xqvm_py-0.3.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 39.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for xqvm_py-0.3.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 746ab6632e4641b0928a502a5d431991ac94ac6cbc3b23ebb68045a1e60380a1
MD5 cb93d32e4a1df769730183f62b3fc569
BLAKE2b-256 53ec8dd7467bf788c3138c22b939345cb921ce7a7ca1c40dfbf5237bd5aaec16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page