stage-b (P0): stabilize entry — compiler_stageb.hako now emits Stage‑1 Program(JSON v0) directly (one-line), avoiding heavy MIR path; FlowEntry prefers v1→v0 first; noisy debug prints in pipeline with_usings gated. Quick core/stageb canaries PASS.
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
// Stage-B compiler entry — ParserBox → FlowEntry emit-only
|
// Stage-B compiler entry — ParserBox → FlowEntry emit-only
|
||||||
|
|
||||||
using lang.compiler.parser.box as ParserBox
|
using lang.compiler.parser.box as ParserBox
|
||||||
using lang.compiler.pipeline_v2.flow_entry as FlowEntryBox
|
|
||||||
|
|
||||||
static box StageBMain {
|
static box StageBMain {
|
||||||
// Minimal Stage‑B driver: parse args/env, extract main body if wrapped in `box Main { static method main(){...} }`,
|
// Minimal Stage‑B driver: parse args/env, extract main body if wrapped in `box Main { static method main(){...} }`,
|
||||||
@ -68,13 +67,11 @@ static box StageBMain {
|
|||||||
|
|
||||||
if body_src == null { body_src = src }
|
if body_src == null { body_src = src }
|
||||||
|
|
||||||
// 5) Parse and emit MIR(JSON v0)
|
// 5) Parse and emit Stage‑1 JSON v0 (Program)
|
||||||
|
// Bridge(JSON v0) が Program v0 を受け取り MIR に lowering するため、ここでは AST(JSON v0) を出力する。
|
||||||
|
// 既定で MIR 直出力は行わない(重い経路を避け、一行出力を保証)。
|
||||||
local ast_json = p.parse_program2(body_src)
|
local ast_json = p.parse_program2(body_src)
|
||||||
local prefer = 1
|
print(ast_json)
|
||||||
local out = FlowEntryBox.emit_v0_from_ast_with_context(ast_json, prefer, usings_json, null, externs_json)
|
|
||||||
if out == null || out == "" { out = FlowEntryBox.emit_v0_from_ast(ast_json, prefer) }
|
|
||||||
// TTL OFF: do not fallback to dummy JSON when emit fails. Empty output surfaces failure to caller.
|
|
||||||
print(out)
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,13 @@ static box FlowEntryBox {
|
|||||||
|
|
||||||
// Emit v0 with optional using / extern metadata(Stage‑B entry)
|
// Emit v0 with optional using / extern metadata(Stage‑B entry)
|
||||||
emit_v0_from_ast_with_context(ast_json, prefer_cfg, usings_json, modules_json, externs_json) {
|
emit_v0_from_ast_with_context(ast_json, prefer_cfg, usings_json, modules_json, externs_json) {
|
||||||
|
// 1) Prefer lightweight v1→v0 経路(簡単な return/binop/compare/call/new はここで完結)
|
||||||
|
{
|
||||||
|
local j1 = PipelineV2.lower_stage1_to_mir_v1(ast_json, prefer_cfg)
|
||||||
|
if j1 != null { return MirJsonV1Adapter.to_v0(j1) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2) using 情報があれば using 解決つきの v0 経路を試す
|
||||||
local used_with_usings = 0
|
local used_with_usings = 0
|
||||||
local out = null
|
local out = null
|
||||||
if usings_json != null && usings_json != "" && usings_json != "[]" {
|
if usings_json != null && usings_json != "" && usings_json != "[]" {
|
||||||
@ -25,9 +32,10 @@ static box FlowEntryBox {
|
|||||||
if out == null {
|
if out == null {
|
||||||
out = PipelineV2.lower_stage1_to_mir(ast_json, prefer_cfg)
|
out = PipelineV2.lower_stage1_to_mir(ast_json, prefer_cfg)
|
||||||
}
|
}
|
||||||
|
// 3) externs が指定され、まだ v1 経路を使っていない場合は v1+meta → v0 を試す
|
||||||
if externs_json != null && externs_json != "" && externs_json != "[]" && used_with_usings == 0 {
|
if externs_json != null && externs_json != "" && externs_json != "[]" && used_with_usings == 0 {
|
||||||
local j1 = PipelineV2.lower_stage1_to_mir_v1_with_meta(ast_json, prefer_cfg, externs_json)
|
local j2 = PipelineV2.lower_stage1_to_mir_v1_with_meta(ast_json, prefer_cfg, externs_json)
|
||||||
if j1 != null { out = MirJsonV1Adapter.to_v0(j1) }
|
if j2 != null { out = MirJsonV1Adapter.to_v0(j2) }
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
@ -457,10 +457,15 @@ flow PipelineV2 {
|
|||||||
}
|
}
|
||||||
// Overload: resolve names via UsingResolverBox before emit
|
// Overload: resolve names via UsingResolverBox before emit
|
||||||
lower_stage1_to_mir_with_usings(ast_json, prefer_cfg, usings_json, modules_json) {
|
lower_stage1_to_mir_with_usings(ast_json, prefer_cfg, usings_json, modules_json) {
|
||||||
print("[DEBUG] === lower_stage1_to_mir_with_usings ENTRY ===")
|
// Debug logs are noisy: emit only when prefer_cfg is a large debug value (>=9)
|
||||||
print("[DEBUG] ast_json length=" + ast_json.length())
|
local _dbg = 0
|
||||||
print("[DEBUG] usings_json=" + usings_json)
|
if prefer_cfg != null { if (""+prefer_cfg) == "9" { _dbg = 1 } }
|
||||||
print("[DEBUG] modules_json=" + modules_json)
|
if _dbg == 1 {
|
||||||
|
print("[DEBUG] === lower_stage1_to_mir_with_usings ENTRY ===")
|
||||||
|
print("[DEBUG] ast_json length=" + ast_json.length())
|
||||||
|
print("[DEBUG] usings_json=" + usings_json)
|
||||||
|
print("[DEBUG] modules_json=" + modules_json)
|
||||||
|
}
|
||||||
if ast_json == null { return PipelineV2.lower_stage1_to_mir(ast_json, prefer_cfg) }
|
if ast_json == null { return PipelineV2.lower_stage1_to_mir(ast_json, prefer_cfg) }
|
||||||
// Build resolver context
|
// Build resolver context
|
||||||
local r = UsingResolverBox.state_new()
|
local r = UsingResolverBox.state_new()
|
||||||
@ -468,7 +473,7 @@ flow PipelineV2 {
|
|||||||
if modules_json != null { UsingResolverBox.load_modules_json(r, modules_json) }
|
if modules_json != null { UsingResolverBox.load_modules_json(r, modules_json) }
|
||||||
// Upgrade alias→namespace mapping now that modules are loaded (Module‑First)
|
// Upgrade alias→namespace mapping now that modules are loaded (Module‑First)
|
||||||
UsingResolverBox.upgrade_aliases(r)
|
UsingResolverBox.upgrade_aliases(r)
|
||||||
print("[DEBUG] upgrade_aliases complete")
|
if _dbg == 1 { print("[DEBUG] upgrade_aliases complete") }
|
||||||
|
|
||||||
// Prefer Call/Method/New branches with name normalization; otherwise fallback to default
|
// Prefer Call/Method/New branches with name normalization; otherwise fallback to default
|
||||||
{
|
{
|
||||||
@ -479,12 +484,12 @@ flow PipelineV2 {
|
|||||||
local scan0 = Stage1JsonScannerBox.extract_name_args(ast_json, kq)
|
local scan0 = Stage1JsonScannerBox.extract_name_args(ast_json, kq)
|
||||||
if scan0 != null {
|
if scan0 != null {
|
||||||
local raw_head = scan0.get("name")
|
local raw_head = scan0.get("name")
|
||||||
print("[DEBUG] preflight raw_head=" + raw_head)
|
if _dbg == 1 { print("[DEBUG] preflight raw_head=" + raw_head) }
|
||||||
local dot = RegexFlow.find_from(raw_head, ".", 0)
|
local dot = RegexFlow.find_from(raw_head, ".", 0)
|
||||||
if dot >= 0 {
|
if dot >= 0 {
|
||||||
local head = raw_head.substring(0, dot)
|
local head = raw_head.substring(0, dot)
|
||||||
local resolved = UsingResolverBox.resolve_namespace_alias(r, head)
|
local resolved = UsingResolverBox.resolve_namespace_alias(r, head)
|
||||||
print("[DEBUG] preflight head=" + head + " resolved=" + resolved)
|
if _dbg == 1 { print("[DEBUG] preflight head=" + head + " resolved=" + resolved) }
|
||||||
if resolved == null {
|
if resolved == null {
|
||||||
print("[ERROR] Unresolved using alias: " + head)
|
print("[ERROR] Unresolved using alias: " + head)
|
||||||
return null
|
return null
|
||||||
@ -514,7 +519,7 @@ flow PipelineV2 {
|
|||||||
if kc != null {
|
if kc != null {
|
||||||
local kn = NormalizerBox.normalize_call_ints(kc)
|
local kn = NormalizerBox.normalize_call_ints(kc)
|
||||||
if kn == null {
|
if kn == null {
|
||||||
print("[DEBUG] normalize_call_ints returned null")
|
if _dbg == 1 { print("[DEBUG] normalize_call_ints returned null") }
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
local raw_name = kn.get("name")
|
local raw_name = kn.get("name")
|
||||||
|
|||||||
Reference in New Issue
Block a user