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). 🐱✨
81 lines
3.4 KiB
Markdown
81 lines
3.4 KiB
Markdown
# Ring0 Inventory(初回棚卸しメモ)
|
||
|
||
このドキュメントは、Phase 85-ring0-runtime のための「Ring0 候補呼び出し」の棚卸しメモだよ。
|
||
ここでは Task 調査で分かった概況だけをまとめておき、詳細な一覧化や移行は後続フェーズで扱う。
|
||
|
||
---
|
||
|
||
## 1. println!/eprintln! 呼び出し
|
||
|
||
- `println!` / `eprintln!` の合計呼び出し回数: **3,955 回**
|
||
- デバッグログ/一時ログ/ユーザ向けメッセージが混在している。
|
||
- Ring0 の `LogApi` / `Console` 相当として、最優先で整理したい対象。
|
||
- 方針メモ:
|
||
- 将来的には `Ring0Context.log` / `Ring0Context.io` 経由に寄せる。
|
||
- 代表パス(selfhost/hack_check/VM/LLVM)の `println!/eprintln!` から段階的に移行する。
|
||
|
||
### Phase 88 移行状況(2025-12-02)
|
||
|
||
**移行済みパス(2箇所)**:
|
||
|
||
| ファイル | 行 | Before | After |
|
||
|---------|---|--------|-------|
|
||
| `src/runner/selfhost.rs` | 27 | `eprintln!("[selfhost][oob-strict] ...")` | `ring0.log.error("[selfhost][oob-strict] ...")` |
|
||
| `src/runner/selfhost.rs` | 177 | `eprintln!("❌ PyVM error ...")` | `ring0.log.error("❌ PyVM error ...")` |
|
||
|
||
**残存パス(3,953箇所)**:
|
||
|
||
| カテゴリ | 出現回数 | 移行予定 |
|
||
|---------|---------|---------|
|
||
| println! | 2,200 | Phase 89-A |
|
||
| eprintln! | 1,753 | Phase 89-B |
|
||
|
||
Phase 89 以降で段階的に移行予定。
|
||
|
||
---
|
||
|
||
## 2. Box / プラグイン / カーネル実装の数
|
||
|
||
- `src/boxes`: 34 Box
|
||
- `plugins/`: 22 プラグイン
|
||
- `crates/nyash_kernel`: 12 カーネル実装
|
||
|
||
ざっくり分類案(Phase 85 時点の暫定):
|
||
|
||
- core_required:
|
||
- StringBox, IntegerBox, BoolBox, ArrayBox, MapBox, ConsoleBox など、言語の基本型+コンソール。
|
||
- core_optional:
|
||
- FileBox, PathBox, RegexBox, MathBox, TimeBox, JsonBox, TomlBox など、標準ユーティリティ系。
|
||
- selfhost_required:
|
||
- Stage1CliBox, AotCompilerBox, MirJsonBuilderBox など、selfhost/Stage1 ライン専用。
|
||
- user_plugin:
|
||
- P2P, HTTP, GUI, Python 連携 等の外部拡張。
|
||
|
||
※ 正確な一覧とファイルパスは、後続フェーズで Box 定義ファイルを機械的に列挙して作る。
|
||
|
||
---
|
||
|
||
## 3. Factory Priority 問題(Phase 15.5 の再確認)
|
||
|
||
- 現状の Factory Priority が `BuiltinFirst`(ビルトイン優先)となっている箇所があり、
|
||
- プラグインで上書きしたいケースでも、ビルトイン版が優先されてしまう。
|
||
- これは:
|
||
- 「core_required な Box」と「user_plugin を使って差し替えたい Box」の境界が曖昧なことの副作用でもある。
|
||
- 方針メモ:
|
||
- Ring1-core の整理と合わせて、Factory Priority を
|
||
- core_required は常にビルトイン
|
||
- core_optional / user_plugin は設定やプロファイルで切り替え可能
|
||
に整理していく。
|
||
|
||
---
|
||
|
||
## 4. 今後の棚卸しタスク(TODO メモ)
|
||
|
||
- `std::fs` / `File::open` / `std::io::stdin` などの呼び出し地点を一覧化。
|
||
- `SystemTime::now` / `Instant::now` / `thread::sleep` など時間・スレッド系 API の呼び出し地点を一覧化。
|
||
- hakmem / nyrt 経由の低レベル API 呼び出し(alloc/free など)を一覧化。
|
||
- 代表パス(selfhost/hack_check/VM/LLVM)のみを対象にした「最小 Ring0 呼び出しセット」を定義する。
|
||
|
||
これらは Phase 86–87 で Ring0Context に寄せていくための下準備だよ。
|
||
|