🎁 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:
@ -748,8 +748,8 @@ impl NyashInterpreter {
|
||||
|
||||
drop(box_declarations); // ロック早期解放
|
||||
|
||||
// 4. constructorの場合の特別処理
|
||||
if method == "constructor" {
|
||||
// 4. constructorまたはinitまたはpackの場合の特別処理
|
||||
if method == "constructor" || method == "init" || method == "pack" || method == parent {
|
||||
return self.execute_from_parent_constructor(parent, &parent_box_decl, current_instance_val.clone_box(), arguments);
|
||||
}
|
||||
|
||||
@ -820,16 +820,17 @@ impl NyashInterpreter {
|
||||
current_instance: Box<dyn NyashBox>, arguments: &[ASTNode])
|
||||
-> Result<Box<dyn NyashBox>, RuntimeError> {
|
||||
|
||||
// 1. 親クラスのコンストラクタを取得(デフォルトコンストラクタまたは指定されたもの)
|
||||
let constructor_name = if arguments.is_empty() {
|
||||
"constructor"
|
||||
} else {
|
||||
"constructor" // TODO: 将来的に名前付きコンストラクタ対応
|
||||
};
|
||||
// 1. 親クラスのコンストラクタを取得(引数の数でキーを作成)
|
||||
// "pack/引数数"、"init/引数数"、"Box名/引数数" の順で試す
|
||||
let pack_key = format!("pack/{}", arguments.len());
|
||||
let init_key = format!("init/{}", arguments.len());
|
||||
let box_name_key = format!("{}/{}", parent, arguments.len());
|
||||
|
||||
let parent_constructor = parent_box_decl.constructors.get(constructor_name)
|
||||
let parent_constructor = parent_box_decl.constructors.get(&pack_key)
|
||||
.or_else(|| parent_box_decl.constructors.get(&init_key))
|
||||
.or_else(|| parent_box_decl.constructors.get(&box_name_key))
|
||||
.ok_or(RuntimeError::InvalidOperation {
|
||||
message: format!("Constructor '{}' not found in parent class '{}'", constructor_name, parent),
|
||||
message: format!("No constructor found for parent class '{}' with {} arguments", parent, arguments.len()),
|
||||
})?
|
||||
.clone();
|
||||
|
||||
@ -844,8 +845,8 @@ impl NyashInterpreter {
|
||||
// パラメータ数チェック
|
||||
if arg_values.len() != params.len() {
|
||||
return Err(RuntimeError::InvalidOperation {
|
||||
message: format!("Parent constructor {}.{} expects {} arguments, got {}",
|
||||
parent, constructor_name, params.len(), arg_values.len()),
|
||||
message: format!("Parent constructor {} expects {} arguments, got {}",
|
||||
parent, params.len(), arg_values.len()),
|
||||
});
|
||||
}
|
||||
|
||||
@ -881,7 +882,7 @@ impl NyashInterpreter {
|
||||
Ok(current_instance)
|
||||
} else {
|
||||
Err(RuntimeError::InvalidOperation {
|
||||
message: format!("Parent constructor '{}' is not a valid function declaration", constructor_name),
|
||||
message: format!("Parent constructor is not a valid function declaration"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user