refactor(joinir): Split ast_lowerer and join_ir_vm_bridge into modules
ast_lowerer.rs → ast_lowerer/ (10 files): - mod.rs: public surface + entry dispatch - context.rs: ExtractCtx helpers - expr.rs: expression-to-JoinIR extraction - if_return.rs: simple if→Select lowering - loop_patterns.rs: loop variants (simple/break/continue) - read_quoted.rs: read_quoted_from lowering (Phase 45-46) - nested_if.rs: NestedIfMerge lowering - analysis.rs: loop if-var analysis + metadata helpers - tests.rs: frontend lowering tests - README.md: module documentation join_ir_vm_bridge.rs → join_ir_vm_bridge/ (5 files): - mod.rs: public surface + shared helpers - convert.rs: JoinIR→MIR lowering - runner.rs: VM execution entry (run_joinir_via_vm) - meta.rs: experimental metadata-aware hooks - tests.rs: bridge-specific unit tests - README.md: module documentation Benefits: - Clear separation of concerns per pattern - Easier navigation and maintenance - Each file has single responsibility - README documents module boundaries Co-authored-by: ChatGPT <noreply@openai.com> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
73
src/mir/join_ir_vm_bridge/mod.rs
Normal file
73
src/mir/join_ir_vm_bridge/mod.rs
Normal file
@ -0,0 +1,73 @@
|
||||
//! Phase 27-shortterm S-4: JoinIR → Rust VM Bridge
|
||||
//!
|
||||
//! 目的: JoinIR(正規化された IR)を Rust VM で実行するブリッジ層
|
||||
//!
|
||||
//! ## Architecture
|
||||
//! ```text
|
||||
//! JoinIR (normalized) → MirModule → Rust VM → Result
|
||||
//! ↑ ↑ ↑
|
||||
//! PHI bugs VM input Execution
|
||||
//! eliminated format (GC, plugins)
|
||||
//! ```
|
||||
//!
|
||||
//! ## Design Principles
|
||||
//! - JoinIR の正規化構造を保持したまま VM に渡す
|
||||
//! - マッピングだけで済ませる(JoinIR でやった正規化は消えない)
|
||||
//! - VM の機能(GC、プラグイン、エラーハンドリング)を活用
|
||||
//!
|
||||
//! ## Minimal Instruction Set (S-4.3)
|
||||
//! - **Compute**: Const, BinOp, Compare
|
||||
//! - **BoxCall**: StringBox メソッド呼び出し
|
||||
//! - **Call/Jump/Ret**: 制御フロー
|
||||
//!
|
||||
//! Phase 27-shortterm scope: skip_ws で green 化できれば成功
|
||||
|
||||
use crate::backend::VMError;
|
||||
use crate::mir::join_ir::JoinFuncId;
|
||||
|
||||
#[macro_use]
|
||||
mod logging {
|
||||
macro_rules! debug_log {
|
||||
($($arg:tt)*) => {
|
||||
if crate::config::env::joinir_vm_bridge_debug() {
|
||||
eprintln!($($arg)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
mod convert;
|
||||
mod meta;
|
||||
mod runner;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub(crate) use convert::{convert_join_function_to_mir, convert_joinir_to_mir};
|
||||
pub use meta::convert_join_module_to_mir_with_meta;
|
||||
pub use runner::run_joinir_via_vm;
|
||||
|
||||
/// Phase 27-shortterm S-4 エラー型
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct JoinIrVmBridgeError {
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl JoinIrVmBridgeError {
|
||||
pub fn new(msg: impl Into<String>) -> Self {
|
||||
Self {
|
||||
message: msg.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<VMError> for JoinIrVmBridgeError {
|
||||
fn from(err: VMError) -> Self {
|
||||
JoinIrVmBridgeError::new(format!("VM error: {:?}", err))
|
||||
}
|
||||
}
|
||||
|
||||
/// JoinFuncId から MIR 用の関数名を生成
|
||||
pub(crate) fn join_func_name(id: JoinFuncId) -> String {
|
||||
format!("join_func_{}", id.0)
|
||||
}
|
||||
Reference in New Issue
Block a user