🏗️ feat: Phase 9.78b準備 - インタープリター・VM統合アーキテクチャ設計

Phase 9.78b: Codexの天才的分析に基づくアーキテクチャ再設計準備

## 📋 実施内容
1. Codex分析結果のアーカイブ
   - 実装詳細共有 → モデル共有・実行時共有への転換提案
   - 8ステップの段階的実装計画

2. Phase 9.78a作業の保存
   - MIR生成でのNewBox命令統一(保持)
   - ScopeTracker基本実装(一時コメントアウト)
   - VM拡張の方向性(TODOコメント付き)

3. ビルドエラー修正
   - ScopeTrackerインポート問題を一時的に解決
   - ビルド成功(警告のみ)

## 📚 作成ドキュメント
- architecture-redesign-proposal.md - Codexの設計提案
- phase_9_78b_interpreter_architecture_refactoring.md - 実装計画
- codex-analysis/* - 分析結果アーカイブ

## 🎯 次のステップ
Phase 9.78b Step 1: BoxDeclarationをcore::modelへ移動
This commit is contained in:
Moe Charm
2025-08-20 17:58:51 +09:00
parent c11b68af90
commit 86b9f7719b
13 changed files with 1478 additions and 1158 deletions

73
src/scope_tracker.rs Normal file
View File

@ -0,0 +1,73 @@
/*!
* ScopeTracker - Track Box instances for proper lifecycle management
*
* Phase 9.78a: Unified Box lifecycle management for VM
*/
use std::sync::Arc;
use crate::box_trait::NyashBox;
/// Tracks Box instances created in different scopes for proper fini calls
pub struct ScopeTracker {
/// Stack of scopes, each containing Boxes created in that scope
scopes: Vec<Vec<Arc<dyn NyashBox>>>,
}
impl ScopeTracker {
/// Create a new scope tracker
pub fn new() -> Self {
Self {
scopes: vec![Vec::new()], // Start with one root scope
}
}
/// Enter a new scope
pub fn push_scope(&mut self) {
self.scopes.push(Vec::new());
}
/// Exit current scope and call fini on all Boxes created in it
pub fn pop_scope(&mut self) {
if let Some(scope) = self.scopes.pop() {
// Call fini in reverse order of creation
for arc_box in scope.into_iter().rev() {
// For now, fini handling is simplified
// In a full implementation, we would check if the Box has a fini method
// and call it appropriately
// TODO: Implement proper fini dispatch
let _ = arc_box; // Suppress unused warning
}
}
// Ensure we always have at least one scope
if self.scopes.is_empty() {
self.scopes.push(Vec::new());
}
}
/// Register a Box in the current scope
pub fn register_box(&mut self, nyash_box: Arc<dyn NyashBox>) {
if let Some(current_scope) = self.scopes.last_mut() {
current_scope.push(nyash_box);
}
}
/// Clear all scopes (used when resetting VM state)
pub fn clear(&mut self) {
// Pop all scopes and call fini
while self.scopes.len() > 1 {
self.pop_scope();
}
// Clear the root scope
if let Some(root_scope) = self.scopes.first_mut() {
root_scope.clear();
}
}
}
impl Default for ScopeTracker {
fn default() -> Self {
Self::new()
}
}