feat(phase88): Ring0Context Skeleton implementation

Phase 88: OS API abstraction layer implementation

**Implementation**:
- Ring0Context module added (4 files)
  - mod.rs: Public API, global initialization (OnceLock)
  - traits.rs: MemApi, IoApi, TimeApi, LogApi trait definitions
  - std_impls.rs: std-based default implementations
  - errors.rs: IoError, TimeError type definitions

**Design Principles**:
- Ring0 knows nothing about Box
- Ring0 knows nothing about Nyash
- Pure OS API abstraction

**Global Initialization**:
- NyashRunner::new() initializes Ring0Context globally
- OnceLock ensures safe initialization (idempotent)

**Migration (2 paths)**:
- src/runner/selfhost.rs:27: eprintln! → ring0.log.error() (OOB strict)
- src/runner/selfhost.rs:177: eprintln! → ring0.log.error() (PyVM error)

**Tests**:
- 4 unit tests added (ring0 module)
- All tests passed
- Build successful (0 errors)

**Migration Status**:
- Migrated: 2/3,955 (0.05%)
- Remaining: 3,953 paths (Phase 89+)

**Files Changed**:
- src/runtime/ring0/mod.rs (new, 100 lines)
- src/runtime/ring0/traits.rs (new, 93 lines)
- src/runtime/ring0/std_impls.rs (new, 77 lines)
- src/runtime/ring0/errors.rs (new, 26 lines)
- src/runtime/mod.rs (Ring0Context export)
- src/runner/mod.rs (global initialization)
- src/runner/selfhost.rs (2 paths migrated)
- docs/development/current/main/ring0-inventory.md (Phase 88 status)

Phase 88 complete. Ready for Phase 89 (gradual migration).

🐱
This commit is contained in:
nyash-codex
2025-12-02 22:38:27 +09:00
parent 8cd9729375
commit 42b09b3c1c
9 changed files with 331 additions and 5 deletions

View File

@ -60,6 +60,12 @@ use tasks::run_named_task;
impl NyashRunner {
/// Create a new runner with the given configuration
pub fn new(config: CliConfig) -> Self {
// Phase 88: Ring0Context 初期化(グローバル、一度だけ)
// OnceLock により、複数回呼ばれても最初の一度だけ初期化される
let _ = runtime::ring0::GLOBAL_RING0.get_or_init(|| {
std::sync::Arc::new(runtime::ring0::default_ring0())
});
Self { config }
}

View File

@ -24,7 +24,9 @@ fn maybe_dump_mir_verbose(module: &crate::mir::MirModule) {
/// Check OOB strict mode and exit(1) if out-of-bounds was observed.
fn check_oob_strict_exit() {
if crate::config::env::oob_strict_fail() && crate::runtime::observe::oob_seen() {
eprintln!("[selfhost][oob-strict] Out-of-bounds observed → exit(1)");
// Phase 88: Ring0Context 経由でエラーログ出力
let ring0 = crate::runtime::ring0::get_global_ring0();
ring0.log.error("[selfhost][oob-strict] Out-of-bounds observed → exit(1)");
std::process::exit(1);
}
}
@ -170,7 +172,9 @@ impl NyashRunner {
println!("Result: {}", code);
std::process::exit(code);
} else {
eprintln!("❌ PyVM error (selfhost-preexpand)");
// Phase 88: Ring0Context 経由でエラーログ出力
let ring0 = crate::runtime::ring0::get_global_ring0();
ring0.log.error("❌ PyVM error (selfhost-preexpand)");
std::process::exit(1);
}
} else {