feat(parserbox): add shallow recursion guard to parse_program2 for Stage-B
This commit is contained in:
@ -235,6 +235,18 @@ box ParserBox {
|
||||
|
||||
// === Top-level program parser ===
|
||||
parse_program2(src) {
|
||||
// Shallow recursion guard for Stage‑B / selfhost callers:
|
||||
// prevent accidental self-recursion in ParserBox.parse_program2.
|
||||
{
|
||||
local depth = env.get("HAKO_STAGEB_PARSER_DEPTH")
|
||||
if depth != null && ("" + depth) != "0" {
|
||||
print("[stageb/recursion] ParserBox.parse_program2 recursion detected")
|
||||
// Fail-fast: return an empty Program(JSON) so caller can detect failure.
|
||||
return "{\"version\":0,\"kind\":\"Program\",\"body\":[]}"
|
||||
}
|
||||
env.set("HAKO_STAGEB_PARSER_DEPTH", "1")
|
||||
}
|
||||
|
||||
local trace = me.trace_enabled()
|
||||
|
||||
// Inline skip_ws to avoid VM bug: method-with-loop called from within loop
|
||||
@ -355,6 +367,7 @@ box ParserBox {
|
||||
if trace == 1 {
|
||||
print("[parser/trace:program2] done pos=" + ("" + i) + " len=" + ("" + n))
|
||||
}
|
||||
env.set("HAKO_STAGEB_PARSER_DEPTH", "0")
|
||||
return "{\"version\":0,\"kind\":\"Program\",\"body\":" + body + "}"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user