Phase 12: 統一TypeBox ABI実装開始 - ChatGPT5による極小コアABI基盤構築
- TypeBox ABI雛形: メソッドスロット管理システム追加 - Type Registry: Array/Map/StringBoxの基本メソッド定義 - Host API: C ABI逆呼び出しシステム実装 - Phase 12ドキュメント整理: 設計文書統合・アーカイブ化 - MIR Builder: クリーンアップと分離実装完了 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
44
src/tests/identical_exec.rs
Normal file
44
src/tests/identical_exec.rs
Normal file
@ -0,0 +1,44 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::mir::{MirModule, MirFunction, FunctionSignature};
|
||||
use crate::mir::{BasicBlockId, MirInstruction, ConstValue, EffectMask, MirType, BinaryOp};
|
||||
use crate::backend::VM;
|
||||
|
||||
fn make_add_main(a: i64, b: i64) -> MirModule {
|
||||
let sig = FunctionSignature {
|
||||
name: "main".to_string(),
|
||||
params: vec![],
|
||||
return_type: MirType::Integer,
|
||||
effects: EffectMask::PURE,
|
||||
};
|
||||
let mut func = MirFunction::new(sig, BasicBlockId::new(0));
|
||||
let bb = func.entry_block;
|
||||
let v0 = func.next_value_id();
|
||||
func.get_block_mut(bb).unwrap().add_instruction(MirInstruction::Const { dst: v0, value: ConstValue::Integer(a) });
|
||||
let v1 = func.next_value_id();
|
||||
func.get_block_mut(bb).unwrap().add_instruction(MirInstruction::Const { dst: v1, value: ConstValue::Integer(b) });
|
||||
let v2 = func.next_value_id();
|
||||
func.get_block_mut(bb).unwrap().add_instruction(MirInstruction::BinOp { dst: v2, op: BinaryOp::Add, lhs: v0, rhs: v1 });
|
||||
func.get_block_mut(bb).unwrap().add_instruction(MirInstruction::Return { value: Some(v2) });
|
||||
let mut module = MirModule::new("identical".to_string());
|
||||
module.add_function(func);
|
||||
module
|
||||
}
|
||||
|
||||
#[cfg(feature = "cranelift-jit")]
|
||||
#[test]
|
||||
fn identical_vm_and_jit_add() {
|
||||
let module = make_add_main(7, 35);
|
||||
// Run VM
|
||||
let mut vm = VM::new();
|
||||
let vm_out = vm.execute_module(&module).expect("VM exec");
|
||||
let vm_s = vm_out.to_string_box().value;
|
||||
|
||||
// Run JIT (Cranelift minimal)
|
||||
let jit_out = crate::backend::cranelift_compile_and_execute(&module, "identical_jit").expect("JIT exec");
|
||||
let jit_s = jit_out.to_string_box().value;
|
||||
|
||||
assert_eq!(vm_s, jit_s, "VM and JIT results should match");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user