🎯 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 完了!🎊 次: ドキュメント更新
16 lines
449 B
Plaintext
16 lines
449 B
Plaintext
// Phase 21.7: Methodization test
|
|
// Tests Global("BoxName.method/arity") → Method{receiver=singleton} conversion
|
|
|
|
static box Calculator {
|
|
add(a, b) {
|
|
return a + b
|
|
}
|
|
|
|
main() {
|
|
// This will be called as Global("Calculator.add/2") by default
|
|
// With HAKO_MIR_BUILDER_METHODIZE=1, it becomes Method{Calculator.add, recv=singleton}
|
|
print("Result: " + ("" + Calculator.add(10, 20)))
|
|
return 0
|
|
}
|
|
}
|