refactor(repl): Phase 288 Box化 - REPL Runner モジュール分離
箱理論モジュール化(Box-First): - src/runner/repl/ 新規モジュール作成 - ReplRunnerBox: REPL実行器の完全隔離 - ReplSessionBox: mir/builder → runner/repl へ移動 File changes: - src/runner/mod.rs: -118行(REPL コード削除) - src/runner/repl/mod.rs: +22行(公開API) - src/runner/repl/repl_runner.rs: +143行(ReplRunnerBox実装) - src/runner/repl/repl_session.rs: moved from mir/builder/ Benefits: - runner/mod.rs が綺麗(REPL 関連削除) - REPL 機能が完全隔離(file mode への影響ゼロ保証) - テスト容易性向上(Box 単体テスト可能) Test results: ✅ REPL 動作確認(print/.reset/.exit) ✅ File mode regression: 154/154 pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -1,55 +0,0 @@
|
||||
//! ReplSessionBox - Session state for REPL mode
|
||||
//!
|
||||
//! Box-First Design: Encapsulates REPL-specific state
|
||||
//! Phase 288 P2
|
||||
//!
|
||||
//! **重要**: ValueId は MIR コンパイル単位でのみ有効なので、
|
||||
//! 実行時の値(VMValue)を保持する。
|
||||
|
||||
use crate::backend::VMValue;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
/// REPL session context - isolated from file mode
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ReplSessionBox {
|
||||
/// Session-level variables (runtime values, persists across evaluations)
|
||||
pub variables: BTreeMap<String, VMValue>,
|
||||
|
||||
/// Last expression value (for `_` variable)
|
||||
pub last_value: Option<VMValue>,
|
||||
|
||||
/// Evaluation counter
|
||||
pub eval_count: usize,
|
||||
}
|
||||
|
||||
impl ReplSessionBox {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// REPL set: 変数に実行時の値を保存
|
||||
pub fn set(&mut self, name: String, value: VMValue) {
|
||||
self.variables.insert(name, value);
|
||||
}
|
||||
|
||||
/// REPL get: 変数の実行時の値を取得(未定義は None)
|
||||
pub fn get(&self, name: &str) -> Option<&VMValue> {
|
||||
self.variables.get(name)
|
||||
}
|
||||
|
||||
/// セッションに変数が存在するか確認
|
||||
pub fn has(&self, name: &str) -> bool {
|
||||
self.variables.contains_key(name)
|
||||
}
|
||||
|
||||
pub fn set_last_value(&mut self, value: VMValue) {
|
||||
self.last_value = Some(value.clone());
|
||||
self.variables.insert("_".to_string(), value);
|
||||
}
|
||||
|
||||
pub fn reset(&mut self) {
|
||||
self.variables.clear();
|
||||
self.last_value = None;
|
||||
self.eval_count = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user