diff --git a/tools/selfhost/README.md b/tools/selfhost/README.md index 43809afa..21c0cdaa 100644 --- a/tools/selfhost/README.md +++ b/tools/selfhost/README.md @@ -8,14 +8,17 @@ Script - tools/selfhost/selfhost_build.sh - --in : input Hako source - --json : write Program(JSON v0); default: /tmp/hako_stageb_$$.json + - --mir : emit MIR(JSON) from source (runner path) + - --exe : build native executable via ny-llvmc (llvmlite harness) - --run: run via Gate‑C/Core Direct (in‑proc). Exit code mirrors program return. - Env: - NYASH_BIN: path to hakorune/nyash binary (auto-detected) - NYASH_ROOT: repo root (auto-detected) + - HAKO_USE_BUILDBOX=1: use BuildBox for emit-only (no run/exe) Examples ```bash -# Emit JSON only +# Emit JSON only (Stage‑B) tools/selfhost/selfhost_build.sh --in apps/demo/main.hako --json /tmp/demo.json # Run and use exit code @@ -23,7 +26,6 @@ tools/selfhost/selfhost_build.sh --in apps/demo/return7.hako --run; echo $? ``` Notes -- The script uses Stage‑B entry (lang/src/compiler/entry/compiler_stageb.hako). +- Stage‑B emit uses either the Stage‑B entry or BuildBox(HAKO_USE_BUILDBOX=1 for emit-only) - Runner executes Core‑Direct in-proc under HAKO_CORE_DIRECT_INPROC=1. - For heavier cases (bundles/alias/require), keep Stage‑B canaries opt‑in in quick profile. - diff --git a/tools/selfhost/selfhost_build.sh b/tools/selfhost/selfhost_build.sh index 7eb561db..1528a366 100644 --- a/tools/selfhost/selfhost_build.sh +++ b/tools/selfhost/selfhost_build.sh @@ -24,6 +24,7 @@ fi IN="" JSON_OUT="" +MIR_OUT="" EXE_OUT="" DO_RUN=0 @@ -32,6 +33,7 @@ while [ $# -gt 0 ]; do --in) IN="$2"; shift 2;; --json) JSON_OUT="$2"; shift 2;; --run) DO_RUN=1; shift;; + --mir) MIR_OUT="$2"; shift 2;; --exe) EXE_OUT="$2"; shift 2;; *) echo "[selfhost] unknown arg: $1" >&2; exit 2;; esac @@ -92,6 +94,12 @@ if [ -n "$JSON_OUT" ]; then echo "[selfhost] JSON v0 written: $tmp_json" >&2 fi +# Optional: emit MIR(JSON) from source (runner compiles .hako directly; Stage‑B JSON is for reference) +if [ -n "$MIR_OUT" ]; then + echo "[selfhost] emitting MIR JSON → $MIR_OUT" >&2 + "$BIN" --backend mir --emit-mir-json "$MIR_OUT" "$IN" >/dev/null +fi + # Optional: build native EXE via ny-llvmc harness (fallback path; parses original source) if [ -n "$EXE_OUT" ]; then # Requirements: ny-llvmc present and harness envs