2025-11-28 17:42:19 +09:00
|
|
|
|
//! 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;
|
2025-12-05 14:41:24 +09:00
|
|
|
|
// Phase 190: Modular converters
|
2025-12-11 20:54:33 +09:00
|
|
|
|
mod bridge;
|
2025-12-05 14:41:24 +09:00
|
|
|
|
mod joinir_block_converter;
|
2025-12-11 20:54:33 +09:00
|
|
|
|
mod joinir_function_converter;
|
2025-11-28 17:42:19 +09:00
|
|
|
|
mod meta;
|
2025-12-11 22:12:46 +09:00
|
|
|
|
#[cfg(feature = "normalized_dev")]
|
|
|
|
|
|
mod normalized_bridge;
|
2025-11-28 17:42:19 +09:00
|
|
|
|
mod runner;
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
|
mod tests;
|
|
|
|
|
|
|
2025-12-05 14:41:24 +09:00
|
|
|
|
// Phase 190: Use modularized converters
|
2025-12-11 20:54:33 +09:00
|
|
|
|
pub(crate) use bridge::{bridge_joinir_to_mir, bridge_joinir_to_mir_with_meta};
|
|
|
|
|
|
#[allow(unused_imports)]
|
2025-12-05 14:41:24 +09:00
|
|
|
|
pub(crate) use convert::convert_joinir_to_mir;
|
|
|
|
|
|
pub(crate) use convert::convert_mir_like_inst; // helper for sub-modules
|
|
|
|
|
|
pub(crate) use joinir_function_converter::JoinIrFunctionConverter;
|
2025-12-16 07:02:14 +09:00
|
|
|
|
pub use meta::convert_join_module_to_mir_with_meta;
|
2025-12-11 22:12:46 +09:00
|
|
|
|
#[cfg(feature = "normalized_dev")]
|
|
|
|
|
|
pub(crate) use normalized_bridge::lower_normalized_to_mir_minimal;
|
2025-11-28 17:42:19 +09:00
|
|
|
|
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)
|
|
|
|
|
|
}
|