feat(mir): Phase 21.7 Step 3 - Methodization実装完了

🎯 Global("BoxName.method/arity") → Method{receiver=singleton} 変換

実装内容:
1. builder.rs: static_box_singletons フィールド追加
   - BoxName → ValueId マッピングでシングルトン管理
2. unified_emitter.rs: methodization ロジック実装
   - HAKO_MIR_BUILDER_METHODIZE=1 で有効化
   - decode_static_method() でstatic box method判定
   - singleton instance を NewBox で生成(キャッシュ済み)
   - Callee::Global → Callee::Method 変換

動作確認:
- デフォルト(OFF): call_global Calculator.add/2 (既存挙動維持)
- トグル(ON): new Calculator → call %singleton.add (methodization)
- RC=0 両モード動作確認済み

テスト:
- apps/tests/phase217_methodize_test.hako 追加
- [methodize] Global(...) → Method{...} トレース出力

環境変数:
- HAKO_MIR_BUILDER_METHODIZE=1: methodization 有効化
- NYASH_METHODIZE_TRACE=1: 変換ログ出力

Phase 21.7 Step 3 完了!🎊
次: ドキュメント更新
This commit is contained in:
nyash-codex
2025-11-22 00:00:51 +09:00
parent a13f14cea0
commit b5cd05c27a
3 changed files with 73 additions and 0 deletions

View File

@ -221,6 +221,12 @@ pub struct MirBuilder {
/// - Some(true): App mode (static box Main.main is entry)
/// - Some(false): Script/Test mode (top-level Program runs sequentially)
pub(super) root_is_app_mode: Option<bool>,
/// 🎯 Phase 21.7: Static box singleton instances for methodization
/// Maps BoxName → ValueId of singleton instance (created on demand)
/// Used when HAKO_MIR_BUILDER_METHODIZE=1 to convert Global("BoxName.method/arity")
/// to Method{receiver=singleton} calls
pub(super) static_box_singletons: HashMap<String, ValueId>,
}
impl MirBuilder {
@ -282,6 +288,7 @@ impl MirBuilder {
in_unified_boxcall_fallback: false,
recursion_depth: 0,
root_is_app_mode: None,
static_box_singletons: HashMap::new(), // Phase 21.7: methodization support
}
}