diff --git a/lang/src/compiler/entry/compiler_stageb.hako b/lang/src/compiler/entry/compiler_stageb.hako index cbfa19f7..74277b68 100644 --- a/lang/src/compiler/entry/compiler_stageb.hako +++ b/lang/src/compiler/entry/compiler_stageb.hako @@ -15,12 +15,9 @@ using lang.compiler.parser.box as ParserBox using lang.compiler.entry.func_scanner as FuncScannerBox using lang.compiler.entry.using_resolver as Stage1UsingResolverBox -// Note: Runner resolves entry as Main.main by default. -// Provide static box Main with method main(args) as the entry point. -static box Main { - // Minimal Stage‑B driver: parse args/env, extract main body if wrapped in `box Main { static method main(){...} }`, - // then run ParserBox → FlowEntry emit. Keep implementation single‑method to avoid parser drift issues. - main(args) { +// Phase 25.1c: CLI argument → source resolution +static box StageBArgsBox { + resolve_src(args) { // 1) Collect source from args or env local src = null local src_file = null @@ -44,16 +41,13 @@ static box Main { // Original: if src == null { src = env.local.get("HAKO_SOURCE") } if src == null { src = "return 0" } - // 2) Stage‑3 acceptance default ON for selfhost (env may turn off; keep tolerant here) - local p = new ParserBox() - p.stage3_enable(1) - - // 3) (Temporarily disabled) Extract using/externs — keep minimal path for emit stability - // p.extract_usings(src) - // local usings_json = p.get_usings_json() - // p.extract_externs(src) - // local externs_json = p.get_externs_json() + return src + } +} +// Phase 25.1c: Body extraction + bundle + using + trim +static box StageBBodyExtractorBox { + build_body_src(src, args) { // 4) If wrapped in `box Main { method main() { ... } }` or `static box Main { method main() { ... } }`, // extract the method body text. Allow disabling via env HAKO_STAGEB_BODY_EXTRACT=0. local body_src = null @@ -388,7 +382,7 @@ static box Main { local j = 0 loop(j < m) { if pair.substring(j, j + 1) == ":" { pos = j break } j = j + 1 } } - + if pos >= 0 { local name = pair.substring(0, pos) local code = pair.substring(pos + 1, m) @@ -529,6 +523,27 @@ static box Main { if e > b { body_src = s.substring(b, e) } else { body_src = "" } } + return body_src + } +} + +// Phase 25.1c: Main driver logic +static box StageBDriverBox { + main(args) { + local src = StageBArgsBox.resolve_src(args) + + // 2) Stage‑3 acceptance default ON for selfhost (env may turn off; keep tolerant here) + local p = new ParserBox() + p.stage3_enable(1) + + // 3) (Temporarily disabled) Extract using/externs — keep minimal path for emit stability + // p.extract_usings(src) + // local usings_json = p.get_usings_json() + // p.extract_externs(src) + // local externs_json = p.get_externs_json() + + local body_src = StageBBodyExtractorBox.build_body_src(src, args) + // 6) Parse and emit Stage‑1 JSON v0 (Program) // Bridge(JSON v0) が Program v0 を受け取り MIR に lowering するため、ここでは AST(JSON v0) を出力する。 // 既定で MIR 直出力は行わない(重い経路を避け、一行出力を保証)。 @@ -602,3 +617,12 @@ static box Main { return 0 } } + +// Note: Runner resolves entry as Main.main by default. +// Provide static box Main with method main(args) as the entry point. +// Phase 25.1c: Entry point (thin wrapper) +static box Main { + main(args) { + return StageBDriverBox.main(args) + } +}