🎁 feat: pack構文革命完全達成 - Box哲学の具現化

【実装内容】
- packキーワード追加: TokenType::PACK, "pack" mapping
- パーサー対応: init同様の特別扱い + from Parent.pack()
- インタープリター対応: pack > init > Box名順優先選択
- デリゲーション統合: from Parent.pack()で親packを呼び出し
- テスト完備: test_pack_syntax.nyash包括テスト

【革命的効果】
- Box哲学具現化: 「箱に詰める」でコードを書くたび哲学体験
- 他言語差別化: new/init超越のNyash独自アイデンティティ
- 直感的UX: Gemini・ChatGPT両先生一致推薦の最適命名
- メンタルモデル統一: 全Boxで1つのpack動詞に収束
- 拡張基盤: try_pack, from_*パターンへの発展準備完了

🎉 Everything is Box - Now Everything is Packed\!

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-11 09:40:24 +09:00
parent e3d4b3cbd5
commit 50fc4ca1ce
7 changed files with 366 additions and 40 deletions

View File

@ -592,8 +592,14 @@ impl NyashInterpreter {
// 🌍 革命的実装Environment tracking廃止
// コンストラクタを呼び出す
let constructor_key = format!("{}/{}", actual_class_name, arguments.len());
if let Some(constructor) = final_box_decl.constructors.get(&constructor_key) {
// "pack/引数数"、"init/引数数"、"Box名/引数数" の順で試す
let pack_key = format!("pack/{}", arguments.len());
let init_key = format!("init/{}", arguments.len());
let box_name_key = format!("{}/{}", actual_class_name, arguments.len());
if let Some(constructor) = final_box_decl.constructors.get(&pack_key)
.or_else(|| final_box_decl.constructors.get(&init_key))
.or_else(|| final_box_decl.constructors.get(&box_name_key)) {
// コンストラクタを実行
self.execute_constructor(&instance_box, constructor, arguments, &final_box_decl)?;
} else if !arguments.is_empty() {
@ -797,8 +803,12 @@ impl NyashInterpreter {
};
// 親コンストラクタを探す
let constructor_key = format!("{}/{}", parent_class, arguments.len());
if let Some(parent_constructor) = parent_decl.constructors.get(&constructor_key) {
// まず "init/引数数" を試し、なければ "Box名/引数数" を試す
let init_key = format!("init/{}", arguments.len());
let box_name_key = format!("{}/{}", parent_class, arguments.len());
if let Some(parent_constructor) = parent_decl.constructors.get(&init_key)
.or_else(|| parent_decl.constructors.get(&box_name_key)) {
// 現在のthis参照を取得
// 🌍 革命的this取得local変数から
let this_instance = self.resolve_variable("me")