diff --git a/lang/src/compiler/entry/compiler_stageb.hako b/lang/src/compiler/entry/compiler_stageb.hako index 14762ce7..7bcc2310 100644 --- a/lang/src/compiler/entry/compiler_stageb.hako +++ b/lang/src/compiler/entry/compiler_stageb.hako @@ -269,6 +269,14 @@ static box StageBBodyExtractorBox { } if k3 >= 0 { + // Phase 25.1c: Guaranteed trace before balanced scan + { + local trc = env.get("HAKO_STAGEB_TRACE") + if trc != null && ("" + trc) == "1" { + print("[stageb/body] Before balanced scan: k3=" + ("" + k3) + " len=" + ("" + s.length())) + } + } + // Balanced scan for matching '}' local depth = 0 local i = k3 @@ -277,26 +285,68 @@ static box StageBBodyExtractorBox { local esc = 0 local start_pos = -1 local end_pos = -1 + local iter_count = 0 // Phase 25.1c: iteration counter loop(i < n) { + // Phase 25.1c: EVERY iteration trace (to detect i stall) + iter_count = iter_count + 1 + { + local trc = env.get("HAKO_STAGEB_TRACE") + if trc != null && ("" + trc) == "1" { + // Print EVERY iteration to catch i-stall immediately + print("[stageb/body/iter] #" + ("" + iter_count) + " i=" + ("" + i) + " depth=" + ("" + depth)) + } + } + // Phase 25.1c: Trace before substring call + { + local trc = env.get("HAKO_STAGEB_TRACE") + if trc != null && ("" + trc) == "1" { + print("[stageb/body/substr-pre] #" + ("" + iter_count) + " calling s.substring(" + ("" + i) + ", " + ("" + (i+1)) + ")") + } + } local ch = s.substring(i, i + 1) + // Phase 25.1c: Trace after substring call + { + local trc = env.get("HAKO_STAGEB_TRACE") + if trc != null && ("" + trc) == "1" { + print("[stageb/body/substr-post] #" + ("" + iter_count) + " got ch") + } + } + // Phase 25.1c: Trace each branch if in_str == 1 { + print("[stageb/body/branch] in_str=1") if esc == 1 { esc = 0 i = i + 1 continue } if ch == "\\" { esc = 1 i = i + 1 continue } if ch == "\"" { in_str = 0 i = i + 1 continue } i = i + 1 continue } - if ch == "\"" { in_str = 1 i = i + 1 continue } - if ch == "{" { depth = depth + 1 i = i + 1 continue } + if ch == "\"" { + print("[stageb/body/branch] quote") + in_str = 1 i = i + 1 continue + } + if ch == "{" { + print("[stageb/body/branch] open-brace depth=" + ("" + depth) + "->+1 i=" + ("" + i) + "->+1") + depth = depth + 1 i = i + 1 continue + } if ch == "}" { + print("[stageb/body/branch] close-brace depth=" + ("" + depth) + "->-1 i=" + ("" + i) + "->+1") depth = depth - 1 i = i + 1 if depth == 0 { break } continue } + print("[stageb/body/branch] other i=" + ("" + i) + "->+1") i = i + 1 } + // Phase 25.1c: Guaranteed trace after balanced scan + { + local trc = env.get("HAKO_STAGEB_TRACE") + if trc != null && ("" + trc) == "1" { + print("[stageb/body] After balanced scan: depth=" + ("" + depth) + " i=" + ("" + i) + " iters=" + ("" + iter_count)) + } + } + { local dbg = env.get("HAKO_STAGEB_DEBUG") if dbg != null && ("" + dbg) == "1" {