docs/runtime: externcall + println normalization; NyRT silent result flag; PyVM console warn/error/trace routing\nselfhost(M2): add MirEmitterBox (Return(Int)->const+ret) and --emit-mir switch; initial selfhost smoke\nrunner: child args/env hardening for selfhost (NYASH_NY_COMPILER_CHILD_ARGS under --; NYASH_JSON_ONLY=1, NYASH_VM_USE_PY=1, NYASH_DISABLE_PLUGINS=1); VM path strips using lines when NYASH_ENABLE_USING=1\nmeta: clarify PyVM/llvmlite as primary (vm/interpreter legacy OFF) in CURRENT_TASK.md; README links to externcall docs

This commit is contained in:
Selfhosting Dev
2025-09-18 06:35:49 +09:00
parent 9a7d77d868
commit 3fe908eb0d
26 changed files with 514 additions and 22 deletions

View File

@ -5,6 +5,7 @@
include "apps/selfhost-compiler/boxes/debug_box.nyash"
include "apps/selfhost-compiler/boxes/parser_box.nyash"
include "apps/selfhost-compiler/boxes/emitter_box.nyash"
include "apps/selfhost-compiler/boxes/mir_emitter_box.nyash"
static box Main {
// ---- IO helper ----
@ -90,27 +91,36 @@ static box Main {
// Gate: minimal JSON when requested via script arg
local min_mode = 0
local emit_mir = 0
if args != null {
local alen = args.length()
local i = 0
loop(i < alen) {
local arg = args.get(i)
if arg == "--min-json" { min_mode = 1 }
if arg == "--emit-mir" { emit_mir = 1 }
i = i + 1
}
}
local json = null
local ast_json = null
if min_mode == 1 {
json = "{\"version\":0,\"kind\":\"Program\",\"body\":[{\"type\":\"Return\",\"expr\":{\"type\":\"Int\",\"value\":0}}]}"
ast_json = "{\"version\":0,\"kind\":\"Program\",\"body\":[{\"type\":\"Return\",\"expr\":{\"type\":\"Int\",\"value\":0}}]}"
} else {
json = me.parse_program(src, stage3_mode)
ast_json = me.parse_program(src, stage3_mode)
}
// Emit via EmitterBox (attach meta.usings when available)
local emitter = new EmitterBox()
json = emitter.emit_program(json, me._usings)
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)
} else {
// Emit Stage1 JSON with metadata
local emitter = new EmitterBox()
json = emitter.emit_program(ast_json, me._usings)
}
// Output
// Output JSON
local console = new ConsoleBox()
console.println(json)
return 0