restore(lang/compiler): bring back lang/src/compiler from e917d400; add Hako index canaries and docs; implement Rust-side index operator (Array/Map get/set) with Fail‑Fast diagnostics

- restore: lang/src/compiler/** (parser/emit/builder/pipeline_v2) from e917d400
- docs: docs/development/selfhosting/index-operator-hako.md
- smokes(hako): tools/smokes/v2/profiles/quick/core/index_operator_hako.sh (opt-in)
- smokes(vm): adjust index_operator_vm.sh for semicolon gate + stable error text
- rust/parser: allow IndexExpr and assignment LHS=Index; postfix parse LBRACK chain
- rust/builder: lower arr/map index to BoxCall get/set; annotate array/map literals; Fail‑Fast for unsupported types
- CURRENT_TASK: mark Rust side done; add Hako tasks checklist

Note: files disappeared likely due to branch FF to a lineage without lang/src/compiler; no explicit delete commit found. Added anchor checks and suggested CI guard in follow-up.
This commit is contained in:
nyash-codex
2025-10-31 20:18:39 +09:00
parent 86fd03afe8
commit 5e3d9e7ae4
86 changed files with 6214 additions and 20 deletions

View File

@ -0,0 +1,70 @@
// UsingResolverBox — static, stateful resolver helpersインスタンス禁止・VM互換
// State layout (Map): {
// alias_paths: Map, alias_names: Map, alias_keys: Array,
// modules_map: Map, modules_keys: Array
// }
using "lang/src/shared/common/string_helpers.hako" as StringHelpers
using "lang/src/shared/common/box_helpers.hako" as BoxHelpers
using "lang/src/compiler/pipeline_v2/regex_flow.hako" as RegexFlow
static box UsingResolverBox {
// Lightweight state as String: holds modules_json only
state_new() { return "" }
load_usings_json(state, usings_json) { return state }
load_modules_json(state, mod_json) { return ("" + mod_json) }
resolve_path_alias(state, alias) { return null }
resolve_namespace_alias(state, alias) {
if alias == null { return null }
local s = "" + state
// Prefer unique tail match by last segment
local i = 0
local start = 0
local found = null
loop(true) {
local kpos = RegexFlow.find_from(s, "\"", start)
if kpos < 0 { break }
local kend = RegexFlow.find_from(s, "\"", kpos + 1)
if kend < 0 { break }
local key = s.substring(kpos + 1, kend)
local dot = RegexFlow.last_index_of(key, ".")
local last = key
if dot >= 0 { last = key.substring(dot + 1, key.size()) }
if last == alias {
if found == null { found = key } else { return null }
} else {
// first-letter case-insensitive match
if last.size() == alias.size() && last.size() > 0 {
local l0 = last.substring(0,1)
local a0 = alias.substring(0,1)
local restl = last.substring(1, last.size())
local resta = alias.substring(1, alias.size())
if restl == resta {
local U = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; local L = "abcdefghijklmnopqrstuvwxyz"
local idxL = L.indexOf(l0); local idxU = U.indexOf(l0)
if (idxL >= 0 && U.substring(idxL, idxL+1) == a0) || (idxU >= 0 && L.substring(idxU, idxU+1) == a0) {
if found == null { found = key } else { return null }
}
}
}
}
start = kend + 1
}
return found
}
resolve_module_path_from_alias(state, alias) { return null }
guess_namespace_from_tail(state, tail) { return me.resolve_namespace_alias(state, tail) }
upgrade_aliases(state) { return 0 }
to_context_json(state) { return "{}" }
map_to_json(m) { return "{}" }
}
static box UsingResolverBoxMain { main(args) { return 0 } }