Files
hakorune/docs/development/roadmap/phases/phase-25.2b/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

38 lines
2.7 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

# Phase 25.2b — Lambda / FunctionBox Semantics (Planning)
Status: planning-only将来フェーズ用のメモ実装はまだ行わない
## ゴール
- Phase 25.1b で selfhost builder の Program→MIR パリティが整ったあとに、Hakoru­ne 言語としてのラムダ式(`fn(x, y) { ... }` / `fn(x) expr`)の意味論を Rust VM / MIR / FunctionBox まで一貫させる。
- MirBuilder / selfhost コードから暫定的に排除している `fn` ベースの helper`norm_if` など)を、正式なクロージャ意味論の上に戻せるようにする。
- Stage1/Stage0 の責務分離を崩さずに、「lambda を使う Hako コード」が hv1 VM / AOT でも安全に実行できる状態を作る。
## 現状Phase 25.1b 前提)
- 構文AST:
- `docs/reference/language/LANGUAGE_REFERENCE_2025.md``fn(x, y) { ... }` / `fn(x) expr` のラムダ構文が記載済み。
- Stage3 パーサは `fn` キーワードを認識し、AST 上では Lambda ノードを持っている(`exprs_lambda.rs` 前提)。
- MIR:
- `src/mir/instruction.rs``MirInstruction::NewClosure { dst, params, body, captures, me }` が定義済み。
- `src/mir/builder/exprs_lambda.rs` は AST ラムダを `NewClosure` に降ろし、`captures` / `me` 情報を構築する実装がある。
- 実行VM:
- hv1 VM`src/backend/mir_interpreter`)は `NewClosure` / `Callee::Closure` をまだ実装していないcatch-all で InvalidInstruction
- `FunctionBox` / `ClosureEnv``src/boxes/function_box.rs` に存在し、手動で FunctionBox を作るテスト経路では動いている。
- selfhost 側:
- Phase 25.1a/b では selfhost builder から `fn` を排除し、lambda なしでも Stage1 CLI を扱える Program→MIR ルートに集中する。
## 25.2b のスコープ(案)
- Rust VM:
- `MirInstruction::NewClosure` を実装し、`FunctionBox` + `ClosureEnv` を構築する。
- `execute_callee_call``Callee::Closure` / `Callee::Value` の処理を追加し、第一級関数呼び出しをサポートする。
- Hakorune selfhost:
- selfhost builder (`MirBuilderBox` / `MirBuilderMinBox`) の helper の一部を lambda 版に戻し、`NewClosure` 経路が実際に踏まれるようにする(最初は dev トグル付きでもよい)。
- Stage1 コードでの lambda 利用ポリシー(どの層で許可するか)を docs に明記する。
- テスト:
- AST→MIR→VM で λ を含むケース単純関数、captures、`me` 利用など)をカバーする canary を追加する。
このフェーズは「selfhost builder パリティ25.1b)」完了後に着手する前提であり、本ドキュメントは計画メモのみとする。***