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,35 @@
// MirBuilderBox — minimal Ny→MIR(JSON v0) lowering entry (dev)
// Phase 15.7: kept optional; pipeline.v2 uses Emit flow directly.
using "lang/src/compiler/pipeline_v2/stage1_extract_flow.hako" as Stage1ExtractFlow
using "lang/src/compiler/pipeline_v2/emit_return_box.hako" as EmitReturnBox
using "lang/src/compiler/pipeline_v2/emit_binop_box.hako" as EmitBinopBox
using "lang/src/compiler/pipeline_v2/emit_compare_box.hako" as EmitCompareBox
using "lang/src/shared/common/box_helpers.hako" as BoxHelpers
box MirBuilderBox {
// Placeholder for optimizer toggle
optimize_flag
birth() { me.optimize_flag = 0 return 0 }
set_optimize(v) { if v == null { v = 0 } me.optimize_flag = v return 0 }
// Accept Stage1 AST JSON and emit minimal MIR(JSON v0)
build(ast_json) {
if ast_json == null { return EmitReturnBox.emit_return_int2(0, 0) }
// If(cond=Compare) → CFG (branch/jump/ret)
if call("String.indexOf/2", ast_json, "\"type\":\"If\"") >= 0 {
local ic = Stage1ExtractFlow.extract_if_compare(ast_json)
if ic != null { return EmitCompareBox.emit_compare_cfg3(BoxHelpers.map_get(ic, "lhs"), BoxHelpers.map_get(ic, "rhs"), BoxHelpers.map_get(ic, "cmp"), 0, 0) }
}
// Return(Compare)
local c = Stage1ExtractFlow.extract_return_compare(ast_json)
if c != null { return EmitCompareBox.emit_compare_cfg3(BoxHelpers.map_get(c, "lhs"), BoxHelpers.map_get(c, "rhs"), BoxHelpers.map_get(c, "cmp"), 0, 0) }
// Return(BinOp)
local b = Stage1ExtractFlow.extract_return_binop(ast_json)
if b != null { return EmitBinopBox.emit_binop2(BoxHelpers.map_get(b, "lhs"), BoxHelpers.map_get(b, "rhs"), BoxHelpers.map_get(b, "kind"), 0) }
// Fallback: Return(Int)
local v = Stage1ExtractFlow.extract_return_int(ast_json)
return EmitReturnBox.emit_return_int2(v, 0)
}
}
static box MirBuilderStub { main(args) { return 0 } }