feat(plugin): Fix plugin BoxRef return and Box argument support

- Fixed deadlock in FileBox plugin copyFrom implementation (single lock)
- Added TLV Handle (tag=8) parsing in calls.rs for returned BoxRefs
- Improved plugin loader with config path consistency and detailed logging
- Fixed loader routing for proper Handle type_id/fini_method_id resolution
- Added detailed logging for TLV encoding/decoding in plugin_loader_v2

Test docs/examples/plugin_boxref_return.nyash now works correctly:
- cloneSelf() returns FileBox Handle properly
- copyFrom(Box) accepts plugin Box arguments
- Both FileBox instances close and fini correctly

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm
2025-08-21 00:41:26 +09:00
parent af32896574
commit cc2a820af7
274 changed files with 7244 additions and 4608 deletions

View File

@ -1,51 +0,0 @@
Nyashプログラミング言語のコンストラクタ設計について深い相談です。
【Nyashの現在の設計哲学】
Nyashは既に「コンストラクタの明示的呼び出し」を採用しています。これは以下の理由によるものです
- 明示性重視:プログラマーが何が起きているかを隠さない
- 初学者フレンドリー:実行順序が直感的
- Everything is Box哲学隠れた魔法的な動作を避ける
【他言語の問題例】
```cpp
// C++:複雑で読みにくい
class Cat : public Animal {
Toy catToy; // 1. 隠れたメンバー初期化
Cat(string name) : Animal(name) { // 2. : Animal(name) が直感的でない
// 3. 最後に自分の処理
}
};
```
【現在のNyash vs 新提案】
```nyash
// 現在の書き方
box MeshNode : P2PBox {
constructor(nodeId, world) {
super P2PBox(nodeId, world) // 特別なキーワード
me.routing = RoutingTable()
}
}
// 新提案:完全統一
box MeshNode : P2PBox {
constructor(nodeId, world) {
from P2PBox.constructor(nodeId, world) // from統一
me.routing = RoutingTable()
}
}
```
【完全統一のメリット】
- from P2PBox.method() と完全に一貫している
- 「どの親の何を呼んでいるか」が超明確
- 多重デリゲーションでも from Logger.constructor() で区別可能
【深く考えてほしい点】
1. Nyashの明示的コンストラクタ呼び出し設計をどう評価しますか
2. from P2PBox.constructor() の完全統一案をどう思いますか?
3. 他言語Java, Python, C#等と比較したNyashの優位性は
4. 初学者にとって最も理解しやすい設計は?
5. 言語の美しさ・一貫性の観点からの評価は?
プログラミング言語設計の専門的視点から、深く分析してください。

View File

@ -1,106 +0,0 @@
Nyashプログラミング言語のオーバーライド設計について深い相談です。
【現在発見された実装問題】
現在のNyashでは HashMap::insert により「暗黙のオーバーライド」が発生している:
```rust
// instance.rs - add_method関数
pub fn add_method(&mut self, method_name: String, method_ast: ASTNode) {
let mut new_methods = (*self.methods).clone();
new_methods.insert(method_name, method_ast); // ← 同名で上書き!
self.methods = Arc::new(new_methods);
}
```
これにより以下が可能になってしまっている:
```nyash
box Node {
send(msg) { // 最初の定義
print("Version 1")
}
send(msg) { // 暗黙に上書きされる
print("Version 2") // ← こちらだけが残る
}
}
```
【Nyashの設計哲学との矛盾】
- **明示性重視**: 何が起きているかを隠さない
- **Everything is Box**: 統一された世界観
- **from デリゲーション**: `from Parent.method()` の明示的呼び出し
- **初学者フレンドリー**: 複雑な概念を分かりやすく表現
【提案する修正方針】
**1. 暗黙のオーバーライドを完全禁止**
```nyash
box Node {
send(msg) {
print("Version 1")
}
send(msg) { // ← コンパイルエラーにする
print("Version 2")
}
}
// Error: Method 'send' is already defined. Use 'override' keyword if intentional.
```
**2. コンストラクタのオーバーロード禁止**
```nyash
box Node {
constructor(id) {
me.id = id
}
constructor(id, name) { // ← エラーにする
me.id = id
me.name = name
}
}
// Error: Constructor overloading is not allowed. Use explicit initialization.
```
**3. デリゲーションでの明示的override**
```nyash
box MeshNode : P2PBox {
// 明示的にオーバーライドする意図を示す
override send(intent, data, target) {
me.routing.log(target)
from P2PBox.send(intent, data, target) // 親の実装も呼べる
}
// 新しいメソッドoverrideなし
sendWithRetry(intent, data, target) {
// 新機能
}
}
```
**4. エラーメッセージの改善**
- 重複定義時: "Method 'send' already exists. Use 'override' if you want to replace parent method."
- override不正使用時: "Method 'newMethod' does not exist in parent. Remove 'override' keyword."
【深く考えてほしい点】
**1. 哲学的整合性**
- この方針はNyashの「明示性重視」「Everything is Box」哲学と整合しますか
- `from Parent.method()` デリゲーション設計との相性は?
**2. 学習コスト vs 安全性**
- `override` キーワード追加による学習コストは妥当ですか?
- 暗黙のオーバーライド禁止により、どの程度安全性が向上しますか?
**3. デリゲーションとの関係**
- デリゲーション先メソッドを `override` するのは自然ですか?
- 多重デリゲーション時の `override` はどう扱うべきですか?
**4. 実装上の課題**
- コンパイル時の重複チェック実装の複雑度は?
- 既存コードへの影響と移行戦略は?
**5. 他言語との比較優位性**
- Java/C#の `@Override` や TypeScript の `override` との違いは?
- Nyashならではの独自価値は何ですか
プログラミング言語設計の専門的視点から、この方針がNyashの目指す「明示的で安全、かつ初学者フレンドリーな言語」に最適かどうか深く分析してください。

View File

@ -1,77 +0,0 @@
Nyashプログラミング言語のBox型アーキテクチャ設計について深い技術相談です。
【現在の状況】
- Rust実装のプログラミング言語Nyash開発中
- "Everything is Box"哲学全データがBoxオブジェクト
- 現在16種類のBox型実装済みStringBox, IntegerBox, P2PBox等
- Arc<Mutex>統一パターンでスレッドセーフ性確保
【現在のアーキテクチャ問題】
現在、全Box型をtype aliasで統一しているが、実装で型エラー地獄が発生
```rust
// 現在の問題のある設計
type StringBox = Arc<Mutex<StringBoxData>>;
type IntegerBox = Arc<Mutex<IntegerBoxData>>;
type P2PBox = Arc<Mutex<P2PBoxData>>;
// 問題型エイリアス複雑化、trait object Debug実装困難
// 結果Copilot実装で型エラー多発、開発効率低下
```
【検討中のシンプル設計】
newtype patternによるシンプル化
```rust
// 案1: newtype pattern
struct StringBox(Arc<Mutex<StringBoxData>>);
struct IntegerBox(Arc<Mutex<IntegerBoxData>>);
struct P2PBox(Arc<Mutex<P2PBoxData>>);
// 案2: 生構造体必要時のみArc化
struct StringBox { data: String }
struct IntegerBox { value: i64 }
// 共有が必要な時だけArc::new()で包む
```
【技術的検討ポイント】
1. **型安全性とシンプルさのバランス**
- type alias vs newtype vs 生構造体
- コンパイル時エラー検出 vs 実装しやすさ
2. **スレッドセーフ性の要件**
- 全Box型で並行処理が必要か
- StringBox等の基本型にもMutex必要
- 必要な時だけArc<Mutex>化する方が良い?
3. **拡張性・保守性**
- 新Box型追加時の実装コスト
- エラーメッセージの分かりやすさ
- 他開発者AI含むの理解しやすさ
4. **パフォーマンス**
- Arc<Mutex>のオーバーヘッド
- ゼロコスト抽象化の実現可能性
- メモリ使用量の最適化
5. **現実的な実装戦略**
- 段階的移行 vs 一括変更
- 既存コードとの互換性
- 開発スピード重視 vs 理想設計重視
【具体的相談事項】
1. type alias vs newtype vs 生構造体、どの設計が最適?
2. 全Box型に一律Arc<Mutex>は過剰?必要な箇所のみの方が良い?
3. Rust専門家から見て推奨されるBox型統一アーキテクチャは
4. プログラミング言語実装において、型システムのベストプラクティスは?
5. 実装効率と設計美学のバランスをどう取るべき?
【制約条件】
- Rust実装必須
- Everything is Box哲学維持
- スレッドセーフ性確保
- 16種類+今後追加予定のBox型すべてで統一
- 実装・保守の現実性重視
プログラミング言語設計・Rust専門家の視点から、実装可能で美しく、長期保守に適したアーキテクチャ設計を提案してください。

View File

@ -1,100 +0,0 @@
Nyash Programming Language - Weak Reference Architecture Critical Decision
I need expert advice on a fundamental architectural decision for weak reference implementation. This is a foundational component that will impact native compilation plans.
【Current Situation】
Copilot has completed 99% of weak reference implementation with excellent quality. Only the final invalidation mechanism remains.
【Two Competing Approaches】
## Approach A: Copilot's "Proper" Global Tracking
```rust
pub struct SharedState {
// Existing fields...
pub instance_registry: Arc<Mutex<Vec<Weak<Mutex<InstanceBox>>>>>,
}
fn invalidate_weak_references(&mut self, target_info: &str) {
// Linear search through ALL instances in the system
for weak_instance in &self.instance_registry {
if let Some(instance) = weak_instance.upgrade() {
instance.lock().unwrap().invalidate_weak_references_to(target_info);
}
}
}
```
**Pros**: Architecturally correct, immediate invalidation, theoretically perfect
**Cons**: O(n) linear search, complex state management, heavyweight
## Approach B: Gemini's "On-Access" Lazy Invalidation
```rust
pub struct Interpreter {
pub invalidated_ids: Arc<Mutex<HashSet<u64>>>, // Simple ID set
}
fn trigger_weak_reference_invalidation(&mut self, target_info: &str) {
if let Ok(id) = target_info.parse::<u64>() {
self.invalidated_ids.lock().unwrap().insert(id); // O(1) operation
}
}
fn get_weak_field(&self, name: &str) -> Option<...> {
if invalidated_ids.contains(&id) { // O(1) lookup
return None; // Auto-nil on access
}
}
```
**Pros**: O(1) operations, minimal changes, leverages 99% existing implementation
**Cons**: Delayed invalidation (only on access), not "immediate"
【Critical Considerations】
## 1. Native Compilation Impact
This weak reference system will be compiled to native code. Performance characteristics matter significantly:
- Approach A: O(n) linear search in native code = potential bottleneck
- Approach B: O(1) HashSet operations = predictable performance
## 2. Foundation Quality vs Pragmatism
- This is foundational memory safety infrastructure
- Must balance correctness with performance
- Real-world usage patterns matter more than theoretical perfection
## 3. Scaling Characteristics
In applications with 1000+ objects:
- Approach A: 1000+ instance traversal on each drop
- Approach B: Single hash table insertion/lookup
## 4. Maintenance Complexity
- Approach A: Complex global state, threading issues, lifecycle management
- Approach B: Simple addition to existing interpreter state
【Specific Technical Questions】
1. **Performance Reality Check**: In a native-compiled language, is O(n) weak reference invalidation acceptable for real applications?
2. **Lazy vs Eager Trade-off**: Is "on-access invalidation" a viable pattern for systems programming? What are the hidden costs?
3. **Native Compilation Compatibility**: Which approach translates better to efficient native code generation?
4. **Memory Safety Guarantee**: Do both approaches provide equivalent memory safety guarantees?
5. **Industry Best Practices**: How do modern systems languages (Rust, Swift, etc.) handle this problem?
【Nyash Context】
- Everything is Box philosophy (unified object model)
- Target: P2P networking applications (performance-sensitive)
- Native compilation planned (MIR → LLVM/Cranelift)
- Developer experience priority (simplicity over theoretical perfection)
【Request】
Please provide expert analysis focusing on:
1. Real-world performance implications for native compilation
2. Hidden complexity costs of each approach
3. Recommendation for foundational language infrastructure
4. Risk assessment for future scaling
This decision affects the entire language's memory management foundation. I need the most technically sound recommendation that balances correctness, performance, and maintainability.
Thank you for your expertise!

View File

@ -1,64 +0,0 @@
Nyashプログラミング言語の関数オーバーロード設計について深い技術的相談です。
【Nyashの技術的特徴】
- Everything is Box哲学: 全データがBoxオブジェクト
- Arc<Mutex>統一アーキテクチャ: 完全スレッドセーフ設計
- 明示性重視: 変数宣言先の即座特定可能
- Rust実装: メモリ安全性+高性能
- 目的: 初学者フレンドリー + 実用性
【検討する技術的課題】
現在P2PBox実装において、関数オーバーロード引数数による分岐採用の是非を検討中。
具体例:
```rust
// Option A: オーバーロードあり
impl P2PBox {
pub fn send(&self, message: IntentBox) -> Result<(), SendError> // ブロードキャスト
pub fn send(&self, to: &str, message: IntentBox) -> Result<(), SendError> // 個別送信
pub fn send(&self, to: &str, message: IntentBox, opts: SendOpts) -> Result<(), SendError> // オプション付き
}
// Option B: オーバーロードなし(現在)
impl P2PBox {
pub fn broadcast(&self, message: IntentBox) -> Result<(), SendError>
pub fn send(&self, to: &str, message: IntentBox) -> Result<(), SendError>
pub fn send_with_options(&self, to: &str, message: IntentBox, opts: SendOpts) -> Result<(), SendError>
}
```
【技術的検討ポイント】
1. **Rust実装との整合性**
- Rustにはメソッドオーバーロードがない
- 引数数による分岐をインタープリターで実装する必要
- パフォーマンスへの影響
2. **Arc<Mutex>アーキテクチャとの親和性**
- 動的ディスパッチの複雑さ
- エラーハンドリングの一貫性
- スレッドセーフティの保持
3. **インタープリター実装の複雑度**
- パーサーでの引数数判定
- 実行時メソッド選択アルゴリズム
- デバッグ情報の提供
4. **型安全性とパフォーマンス**
- 実行時型チェックのオーバーヘッド
- エラーメッセージの品質
- 開発時デバッグ体験
5. **エコシステム設計との整合性**
- 他のBox型との一貫性
- 拡張性(新しいオーバーロード追加)
- メンテナンス性
【深く検討してほしい点】
1. 技術的実装の複雑さ vs ユーザー体験の向上
2. Nyashの「明示性重視」哲学との技術的整合性
3. 初学者がエラーに遭遇した時のデバッグ体験
4. P2P通信という特定ドメインでの最適解
5. 言語の長期進化における影響
プログラミング言語実装の専門的視点から、技術的に最良で保守しやすい設計を分析してください。

View File

@ -1,46 +0,0 @@
Nyashプログラミング言語の関数オーバーロード採用可否について言語設計の専門的観点から相談です。
【背景】
Nyashは「Everything is Box」哲学で、明示性重視・初学者フレンドリー・メモリ安全性を重視する言語です。現在Phase 2でP2PBox実装中で、関数オーバーロード引数数による分岐を採用するか重要な決断が必要です。
【具体的争点】
send(a) と send(a, b) のような関数オーバーロードを許すか?
例:
```nyash
// オーバーロードありの場合
node.send("hello") // ブロードキャスト
node.send("bob", "hello") // 個別送信
node.send("bob", msg, options) // オプション付き
// オーバーロードなしの場合(現在)
node.broadcast("hello") // 明示的メソッド名
node.send("bob", "hello") // 必ず2引数
node.sendWithOptions("bob", msg, options) // 明示的メソッド名
```
【メリット】
1. API使いやすさ向上
2. 他言語からの移行しやすさ
3. 直感的な呼び出し
【デメリット】
1. 間違った関数を呼ぶリスク
2. デバッグ困難
3. Nyashの明示性哲学と矛盾
4. 初学者混乱
5. 型推論複雑化
【Nyashの設計思想との照合】
- 明示性重視: プログラマーが変数の宣言先を即座に特定可能
- 初学者フレンドリー: 学習コストが低い
- Everything is Box: 統一されたオブジェクトモデル
【質問】
1. Nyashの設計思想から見て、関数オーバーロードは採用すべきか
2. 明示性 vs 利便性のトレードオフをどう判断すべきか?
3. 初学者向け言語として適切な選択は?
4. P2P通信APIにおける最良の設計は
5. 他の現代的言語設計トレンドとの整合性は?
プログラミング言語設計の専門的視点から、Nyashの将来を決めるアドバイスをお願いします。

View File

@ -1,73 +0,0 @@
Nyash言語のweak参照システム最終実装について技術的相談をお願いします。
【現在の状況】
copilot様がweak参照システムを99%完成させました。驚くべき実装品質です。
【✅ 完成済みの素晴らしい実装】
1. ハイブリッド構造: fields + fields_ng 併用システム
2. weak参照専用メソッド: set_weak_field(), get_weak_field()
3. 文字列ベース追跡: "WEAK_REF_TO:..." → "WEAK_REFERENCE_DROPPED"
4. インタープリター統合: weak参照の検出・代入・アクセス完璧
5. 5つの包括的テストケース
【⚠️ 残り1%の課題】
単一関数 trigger_weak_reference_invalidation() が未実装:
```rust
pub(super) fn trigger_weak_reference_invalidation(&mut self, target_info: &str) {
eprintln!("🔗 DEBUG: Triggering global weak reference invalidation for: {}", target_info);
// TODO: Real implementation would require tracking all instances
// and their weak references
}
```
【現在の動作】
```
✅ weak参照検出: 完璧 (🔗 DEBUG: Assigning to weak field 'parent')
✅ ドロップ検出: 動作中 (🔗 DEBUG: Variable 'parent' set to 0)
✅ 無効化呼び出し: 実行中 (🔗 DEBUG: Triggering global weak reference invalidation)
❌ 実際のnil化: 未接続 (🔗 DEBUG: Weak field 'parent' still has valid reference)
```
【copilot提案の実装アプローチ】
グローバルインスタンス追跡システム:
```rust
pub struct SharedState {
// 既存フィールド...
pub instance_registry: Arc<Mutex<Vec<Weak<Mutex<InstanceBox>>>>>,
}
impl SharedState {
fn register_instance(&mut self, instance: Weak<Mutex<InstanceBox>>) { ... }
fn invalidate_weak_references(&mut self, target_info: &str) {
// 全インスタンスを走査してweak参照を無効化
}
}
```
【技術的課題】
1. 全InstanceBox作成時のグローバル登録必要
2. 複雑なスレッドセーフティ管理
3. デッドweak参照のガベージコレクション
4. 5+ファイルにわたる変更
【代替案検討の観点】
1. **より簡単な実装**: グローバル追跡なしで実現可能?
2. **性能重視**: シンプルな文字列マッチングで十分?
3. **段階的実装**: デモレベルで動作する最小実装?
【具体的質問】
1. グローバルインスタンス追跡は本当に必要ですか?
2. copilotの文字列ベース追跡をより簡単に完成できますか
3. 「target_info」による簡単なマッチング実装は可能ですか
4. デモ目的なら手動的な実装で十分ではないですか?
【Nyashの設計哲学】
- Everything is Box: すべてがBoxオブジェクト
- 明示性重視: 隠れた動作を避ける
- シンプル重視: 初学者フレンドリー
- 実用性優先: 完璧より動くもの
プログラミング言語実装の専門的観点から、最もシンプルで実装しやすいアプローチを提案してください。copilot様の99%完成した実装を活かしつつ、最後の1%を効率的に完成させる方法をお願いします。

View File

@ -1,40 +0,0 @@
Nyash言語のweak参照実装で根本的な設計問題が発覚しました。専門的分析をお願いします。
【現在の問題】
InstanceBox構造が原因でweak参照が実装できません
```rust
pub struct InstanceBox {
pub fields: Arc<Mutex<HashMap<String, Box<dyn NyashBox>>>>, // 問題の核心
}
```
NyashValue::WeakBoxを作っても、Box<dyn NyashBox>にしか格納できず、弱参照情報が失われます。
【解決策の選択肢】
1. **根本解決**(理想だが影響大)
```rust
pub fields: Arc<Mutex<HashMap<String, NyashValue>>>, // 全面アーキテクチャ変更
```
2. **暫定解決**copilot提案
```rust
pub struct InstanceBox {
pub fields: Arc<Mutex<HashMap<String, Box<dyn NyashBox>>>>, // 既存維持
pub weak_fields: Arc<Mutex<HashMap<String, Weak<Mutex<dyn NyashBox>>>>>, // 追加
}
```
【コンテキスト】
- NyashValue革命は完了済みArc<Mutex>過剰症候群解決)
- Everything is Box哲学必須
- 実用性重視(完璧より動くもの優先)
【質問】
1. 暫定解決策の技術的妥当性は?
2. パフォーマンス・保守性への影響は?
3. 根本解決は本当に必要か?
4. 段階的移行戦略の是非は?
実装可能性と設計の美しさのバランスを重視した分析をお願いします。