diff --git a/docs/development/selfhosting/quickstart.md b/docs/development/selfhosting/quickstart.md index 69ae6a81..43511f2f 100644 --- a/docs/development/selfhosting/quickstart.md +++ b/docs/development/selfhosting/quickstart.md @@ -2,16 +2,17 @@ This note shows how to run the Nyash self‑host compiler MVP to emit MIR(JSON v0) and execute it with the current VM line. The flow keeps defaults unchanged and uses small, opt‑in flags for development. -## Layout -- Compiler MVP: `apps/selfhost-compiler/compiler.nyash` -- Runtime helpers (dev): `apps/selfhost-runtime/` -- Mini‑VM samples (dev): `apps/selfhost/vm/` +## Layout (migrated) +- Compiler entry (Stage‑B): `lang/src/compiler/entry/compiler_stageb.hako` +- Compiler entry (compat, Stage‑A/AOT): `lang/src/compiler/entry/compiler.hako` +- Shared helpers live under `lang/src/shared/` +- VM/Core live under `lang/src/vm/` ## Run the self‑host compiler -Compile a minimal program (string embedded in the compiler) and print JSON: +Compile a minimal program (string embedded in the compiler) and print JSON v0: ``` -./target/release/nyash apps/selfhost-compiler/compiler.nyash -- --stage3 +./target/release/nyash lang/src/compiler/entry/compiler_stageb.hako -- --stage3 --source 'box Main { static method main() { return 7 } }' ``` ENV → child args (透過): @@ -22,8 +23,8 @@ ENV → child args (透過): Examples: ``` -NYASH_NY_COMPILER_MIN_JSON=1 ./target/release/nyash apps/selfhost-compiler/compiler.nyash -- --stage3 > /tmp/out.json -NYASH_SELFHOST_READ_TMP=1 ./target/release/nyash apps/selfhost-compiler/compiler.nyash -- --min-json --stage3 +NYASH_NY_COMPILER_MIN_JSON=1 ./target/release/nyash lang/src/compiler/entry/compiler_stageb.hako -- --stage3 --source 'box Main { static method main() { return 1+2 } }' > /tmp/out.json +NYASH_SELFHOST_READ_TMP=1 ./target/release/nyash lang/src/compiler/entry/compiler_stageb.hako -- --min-json --stage3 ``` ## Execute MIR(JSON v0) diff --git a/nyash.toml b/nyash.toml index 1d2ef974..36a3f27d 100644 --- a/nyash.toml +++ b/nyash.toml @@ -50,19 +50,9 @@ path = "lang/src/shared/common/string_helpers.hako" [modules] # Map logical namespaces to Nyash source paths (consumed by runner) -selfhost.compiler.debug = "apps/selfhost/compiler/boxes/debug_box.nyash" -selfhost.compiler.parser = "apps/selfhost/compiler/boxes/parser_box.nyash" -selfhost.compiler.emitter = "apps/selfhost/compiler/boxes/emitter_box.nyash" -selfhost.compiler.mir = "apps/selfhost/compiler/boxes/mir_emitter_box.nyash" -selfhost.vm.json_cur = "apps/selfhost/vm/boxes/json_cur.nyash" -selfhost.vm.json = "apps/selfhost/common/json_adapter.nyash" -selfhost.vm.core = "apps/selfhost/vm/boxes/mini_vm_core.nyash" -selfhost.vm.scan = "apps/selfhost/common/mini_vm_scan.nyash" -selfhost.vm.binop = "apps/selfhost/common/mini_vm_binop.nyash" -selfhost.vm.compare = "apps/selfhost/common/mini_vm_compare.nyash" -selfhost.vm.prints = "apps/selfhost/vm/boxes/mini_vm_prints.nyash" -selfhost.vm.seam = "apps/selfhost/vm/boxes/seam_inspector.nyash" -selfhost.vm.mir_min = "apps/selfhost/vm/boxes/mir_vm_min.nyash" +# NOTE (Phase‑20.33): legacy `apps/selfhost/*` modules have been retired. +# If you still rely on `selfhost.*` keys, migrate to the `lang.*`/`hakorune.*` +# equivalents below. This removal is intentional to surface stale references. # Lang compiler (Phase 20.33 migration) "lang.compiler.parser.box" = "lang/src/compiler/parser/parser_box.hako" @@ -99,7 +89,7 @@ selfhost.vm.mir_min = "apps/selfhost/vm/boxes/mir_vm_min.nyash" "lang.compiler.emit.common.newbox_emit" = "lang/src/compiler/emit/common/newbox_emit_box.hako" "lang.compiler.emit.common.header_emit" = "lang/src/compiler/emit/common/header_emit_box.hako" -# Shared helpers (selfhost shared/vm) +# Shared helpers (selfhost shared/vm) — kept under `lang/` tree "selfhost.shared.json_adapter" = "lang/src/shared/json_adapter.hako" "selfhost.shared.common.mini_vm_scan" = "lang/src/shared/common/mini_vm_scan.hako" "selfhost.shared.common.mini_vm_binop" = "lang/src/shared/common/mini_vm_binop.hako" @@ -119,11 +109,7 @@ selfhost.vm.mir_min = "apps/selfhost/vm/boxes/mir_vm_min.nyash" "hakorune.vm.mir_min" = "lang/src/vm/boxes/mir_vm_min.hako" "hakorune.vm.core" = "lang/src/vm/boxes/mini_vm_core.hako" -# Temporary alias keys (migration aid; keys kept stable) -selfhost.common.json = "apps/selfhost/common/json_adapter.nyash" -selfhost.common.scan = "apps/selfhost/common/mini_vm_scan.nyash" -selfhost.common.binop = "apps/selfhost/common/mini_vm_binop.nyash" -selfhost.common.compare = "apps/selfhost/common/mini_vm_compare.nyash" +# Temporary alias keys removed (Phase‑20.33 TTL reached). Use `selfhost.shared.*` above. # v2 Plugin libraries (loader reads these for TypeBox ABI) [libraries] diff --git a/tools/dep_tree.sh b/tools/dep_tree.sh index d04513e6..dcce5a74 100644 --- a/tools/dep_tree.sh +++ b/tools/dep_tree.sh @@ -3,6 +3,16 @@ set -euo pipefail ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) ENTRY=${1:-lang/src/compiler/entry/compiler_stageb.hako} -NYASH_DISABLE_PLUGINS=0 NYASH_CLI_VERBOSE=0 NYASH_USE_PLUGIN_BUILTINS=1 \ - "$ROOT_DIR/target/release/nyash" --backend interpreter \ - "$ROOT_DIR/apps/selfhost/tools/dep_tree_main.nyash" <<<"$ENTRY" # TODO: migrate to lang tool +# Phase‑20.33: legacy apps/selfhost/tools/dep_tree_main.nyash has been retired. +# Intentionally fail fast to surface stale references. TTL: replace with lang tool. +LEGACY_TOOL="$ROOT_DIR/apps/selfhost/tools/dep_tree_main.nyash" +if [ -f "$LEGACY_TOOL" ]; then + echo "[warn] Using legacy dep_tree tool (apps/selfhost). Migrate to lang tool soon (TTL)." >&2 + NYASH_DISABLE_PLUGINS=0 NYASH_CLI_VERBOSE=0 NYASH_USE_PLUGIN_BUILTINS=1 \ + "$ROOT_DIR/target/release/nyash" --backend interpreter \ + "$LEGACY_TOOL" <<<"$ENTRY" +else + echo "[error] Legacy dep_tree tool not found: $LEGACY_TOOL" >&2 + echo "[hint] Replace this script to call a lang/ tool when available. See CURRENT_TASK.md (Phase‑20.33)." >&2 + exit 2 +fi diff --git a/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_fail_vm.sh b/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_fail_vm.sh new file mode 100644 index 00000000..bc29f9ff --- /dev/null +++ b/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_fail_vm.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# canonicalize_fail_vm.sh — Bridge canonicalize FAIL case (opt-in) + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +ROOT="$(cd "$SCRIPT_DIR/../../../../../.." && pwd)" +source "$ROOT/tools/smokes/v2/lib/test_runner.sh" +require_env || exit 2 + +if [ "${SMOKES_ENABLE_BRIDGE_CANON:-0}" != "1" ]; then + test_skip "bridge_canonicalize_fail" "opt-in (set SMOKES_ENABLE_BRIDGE_CANON=1)" && exit 0 +fi + +# v1 JSON with unsupported instruction to assert stable failure message +json_path="/tmp/ny_v1_fail_$$.json" +cat >"$json_path" <<'JSON' +{"schema_version":"1.0","functions":[{"name":"main","blocks":[{"id":0,"instructions":[{"op":"foo","dst":1},{"op":"ret"}]}]}]} +JSON + +set +e +output=$("$ROOT/target/release/nyash" --json-file "$json_path" 2>&1) +rc=$? +set -e +rm -f "$json_path" + +if [ $rc -ne 0 ] && echo "$output" | grep -q "unsupported instruction 'foo'"; then + echo "[PASS] bridge_canonicalize_fail" + exit 0 +else + echo "[FAIL] bridge_canonicalize_fail: expected failure with stable message" >&2 + echo "$output" >&2 + exit 1 +fi + diff --git a/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_off_vm.sh b/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_off_vm.sh new file mode 100644 index 00000000..a27e213e --- /dev/null +++ b/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_off_vm.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# canonicalize_off_vm.sh — Bridge canonicalize OFF (opt-in) + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +ROOT="$(cd "$SCRIPT_DIR/../../../../../.." && pwd)" +source "$ROOT/tools/smokes/v2/lib/test_runner.sh" +require_env || exit 2 + +if [ "${SMOKES_ENABLE_BRIDGE_CANON:-0}" != "1" ]; then + test_skip "bridge_canonicalize_off" "opt-in (set SMOKES_ENABLE_BRIDGE_CANON=1)" && exit 0 +fi + +# Same v1 minimal JSON (const+ret) without toggles should still run (no mir_call involved) +json_path="/tmp/ny_v1_const_off_$$.json" +cat >"$json_path" <<'JSON' +{"schema_version":"1.0","functions":[{"name":"main","blocks":[{"id":0,"instructions":[{"op":"const","dst":1,"value":{"type":"Integer","value":3}},{"op":"ret","value":1}]}]}]} +JSON + +"$ROOT/target/release/nyash" --json-file "$json_path" >/dev/null 2>&1 +rc=$? +rm -f "$json_path" +if [ $rc -eq 0 ]; then + echo "[PASS] bridge_canonicalize_off" + exit 0 +else + echo "[FAIL] bridge_canonicalize_off: expected rc=0, got $rc" >&2 + exit 1 +fi + diff --git a/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_on_vm.sh b/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_on_vm.sh new file mode 100644 index 00000000..992a4cdb --- /dev/null +++ b/tools/smokes/v2/profiles/quick/core/bridge/canonicalize_on_vm.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# canonicalize_on_vm.sh — Bridge canonicalize ON (opt-in) + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +ROOT="$(cd "$SCRIPT_DIR/../../../../../.." && pwd)" +source "$ROOT/tools/smokes/v2/lib/test_runner.sh" +require_env || exit 2 + +if [ "${SMOKES_ENABLE_BRIDGE_CANON:-0}" != "1" ]; then + test_skip "bridge_canonicalize_on" "opt-in (set SMOKES_ENABLE_BRIDGE_CANON=1)" && exit 0 +fi + +# Minimal v1 JSON with only const/copy/ret (no mir_call), should run regardless +json_path="/tmp/ny_v1_const_$$.json" +cat >"$json_path" <<'JSON' +{"schema_version":"1.0","functions":[{"name":"main","blocks":[{"id":0,"instructions":[{"op":"const","dst":1,"value":{"type":"Integer","value":7}},{"op":"ret","value":1}]}]}]} +JSON + +HAKO_NYVM_V1_DOWNCONVERT=1 HAKO_BRIDGE_INJECT_SINGLETON=1 \ + "$ROOT/target/release/nyash" --json-file "$json_path" >/dev/null 2>&1 +rc=$? +rm -f "$json_path" +if [ $rc -eq 0 ]; then + echo "[PASS] bridge_canonicalize_on" + exit 0 +else + echo "[FAIL] bridge_canonicalize_on: expected rc=0, got $rc" >&2 + exit 1 +fi +