feat(stageb): implement UsingResolverBox foundation (partial)

Implemented:
- UsingResolverBox full implementation in using_resolver_box.hako
  - state_new(): Empty state creation
  - load_modules_json(): Load modules JSON from nyash.toml
  - resolve_path_alias(): Resolve paths from aliases
  - resolve_namespace_alias(): Tail segment matching with case-insensitive support
  - to_context_json(): Generate context JSON for ParserBox
- Added sh_core entry to nyash.toml modules section
  - Maps to lang/src/shared/common/string_helpers.hako
  - Fixes "using not found: 'sh_core'" errors
- Cleaned up compiler_stageb.hako
  - Removed problematic using statements
  - Added documentation

Known Issue (to be fixed next):
- Body extraction bug in compiler_stageb.hako:51-197
  - Multiline source extraction fails for "static box Main { main() {...} }"
  - Results in empty Program JSON body
  - Causes Stage-B emit pipeline to fall back to jsonfrag (ratio=207900%)
  - This is the root cause blocking selfhost builder path

Impact:
-  sh_core resolution errors fixed
-  UsingResolverBox infrastructure complete
-  Stage-B emit pipeline not restored (body extraction bug)
-  Selfhost builder path still blocked

Next Priority: Fix body extraction bug to restore Stage-B pipeline

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-13 18:11:25 +09:00
parent 376857a81f
commit 1ac0c6b880
6 changed files with 184 additions and 12 deletions

View File

@ -9,6 +9,31 @@ static box AotPrepHelpers {
return me._linear_expr(json, vid, 0)
}
// Public: fold integer binops on constants (returns string i64 or "")
evaluate_binop_constant(operation, lhs_val, rhs_val) {
if operation == "" { return "" }
local li = StringHelpers.to_i64(lhs_val)
local ri = StringHelpers.to_i64(rhs_val)
if li == null || ri == null { return "" }
local res = null
if operation == "add" || operation == "+" {
res = li + ri
} else if operation == "sub" || operation == "-" {
res = li - ri
} else if operation == "mul" || operation == "*" {
res = li * ri
} else if operation == "sdiv" || operation == "div" || operation == "/" {
if ri == 0 { return "" }
res = li / ri
} else if operation == "srem" || operation == "rem" || operation == "%" {
if ri == 0 { return "" }
res = li % ri
} else {
return ""
}
return StringHelpers.int_to_str(res)
}
// Public: Is `vid` defined by a const (following copy chains)
is_const_vid(json, vid) {
if vid == "" { return false }
@ -111,4 +136,3 @@ static box AotPrepHelpers {
return -1
}
}

View File

@ -1,7 +1,7 @@
// AotPrepLoopHoistBox — Hoist loop-local consts (binop/div/rem/compare) to block head
using selfhost.shared.json.utils.json_frag as JsonFragBox
using selfhost.shared.common.string_helpers as StringHelpers
using selfhost.llvm.ir.aot_prep as AotPrepBox // for _evaluate_binop_constant
using selfhost.llvm.ir.aot_prep.helpers.common as AotPrepHelpers // for evaluate_binop_constant
static box AotPrepLoopHoistBox {
run(json) {
@ -75,7 +75,7 @@ static box AotPrepLoopHoistBox {
local lhs_val = const_vals.contains(lhs) ? const_vals[lhs] : ""
local rhs_val = const_vals.contains(rhs) ? const_vals[rhs] : ""
if lhs_val == "" || rhs_val == "" { continue }
local computed = AotPrepBox._evaluate_binop_constant(operation, lhs_val, rhs_val)
local computed = AotPrepHelpers.evaluate_binop_constant(operation, lhs_val, rhs_val)
if computed == "" { continue }
const_defs[dst] = inst
const_vals[dst] = computed