Files
hakorune/src/runtime/mod.rs
nyash-codex 44c6ca9585 chore(runtime): Phase 98.5 Arc 完全修飾パス簡略化 & コメント統一
## 修正内容
**src/runtime/mod.rs** (4箇所):
- use文: std::sync::OnceLock → std::sync::{Arc, OnceLock}
- Line 64: OnceLock<std::sync::Arc<...>> → OnceLock<Arc<...>>
- Line 68: std::sync::Arc::new(...) → Arc::new(...)
- Line 72/80: 戻り値型で std::sync::Arc → Arc に統一

**src/runner/modes/vm.rs** (1箇所):
- Line 589: コメント統一 "println" → "eprintln"(実装に合わせる)

## 効果
- 可読性向上: std::sync:: プレフィックス4箇所削除
- 一貫性向上: console_println! マクロの説明と実装を統一
- 追加依存なし、機能変更なし

## テスト結果
 cargo build --release: 成功
 cargo test --lib runtime::core_services: 11 passed

🧹 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 11:17:41 +09:00

118 lines
4.6 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! Nyashランタイムモジュール
//!
//! プラグインシステムとBox管理の中核
pub mod box_registry;
pub mod core_box_ids; // Phase 87: CoreBoxId/CoreMethodId 型安全enum
pub mod core_services; // Phase 91: CoreServices trait 定義
pub mod deprecations;
pub mod gc;
pub mod plugin_host; // Phase 91: PluginHost skeleton
pub mod ring0; // Phase 88: Ring0Context - OS API 抽象化レイヤー
pub mod gc_controller;
pub mod gc_mode;
pub mod gc_trace;
pub mod global_hooks;
pub mod leak_tracker;
pub mod nyash_runtime;
pub mod observe; // Lightweight observability flags (OOB etc.)
pub mod plugin_config;
pub mod plugin_ffi_common;
pub mod plugin_loader_unified;
pub mod plugin_loader_v2;
pub mod provider_lock;
pub mod provider_verify;
pub mod scheduler;
pub mod semantics;
pub mod unified_registry; // Deprecation warnings with warn-once guards
// pub mod plugin_box; // legacy - 古いPluginBox
// pub mod plugin_loader; // legacy - Host VTable使用
pub mod extern_registry; // ExternCall (env.*) 登録・診断用レジストリ
pub mod host_api; // C ABI: plugins -> host 逆呼び出しAPITLSでVMに橋渡し
pub mod host_handles; // C ABI(TLV) 向け HostHandle レジストリ(ユーザー/内蔵Box受け渡し
pub mod modules_registry;
pub mod type_box_abi; // Phase 12: Nyash ABI (vtable) 雛形
pub mod type_meta;
pub mod type_registry; // Phase 12: TypeId→TypeBox 解決(雛形) // env.modules minimal registry
#[cfg(test)]
mod tests;
pub use box_registry::{get_global_registry, BoxFactoryRegistry, BoxProvider};
pub use core_box_ids::{CoreBoxCategory, CoreBoxId, CoreMethodId}; // Phase 87: 型安全enum
pub use plugin_config::PluginConfig;
pub use ring0::{get_global_ring0, init_global_ring0, Ring0Context}; // Phase 88: Ring0 公開 API
pub use plugin_host::CoreInitError; // Phase 92: CoreServices 初期化エラー
pub use plugin_loader_unified::{
get_global_plugin_host, init_global_plugin_host, MethodHandle, PluginBoxType, PluginHost,
PluginLibraryHandle,
};
pub use plugin_loader_v2::{get_global_loader_v2, init_global_loader_v2, PluginLoaderV2};
pub mod cache_versions;
pub use gc::{BarrierKind, GcHooks};
pub use nyash_runtime::{NyashRuntime, NyashRuntimeBuilder};
pub use scheduler::{Scheduler, SingleThreadScheduler};
pub use unified_registry::{
get_global_unified_registry, init_global_unified_registry, register_user_defined_factory,
};
// pub use plugin_box::PluginBox; // legacy
// Use unified plugin loader (formerly v2)
// pub use plugin_loader::{PluginLoaderV2 as PluginLoader, get_global_loader_v2 as get_global_loader}; // legacy
// Phase 95: CoreServices 用 global accessor
use std::sync::{Arc, OnceLock};
static GLOBAL_CORE_PLUGIN_HOST: OnceLock<Arc<plugin_host::PluginHost>> = OnceLock::new();
pub fn init_core_plugin_host(host: plugin_host::PluginHost) {
GLOBAL_CORE_PLUGIN_HOST
.set(Arc::new(host))
.expect("[Phase 95] CorePluginHost already initialized");
}
pub fn get_core_plugin_host() -> Arc<plugin_host::PluginHost> {
GLOBAL_CORE_PLUGIN_HOST
.get()
.expect("[Phase 95] CorePluginHost not initialized")
.clone()
}
/// Phase 98: Safe accessor that returns None if not initialized
pub fn try_get_core_plugin_host() -> Option<Arc<plugin_host::PluginHost>> {
GLOBAL_CORE_PLUGIN_HOST.get().cloned()
}
/// Phase 98: Helper macro to print using ConsoleService if available, otherwise eprintln
#[macro_export]
macro_rules! console_println {
($($arg:tt)*) => {
if let Some(host) = $crate::runtime::try_get_core_plugin_host() {
host.core.console.println(&format!($($arg)*));
} else {
eprintln!($($arg)*);
}
};
}
/// Runtime 初期化Phase 95: global accessor 実装完了)
///
/// Phase 94: フォールバック削除 - 常に実際の Box を使用
/// Phase 95: global に登録して get_core_plugin_host() でアクセス可能に
pub fn initialize_runtime(ring0: std::sync::Arc<Ring0Context>) -> Result<(), CoreInitError> {
use crate::box_factory::UnifiedBoxRegistry;
use crate::box_factory::builtin::BuiltinBoxFactory;
let mut registry = UnifiedBoxRegistry::with_env_policy();
// Phase 94: BuiltinBoxFactory を登録して core_required Boxes を提供
registry.register(std::sync::Arc::new(BuiltinBoxFactory::new()));
// Phase 94: 常に実際の Box → Service 変換を使用Fail-Fast原則
let plugin_host = plugin_host::PluginHost::with_core_from_registry(ring0, &registry)?;
plugin_host.ensure_core_initialized();
// Phase 95: global に登録
init_core_plugin_host(plugin_host);
Ok(())
}