selfhost-compiler: make EmitterBox/MirEmitterBox static; call as Class.method to avoid NewBox→birth warnings and stabilize JSON emission path

This commit is contained in:
nyash-codex
2025-09-28 20:54:14 +09:00
parent 59eb39e8a0
commit 1d49e24bf0
4 changed files with 6 additions and 15 deletions

View File

@ -1,5 +1,5 @@
// EmitterBox — thin wrapper to emit JSON v0 (extracted)
box EmitterBox {
static box EmitterBox {
emit_program(json, usings_json) {
if json == null { return json }
// Normalize usings payload to at least an empty array so meta.usings is always present
@ -20,7 +20,3 @@ box EmitterBox {
return head + "\"meta\":{\"usings\":" + payload + "}" + tail
}
}
static box EmitterStub {
main(args) { return 0 }
}

View File

@ -2,7 +2,7 @@
// Scope: Return(Int) only (const + ret). Safe default to 0 when not found.
// Future: add Binary/Compare/ExternCall/BoxCall lowering incrementally.
box MirEmitterBox {
static box MirEmitterBox {
// Extract first Return(Int) value from Stage-1 JSON (very small string scan)
_extract_return_int(ast_json) {
if ast_json == null { return 0 }
@ -47,6 +47,3 @@ box MirEmitterBox {
return s
}
}
static box MirEmitterStub { main(args) { return 0 } }

View File

@ -115,12 +115,10 @@ static box Main {
if emit_mir == 1 {
// Lower minimal AST to MIR JSON (Return(Int) only for MVP)
local mir = new MirEmitterBox()
json = mir.emit_mir_min(ast_json)
json = MirEmitterBox.emit_mir_min(ast_json)
} else {
// Emit Stage1 JSON with metadata
local emitter = new EmitterBox()
json = emitter.emit_program(ast_json, me._usings)
json = EmitterBox.emit_program(ast_json, me._usings)
}
// Output JSON

View File

@ -16,8 +16,8 @@ fi
echo "[selfhost-smoke] Step 1: Emit JSON via selfhost compiler (min-json, stage3)"
OUT_JSON="/tmp/nyash_selfhost_out.json"
set -x
if NYASH_ENABLE_USING=1 NYASH_ALLOW_USING_FILE=1 NYASH_USING_AST=1 NYASH_NY_COMPILER_MIN_JSON=1 \
"${NY_BIN}" apps/selfhost-compiler/compiler.nyash -- --stage3 > "${OUT_JSON}"; then
if NYASH_ENABLE_USING=1 NYASH_ALLOW_USING_FILE=1 NYASH_USING_AST=1 \
"${NY_BIN}" apps/selfhost-compiler/compiler.nyash -- --min-json --emit-mir --stage3 > "${OUT_JSON}"; then
:
else
echo "[selfhost-smoke] WARN: selfhost compiler emission failed (policy/duplicates?). Continuing." >&2