2025-09-04 03:41:02 +09:00
|
|
|
|
/*!
|
2025-09-24 11:43:11 +09:00
|
|
|
|
* Builtin Box Factory (Phase 15.5: Transitioning to "Everything is Plugin")
|
2025-09-04 03:41:02 +09:00
|
|
|
|
*
|
2025-09-24 11:43:11 +09:00
|
|
|
|
* ⚠️ MIGRATION IN PROGRESS: Phase 15.5 Core Box Unification
|
|
|
|
|
|
* 🎯 Goal: Remove builtin priority, make all Boxes plugin-based
|
|
|
|
|
|
* 📋 Current: builtin > user > plugin (PROBLEMATIC)
|
|
|
|
|
|
* 🚀 Target: plugin > user > builtin_compat (Phase 1) → plugin-only (Phase 3)
|
|
|
|
|
|
*
|
|
|
|
|
|
* Implementation Strategy:
|
|
|
|
|
|
* - Phase 0: ✅ Separate implementations to builtin_impls/ (easy deletion)
|
|
|
|
|
|
* - Phase 1: 🚧 Add strict_plugin_first policy + access guards
|
|
|
|
|
|
* - Phase 2: 🔄 Delete builtin_impls/ files one by one
|
|
|
|
|
|
* - Phase 3: ❌ Delete BuiltinBoxFactory entirely
|
2025-09-04 03:41:02 +09:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
use super::BoxFactory;
|
2025-09-24 09:30:42 +09:00
|
|
|
|
use super::RuntimeError;
|
2025-09-24 11:43:11 +09:00
|
|
|
|
use crate::box_trait::NyashBox;
|
|
|
|
|
|
|
|
|
|
|
|
// Separated implementations (Phase 0: ✅ Complete)
|
|
|
|
|
|
use super::builtin_impls;
|
2025-09-04 03:41:02 +09:00
|
|
|
|
|
|
|
|
|
|
/// Factory for builtin Box types
|
|
|
|
|
|
pub struct BuiltinBoxFactory;
|
|
|
|
|
|
|
|
|
|
|
|
impl BuiltinBoxFactory {
|
2025-09-17 07:43:07 +09:00
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
|
Self
|
|
|
|
|
|
}
|
2025-09-04 03:41:02 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl BoxFactory for BuiltinBoxFactory {
|
|
|
|
|
|
fn create_box(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
name: &str,
|
|
|
|
|
|
args: &[Box<dyn NyashBox>],
|
|
|
|
|
|
) -> Result<Box<dyn NyashBox>, RuntimeError> {
|
2025-09-24 11:43:11 +09:00
|
|
|
|
// Phase 0: ✅ Route to separated implementations (easy deletion)
|
2025-09-04 03:41:02 +09:00
|
|
|
|
match name {
|
2025-09-24 11:43:11 +09:00
|
|
|
|
// Phase 2.1-2.2: DELETE when plugins are confirmed working
|
|
|
|
|
|
"StringBox" => builtin_impls::string_box::create(args),
|
|
|
|
|
|
"IntegerBox" => builtin_impls::integer_box::create(args),
|
|
|
|
|
|
|
|
|
|
|
|
// Phase 2.3: DELETE when BoolBox plugin is created
|
|
|
|
|
|
"BoolBox" => builtin_impls::bool_box::create(args),
|
|
|
|
|
|
|
|
|
|
|
|
// Phase 2.4-2.5: DELETE when collection plugins confirmed
|
|
|
|
|
|
"ArrayBox" => builtin_impls::array_box::create(args),
|
|
|
|
|
|
"MapBox" => builtin_impls::map_box::create(args),
|
|
|
|
|
|
|
|
|
|
|
|
// Phase 2.6: DELETE LAST (critical for logging)
|
|
|
|
|
|
"ConsoleBox" => builtin_impls::console_box::create(args),
|
2025-09-04 03:41:02 +09:00
|
|
|
|
|
2025-11-08 17:04:21 +09:00
|
|
|
|
// Phase 15.5: Fallback support (auto/core-ro modes)
|
|
|
|
|
|
"FileBox" => builtin_impls::file_box::create(args),
|
|
|
|
|
|
|
2025-09-24 11:43:11 +09:00
|
|
|
|
// Special: Keep vs Delete discussion needed
|
|
|
|
|
|
"NullBox" => builtin_impls::null_box::create(args),
|
2025-09-04 03:41:02 +09:00
|
|
|
|
|
|
|
|
|
|
// Leave other types to other factories (user/plugin)
|
2025-09-17 07:43:07 +09:00
|
|
|
|
_ => Err(RuntimeError::InvalidOperation {
|
|
|
|
|
|
message: format!("Unknown Box type: {}", name),
|
|
|
|
|
|
}),
|
2025-09-04 03:41:02 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn box_types(&self) -> Vec<&str> {
|
|
|
|
|
|
vec![
|
|
|
|
|
|
// Primitive wrappers
|
2025-09-17 07:43:07 +09:00
|
|
|
|
"StringBox",
|
|
|
|
|
|
"IntegerBox",
|
|
|
|
|
|
"BoolBox",
|
2025-09-04 03:41:02 +09:00
|
|
|
|
// Collections/common
|
2025-09-17 07:43:07 +09:00
|
|
|
|
"ArrayBox",
|
|
|
|
|
|
"MapBox",
|
|
|
|
|
|
"ConsoleBox",
|
2025-11-08 17:04:21 +09:00
|
|
|
|
// Fallback support
|
|
|
|
|
|
"FileBox",
|
2025-09-17 07:43:07 +09:00
|
|
|
|
"NullBox",
|
2025-09-04 03:41:02 +09:00
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-17 07:43:07 +09:00
|
|
|
|
fn is_builtin_factory(&self) -> bool {
|
|
|
|
|
|
true
|
|
|
|
|
|
}
|
2025-09-04 03:41:02 +09:00
|
|
|
|
}
|