fix(bridge): implement env.box_introspect.kind lowering + Stage0 build fixes
Phase 25.1b type system groundwork - env.* namespace support in Bridge layer
Changes:
- Bridge layer (JSON v0 → MIR):
- Add 'env' as well-known variable in MapVars::resolve()
- Implement env.box_introspect.kind(value) → ExternCall lowering
- Pattern: Method { recv: Method { recv: Var("env"), method: "box_introspect" }, method: "kind" }
- VM/extern fixes:
- Add Arc::from() conversion for env.box_introspect.kind result
- Fix MapBox API usage in extern_functions.rs logging
- Build fixes:
- Comment out missing llvm_legacy/llvm modules in src/backend/mod.rs
- Comment out missing gui_visual_node_prototype in Cargo.toml
- New files:
- lang/src/shared/common/box_type_inspector_box.hako (type introspection API)
Context:
- Enables BoxTypeInspectorBox to query runtime Box types via env.box_introspect.kind
- Required for selfhost MirBuilder type-aware lowering (multi-carrier loops, etc.)
- Part of Phase 25.1b "no fallback" selfhosting strategy
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
59
lang/src/shared/common/box_type_inspector_box.hako
Normal file
59
lang/src/shared/common/box_type_inspector_box.hako
Normal file
@ -0,0 +1,59 @@
|
||||
// box_type_inspector_box.hako — Runtime box type metadata helper
|
||||
// Responsibility:
|
||||
// - Wrap env.box_introspect.* extern calls for Stage1 code.
|
||||
// - Provide describe/kind/is_map/is_array helpers without depending on `"" + MapBox`.
|
||||
|
||||
static box BoxTypeInspectorBox {
|
||||
method _describe(value) {
|
||||
local args = new ArrayBox()
|
||||
args.push(value)
|
||||
local info = hostbridge.extern_invoke("env.box_introspect", "kind", args)
|
||||
if env.get("HAKO_BOX_INTROSPECT_TRACE") == "1" {
|
||||
if info != null {
|
||||
print("[box_introspect:hako] kind=" + ("" + info.get("kind")) +
|
||||
" is_map=" + ("" + info.get("is_map")) +
|
||||
" is_array=" + ("" + info.get("is_array")))
|
||||
} else {
|
||||
print("[box_introspect:hako] info=null")
|
||||
}
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
method kind(value) {
|
||||
local info = me._describe(value)
|
||||
if info == null { return "Unknown" }
|
||||
local k = info.get("kind")
|
||||
if k == null { return "Unknown" }
|
||||
return "" + k
|
||||
}
|
||||
|
||||
method is_map(value) {
|
||||
local info = me._describe(value)
|
||||
if info != null {
|
||||
local flag = info.get("is_map")
|
||||
if flag != null { return flag }
|
||||
}
|
||||
// Fallback: detect MapBox from repr when extern is unavailable
|
||||
local repr = "" + value
|
||||
if repr.indexOf("MapBox(") == 0 { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
method is_array(value) {
|
||||
local info = me._describe(value)
|
||||
if info != null {
|
||||
local flag = info.get("is_array")
|
||||
if flag != null { return flag }
|
||||
}
|
||||
// Fallback: detect ArrayBox from repr when extern is unavailable
|
||||
local repr = "" + value
|
||||
if repr.indexOf("ArrayBox(") == 0 { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
method describe(value) {
|
||||
// Expose full Map so callers can inspect additional fields (type_name/type_id/etc.)
|
||||
return me._describe(value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user