This guide answers a practical question:
Can I test HAS compiler-generated code on a virtual CPU?
Yes. On Linux (or WSL), HAS provides an optional Musashi-based runtime test
tier that compiles your .has program, assembles it, and executes it on a
virtual Motorola 68000 CPU.
Use this when you want execution-level confidence in generated code behavior (branches, arithmetic, call/return flow), not just parse/codegen success.
This workflow is intentionally Linux-only right now.
- Supported: native Linux and WSL
- Not supported: Windows shells (PowerShell/CMD) for this runtime flow
Run these commands from the repository root:
./scripts/setup_musashi.sh
./scripts/build_musashi_runner.sh
./scripts/test_runtime_musashi.shOptional pytest entrypoints:
python3 -m pytest tests/test_runtime_musashi.py -v
python3 -m pytest -m "runtime and musashi" -v- Linux or WSL terminal
gitpython3gccvasmm68k_motinPATH- Python dependencies installed:
python3 -m pip install -r requirements.txtQuick tool check:
command -v git
command -v python3
command -v gcc
command -v vasmm68k_motAfter setup:
- Musashi sources are prepared in
build/musashi-src - Pinned commit is read from
tools/musashi.lock
After build:
- Runner binary exists at
build/has-musashi-runner
After runtime test script:
- Tests listed in
tests/runtime_musashi_manifest.txtare compiled and executed - Summary should end with
fail=0
For pytest runs:
- Runtime Musashi tests should report
PASSED
Cause:
- Running from a non-Linux shell.
Fix:
- Use a Linux or WSL terminal.
Cause:
- Missing C toolchain (
gcc) or build dependencies.
Fix:
- Install/verify
gcc, then rerun:
./scripts/build_musashi_runner.shCause:
- Missing Linux prerequisite (commonly assembler/toolchain).
Fix:
- Install missing tool(s), verify
vasmm68k_motis inPATH, rerun runtime test.
Cause:
- Test did not emit required MMIO signal.
Fix:
- Ensure test writes PASS or FAIL using the MMIO protocol described below.
The Musashi runner treats MMIO writes as test signals:
0x00100004-> PASS event0x00100000-> FAIL event0x00100014-> write one debug byte to stdout (optional)
Add a .has file under examples/runtime_musashi/.
Minimal shape:
code main:
; Optional test logic here
asm "move.l #1,$00100004"; ; PASS
asm "stop #$2700";
Use FAIL instead when asserting a failure path:
asm "move.l #1,$00100000"; ; FAIL
Add the new file path to tests/runtime_musashi_manifest.txt.
./scripts/test_runtime_musashi.shpython3 -m pytest tests/test_runtime_musashi.py -vReference examples:
examples/runtime_musashi/smoke_mmio_pass.hasexamples/runtime_musashi/proc_math_branch_pass.has
- Technical overview:
docs/MUSASHI_RUNTIME_TESTING.md