Files
hakorune/lang/src/mir/builder/README.md
nyash-codex 7ca7f646de Phase 25.1b: Step2完了(FuncBodyBasicLowerBox導入)
Step2実装内容:
- FuncBodyBasicLowerBox導入(defs専用下請けモジュール)
- _try_lower_local_if_return実装(Local+単純if)
- _inline_local_ints実装(軽い正規化)
- minimal lowers統合(Return/BinOp/IfCompare/MethodArray系)

Fail-Fast体制確立:
- MirBuilderBox: defs_onlyでも必ずタグ出力
- [builder/selfhost-first:unsupported:defs_only]
- [builder/selfhost-first:unsupported:no_match]

Phase構造整備:
- Phase 25.1b README新設(Step0-3計画)
- Phase 25.2b README新設(次期計画)
- UsingResolverBox追加(using system対応準備)

スモークテスト:
- stage1_launcher_program_to_mir_canary_vm.sh追加

Next: Step3 LoopForm対応

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-15 22:32:13 +09:00

35 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# MirBuilderBox — Program(JSON v0) → MIR(JSON v0)
Responsibility
- Convert StageB Program(JSON v0) into MIR(JSON v0) for VM/LLVM lines.
- Keep the boundary/contract stable and FailFast; no silent fallback to stub MIR.
Interface (stable)
- `emit_from_program_json_v0(program_json: String, opts: Map|Null) -> String|Null`
- Returns canonical MIR(JSON v0) on success; returns null and prints a tagged diagnostic on failure.
Tags (FailFast, stable)
- `[mirbuilder/input/null]` — input is null
- `[mirbuilder/input/invalid]` — header missing (version/kind)
- `[mirbuilder/internal/unsupported] ...` — Program(JSON) shape not yet supported by internal lowers
- `[builder/selfhost-first:unsupported:defs_only]` — only defs を lowering できる状態main なし)のため中止
- `[builder/selfhost-first:unsupported:no_match]` — internal lowers / defs のどちらにもマッチせず中止
- `[builder/funcs:fail:no-main]` — inject_funcs が main を含まない MIR に defs を差し込もうとしたため拒否(`HAKO_MIR_BUILDER_REQUIRE_MAIN=1` 時)
- `[mirbuilder/delegate]` — delegate path selectedRunner/extern provider 経由)
- `[mirbuilder/delegate/missing]` — delegate/provider not wired yet
Toggles
- `HAKO_MIR_BUILDER_INTERNAL=0/1` — internal lowers gate既定=1
- `HAKO_MIR_BUILDER_REGISTRY=0/1` — pattern registry gate既定=1
- `HAKO_MIR_BUILDER_DELEGATE=1` — use Runner/extern provider (`env.mirbuilder.emit`) 経由で Program→MIR
- `HAKO_MIR_BUILDER_FUNCS=1` — enable defs lowering via `FuncLoweringBox.lower_func_defs`
- `HAKO_MIR_BUILDER_METHODIZE=1` — enable call→mir_call(Method) rewrite after MIR 生成
- `HAKO_MIR_BUILDER_JSONFRAG_NORMALIZE=1` — apply JsonFrag normalizer to selfhost/provider output
- `HAKO_MIR_BUILDER_LOOP_FORCE_JSONFRAG=1` — devonly: minimal loop MIR を強制生成(テスト用)
- `HAKO_MIR_BUILDER_REQUIRE_MAIN=1` — inject_funcs で `"name":"main"` を持たない MIR に defs を追加するのを禁止(既定=0
Notes
- BoxFirst policy: define the interface and tags first, then evolve implementation behind the same contract.
- Large payloads: implementation is currently string/JsonFragbased; later phases may stream or segment JSON, but I/F は維持する。
- Phase 25.1b では `FuncLoweringBox` との連携を拡張し、「main + defs」構造を前提とした multifunction MIR の土台を整えるdefsonly モジュールは FailFast