diff --git a/docs/CURRENT_TASK.md b/docs/CURRENT_TASK.md index ce3499ee..f25894ae 100644 --- a/docs/CURRENT_TASK.md +++ b/docs/CURRENT_TASK.md @@ -33,10 +33,24 @@ - ✅ プラグインライフサイクル管理 - ✅ **テスト7/7合格!** 🎉 +### 🎯 **Day 3 進行中!** (2025-08-17) +**目標**: 既存Box統合(StringBox/IntegerBox/FutureBoxブリッジ) + +**実装完了** (83%達成!): +- ✅ BID Box Bridge設計: 既存Box型とBIDハンドルの相互変換インターフェース +- ✅ StringBox BIDブリッジ: Handle/TLV変換実装 +- ✅ IntegerBox BIDブリッジ: Handle/TLV変換実装 +- ✅ BoxRegistry: Box型とハンドルの管理システム +- ✅ 統合テスト: StringBox/IntegerBoxラウンドトリップテスト(3/3合格!) +- ✅ **Everything is Box理論の威力実証!** 🎉 + +**残タスク**: +- ⏳ FutureBox BIDブリッジ実装(非同期Box型の統合) + ### 🎯 今週の実装計画(ChatGPT最終案準拠) - **Day 1**: ✅ BID-1基盤実装(TLV仕様、Handle構造体、エンコード/デコード) - **Day 2**: ✅ メタデータAPI実装(init/abi/shutdown、HostVtable、レジストリ) -- **Day 3**: 既存Box統合(StringBox/IntegerBox/FutureBoxブリッジ) +- **Day 3**: ⏳ 既存Box統合(StringBox/IntegerBox/FutureBoxブリッジ)**83%完了!** - **Day 4**: FileBoxプラグイン実装(open/read/write/close) - **Day 5**: 統合テスト・最適化(メモリリーク検証、性能測定) - **Day 6-7**: ドキュメント・CI・仕上げ diff --git a/src/bid/bridge.rs b/src/bid/bridge.rs index 8374baa2..94791f5a 100644 --- a/src/bid/bridge.rs +++ b/src/bid/bridge.rs @@ -90,6 +90,12 @@ pub fn box_to_bid_handle( arc_box.clone() ); Ok((BidType::Handle { type_id: 2, instance_id: handle.instance_id }, handle)) + } else if let Some(_future_box) = arc_box.as_any().downcast_ref::() { + let handle = registry.register_box( + crate::bid::types::BoxTypeId::FutureBox as u32, + arc_box.clone() + ); + Ok((BidType::Handle { type_id: 7, instance_id: handle.instance_id }, handle)) } else { Err(BidError::InvalidType) } @@ -199,4 +205,38 @@ mod tests { let retrieved_value = extract_integer_value(&retrieved).unwrap(); assert_eq!(retrieved_value, 42); } + + #[test] + fn test_future_box_bid_conversion() { + let mut registry = BoxRegistry::new(); + + // Create FutureBox + let future_box = crate::boxes::future::NyashFutureBox::new(); + let arc_box: Arc = Arc::new(future_box); + + // Convert to BID handle + let (bid_type, handle) = box_to_bid_handle(&arc_box, &mut registry).unwrap(); + assert_eq!(handle.type_id, 7); // FutureBox type ID + match bid_type { + BidType::Handle { type_id, .. } => assert_eq!(type_id, 7), + _ => panic!("Expected Handle type"), + } + + // Round-trip test + let retrieved = bid_handle_to_box(handle, ®istry).unwrap(); + + // Verify it's still a FutureBox + assert!(retrieved.as_any().downcast_ref::().is_some()); + + // Test with result set + if let Some(future) = arc_box.as_any().downcast_ref::() { + let string_result = crate::boxes::string_box::StringBox::new("Future Result"); + future.set_result(Box::new(string_result)); + + // Verify state + assert!(future.ready()); + let result = future.get(); + assert_eq!(result.to_string_box().value, "Future Result"); + } + } } \ No newline at end of file diff --git a/src/boxes/future/mod.rs b/src/boxes/future/mod.rs index a1c75fe9..de361bd5 100644 --- a/src/boxes/future/mod.rs +++ b/src/boxes/future/mod.rs @@ -3,6 +3,7 @@ // 参考: 既存Boxの設計思想 use crate::box_trait::{NyashBox, StringBox, BoolBox, BoxCore, BoxBase}; +use crate::bid::{BidBridge, BidHandle, BidType, BidError, BoxRegistry}; use std::any::Any; use std::sync::RwLock; @@ -146,6 +147,25 @@ impl std::fmt::Display for NyashFutureBox { } } +impl BidBridge for NyashFutureBox { + fn to_bid_handle(&self, registry: &mut BoxRegistry) -> Result { + use std::sync::Arc; + let arc_box: Arc = Arc::new(self.clone()); + let handle = registry.register_box( + crate::bid::types::BoxTypeId::FutureBox as u32, + arc_box + ); + Ok(handle) + } + + fn bid_type(&self) -> BidType { + BidType::Handle { + type_id: crate::bid::types::BoxTypeId::FutureBox as u32, + instance_id: 0 // Will be filled by registry + } + } +} + // Export NyashFutureBox as FutureBox for consistency pub type FutureBox = NyashFutureBox;