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).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
|
//! Phase 88: Ring0 trait 定義
|
|
|
|
|
|
//!
|
|
|
|
|
|
//! OS API レイヤーの純粋な抽象化。
|
|
|
|
|
|
//! Box 名・Nyash 型を一切知らない。
|
|
|
|
|
|
|
|
|
|
|
|
use super::errors::{IoError, TimeError};
|
feat(phase90): Ring0Context fs/time/thread migration complete
Phase 90 完了: IO/fs/time/thread 系の Ring0 移行
**Phase 90-A: fs 系移行(7箇所)**
- FsApi trait 追加(6メソッド)
- StdFs 実装(std::fs ベース)
- IoError 拡張(4バリアント追加)
- 移行: strip.rs(4), dispatch.rs(1), mod.rs(3)
**Phase 90-B: io 系移行**
- Phase 88 完了済み(スキップ)
**Phase 90-C: time 系移行(3箇所)**
- TimeApi に elapsed() 追加
- 移行: selfhost_exe.rs(1), io.rs(1), plugin_loader_unified.rs(1)
**Phase 90-D: thread 系移行(2箇所)**
- ThreadApi trait 追加(sleep メソッド)
- StdThread 実装
- 移行: global_hooks.rs(1), plugin_loader_unified.rs(1)
**Phase 90-E: 統合テスト**
- ビルド成功(6 warnings, 0 errors)
- テスト: 522/554 passed (94.2%)
- 退行なし
**実装成果**:
- Ring0Context 拡張: fs, thread フィールド追加
- 総移行: 12箇所(fs: 7, time: 3, thread: 2)
- 移行率: fs(2.9%), time(2.1%), thread(5.4%)
**次のステップ**: Phase 91 (PluginHost/CoreServices skeleton)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 06:14:57 +09:00
|
|
|
|
use std::path::{Path, PathBuf};
|
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).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
|
use std::time::SystemTime;
|
|
|
|
|
|
|
|
|
|
|
|
/// メモリ API(Phase 88: noop、将来 hakmem 接続)
|
|
|
|
|
|
pub trait MemApi: Send + Sync {
|
|
|
|
|
|
/// メモリ割り当て(Phase 88: 未実装)
|
|
|
|
|
|
fn alloc(&self, size: usize) -> *mut u8;
|
|
|
|
|
|
|
|
|
|
|
|
/// メモリ解放(Phase 88: 未実装)
|
|
|
|
|
|
fn free(&self, ptr: *mut u8);
|
|
|
|
|
|
|
|
|
|
|
|
/// メモリ統計(Phase 88: 未実装)
|
|
|
|
|
|
fn stats(&self) -> MemStats;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// メモリ統計情報
|
|
|
|
|
|
#[derive(Debug, Default, Clone)]
|
|
|
|
|
|
pub struct MemStats {
|
|
|
|
|
|
pub allocated: usize,
|
|
|
|
|
|
pub freed: usize,
|
|
|
|
|
|
pub current: usize,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// IO API
|
|
|
|
|
|
pub trait IoApi: Send + Sync {
|
|
|
|
|
|
/// 標準出力への書き込み
|
|
|
|
|
|
fn stdout_write(&self, data: &[u8]) -> Result<(), IoError>;
|
|
|
|
|
|
|
|
|
|
|
|
/// 標準エラー出力への書き込み
|
|
|
|
|
|
fn stderr_write(&self, data: &[u8]) -> Result<(), IoError>;
|
|
|
|
|
|
|
|
|
|
|
|
/// 標準入力からの読み込み
|
|
|
|
|
|
fn stdin_read(&self, buf: &mut [u8]) -> Result<usize, IoError>;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 時刻 API
|
|
|
|
|
|
pub trait TimeApi: Send + Sync {
|
|
|
|
|
|
/// 現在時刻取得
|
|
|
|
|
|
fn now(&self) -> Result<SystemTime, TimeError>;
|
|
|
|
|
|
|
|
|
|
|
|
/// モノトニック時刻取得(高精度タイマー用)
|
|
|
|
|
|
fn monotonic_now(&self) -> Result<std::time::Instant, TimeError>;
|
feat(phase90): Ring0Context fs/time/thread migration complete
Phase 90 完了: IO/fs/time/thread 系の Ring0 移行
**Phase 90-A: fs 系移行(7箇所)**
- FsApi trait 追加(6メソッド)
- StdFs 実装(std::fs ベース)
- IoError 拡張(4バリアント追加)
- 移行: strip.rs(4), dispatch.rs(1), mod.rs(3)
**Phase 90-B: io 系移行**
- Phase 88 完了済み(スキップ)
**Phase 90-C: time 系移行(3箇所)**
- TimeApi に elapsed() 追加
- 移行: selfhost_exe.rs(1), io.rs(1), plugin_loader_unified.rs(1)
**Phase 90-D: thread 系移行(2箇所)**
- ThreadApi trait 追加(sleep メソッド)
- StdThread 実装
- 移行: global_hooks.rs(1), plugin_loader_unified.rs(1)
**Phase 90-E: 統合テスト**
- ビルド成功(6 warnings, 0 errors)
- テスト: 522/554 passed (94.2%)
- 退行なし
**実装成果**:
- Ring0Context 拡張: fs, thread フィールド追加
- 総移行: 12箇所(fs: 7, time: 3, thread: 2)
- 移行率: fs(2.9%), time(2.1%), thread(5.4%)
**次のステップ**: Phase 91 (PluginHost/CoreServices skeleton)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 06:14:57 +09:00
|
|
|
|
|
|
|
|
|
|
/// 経過時間取得 (Phase 90-C)
|
|
|
|
|
|
fn elapsed(&self, start: std::time::Instant) -> std::time::Duration;
|
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).
🐱✨
2025-12-02 22:38:27 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// ログレベル
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
|
pub enum LogLevel {
|
|
|
|
|
|
Debug,
|
|
|
|
|
|
Info,
|
|
|
|
|
|
Warn,
|
|
|
|
|
|
Error,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// ログ API
|
|
|
|
|
|
pub trait LogApi: Send + Sync {
|
|
|
|
|
|
/// ログ出力
|
|
|
|
|
|
fn log(&self, level: LogLevel, msg: &str);
|
|
|
|
|
|
|
|
|
|
|
|
/// デバッグログ(便利メソッド)
|
|
|
|
|
|
fn debug(&self, msg: &str) {
|
|
|
|
|
|
self.log(LogLevel::Debug, msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 情報ログ(便利メソッド)
|
|
|
|
|
|
fn info(&self, msg: &str) {
|
|
|
|
|
|
self.log(LogLevel::Info, msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// 警告ログ(便利メソッド)
|
|
|
|
|
|
fn warn(&self, msg: &str) {
|
|
|
|
|
|
self.log(LogLevel::Warn, msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// エラーログ(便利メソッド)
|
|
|
|
|
|
fn error(&self, msg: &str) {
|
|
|
|
|
|
self.log(LogLevel::Error, msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
feat(phase90): Ring0Context fs/time/thread migration complete
Phase 90 完了: IO/fs/time/thread 系の Ring0 移行
**Phase 90-A: fs 系移行(7箇所)**
- FsApi trait 追加(6メソッド)
- StdFs 実装(std::fs ベース)
- IoError 拡張(4バリアント追加)
- 移行: strip.rs(4), dispatch.rs(1), mod.rs(3)
**Phase 90-B: io 系移行**
- Phase 88 完了済み(スキップ)
**Phase 90-C: time 系移行(3箇所)**
- TimeApi に elapsed() 追加
- 移行: selfhost_exe.rs(1), io.rs(1), plugin_loader_unified.rs(1)
**Phase 90-D: thread 系移行(2箇所)**
- ThreadApi trait 追加(sleep メソッド)
- StdThread 実装
- 移行: global_hooks.rs(1), plugin_loader_unified.rs(1)
**Phase 90-E: 統合テスト**
- ビルド成功(6 warnings, 0 errors)
- テスト: 522/554 passed (94.2%)
- 退行なし
**実装成果**:
- Ring0Context 拡張: fs, thread フィールド追加
- 総移行: 12箇所(fs: 7, time: 3, thread: 2)
- 移行率: fs(2.9%), time(2.1%), thread(5.4%)
**次のステップ**: Phase 91 (PluginHost/CoreServices skeleton)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 06:14:57 +09:00
|
|
|
|
|
|
|
|
|
|
/// ファイルシステムメタデータ
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
|
pub struct FsMetadata {
|
|
|
|
|
|
pub is_file: bool,
|
|
|
|
|
|
pub is_dir: bool,
|
|
|
|
|
|
pub len: u64,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// ファイルシステム API (Phase 90-A)
|
|
|
|
|
|
pub trait FsApi: Send + Sync {
|
|
|
|
|
|
/// ファイルを文字列として読み込む
|
|
|
|
|
|
fn read_to_string(&self, path: &Path) -> Result<String, IoError>;
|
|
|
|
|
|
|
|
|
|
|
|
/// ファイルをバイト列として読み込む
|
|
|
|
|
|
fn read(&self, path: &Path) -> Result<Vec<u8>, IoError>;
|
|
|
|
|
|
|
|
|
|
|
|
/// ファイルに書き込む
|
|
|
|
|
|
fn write_all(&self, path: &Path, data: &[u8]) -> Result<(), IoError>;
|
|
|
|
|
|
|
2025-12-03 21:30:47 +09:00
|
|
|
|
/// ファイルに追記(append)
|
|
|
|
|
|
///
|
|
|
|
|
|
/// ファイルが存在しない場合は新規作成、存在する場合は末尾に追記。
|
|
|
|
|
|
/// Phase 111: write_all と対称的に提供。
|
|
|
|
|
|
fn append_all(&self, path: &Path, data: &[u8]) -> Result<(), IoError>;
|
|
|
|
|
|
|
feat(phase90): Ring0Context fs/time/thread migration complete
Phase 90 完了: IO/fs/time/thread 系の Ring0 移行
**Phase 90-A: fs 系移行(7箇所)**
- FsApi trait 追加(6メソッド)
- StdFs 実装(std::fs ベース)
- IoError 拡張(4バリアント追加)
- 移行: strip.rs(4), dispatch.rs(1), mod.rs(3)
**Phase 90-B: io 系移行**
- Phase 88 完了済み(スキップ)
**Phase 90-C: time 系移行(3箇所)**
- TimeApi に elapsed() 追加
- 移行: selfhost_exe.rs(1), io.rs(1), plugin_loader_unified.rs(1)
**Phase 90-D: thread 系移行(2箇所)**
- ThreadApi trait 追加(sleep メソッド)
- StdThread 実装
- 移行: global_hooks.rs(1), plugin_loader_unified.rs(1)
**Phase 90-E: 統合テスト**
- ビルド成功(6 warnings, 0 errors)
- テスト: 522/554 passed (94.2%)
- 退行なし
**実装成果**:
- Ring0Context 拡張: fs, thread フィールド追加
- 総移行: 12箇所(fs: 7, time: 3, thread: 2)
- 移行率: fs(2.9%), time(2.1%), thread(5.4%)
**次のステップ**: Phase 91 (PluginHost/CoreServices skeleton)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 06:14:57 +09:00
|
|
|
|
/// パスが存在するか確認
|
|
|
|
|
|
fn exists(&self, path: &Path) -> bool;
|
|
|
|
|
|
|
|
|
|
|
|
/// ファイルメタデータを取得
|
|
|
|
|
|
fn metadata(&self, path: &Path) -> Result<FsMetadata, IoError>;
|
|
|
|
|
|
|
|
|
|
|
|
/// パスを正規化
|
|
|
|
|
|
fn canonicalize(&self, path: &Path) -> Result<PathBuf, IoError>;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// スレッド API (Phase 90-D)
|
|
|
|
|
|
pub trait ThreadApi: Send + Sync {
|
|
|
|
|
|
/// 指定時間スリープ
|
|
|
|
|
|
fn sleep(&self, duration: std::time::Duration);
|
|
|
|
|
|
// spawn は Phase 91 以降で追加予定
|
|
|
|
|
|
}
|