Phase 12: VM/JIT identical execution tests + host API slot routing
ChatGPT5による統一実行パス実装: - VM/JIT同一実行テスト追加(Array/Map/String/Instance) - host_api slot経由呼び出し(NYASH_JIT_HOST_BRIDGE=1) - extern_registry拡張(console系メソッドslot登録) - CI: vm-jit-identical.yml(STRICT/非STRICT両系テスト) - InstanceBox getField/setField slot 1,2統一 技術的改善: - JIT: ops_ext委譲による統一メソッド解決 - VM: vtable/PIC/名前ベースフォールバック階層 - host_bridge: TLV encode/decode BoxRef対応 - C ABI: nyrt_host_api.h外部公開ヘッダー テスト追加: - identical_exec_collections: Array/Map操作一致 - identical_exec_instance: ユーザー定義Box一致 - identical_exec_string: StringBox操作一致 - host_reverse_slot: 逆引きslot解決テスト 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
40
src/tests/identical_exec_string.rs
Normal file
40
src/tests/identical_exec_string.rs
Normal file
@ -0,0 +1,40 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::backend::VM;
|
||||
use crate::mir::{MirModule, MirFunction, FunctionSignature, BasicBlockId, MirInstruction, ConstValue, EffectMask, MirType};
|
||||
|
||||
fn make_string_len() -> MirModule {
|
||||
let mut module = MirModule::new("identical_string".to_string());
|
||||
let sig = FunctionSignature { name: "main".into(), params: vec![], return_type: MirType::Integer, effects: EffectMask::PURE };
|
||||
let mut f = MirFunction::new(sig, BasicBlockId::new(0));
|
||||
let bb = f.entry_block;
|
||||
let s = f.next_value_id();
|
||||
f.get_block_mut(bb).unwrap().add_instruction(MirInstruction::Const { dst: s, value: ConstValue::String("hello".into()) });
|
||||
let ln = f.next_value_id();
|
||||
f.get_block_mut(bb).unwrap().add_instruction(MirInstruction::BoxCall { dst: Some(ln), box_val: s, method: "len".into(), args: vec![], method_id: None, effects: EffectMask::PURE });
|
||||
f.get_block_mut(bb).unwrap().add_instruction(MirInstruction::Return { value: Some(ln) });
|
||||
module.add_function(f);
|
||||
module
|
||||
}
|
||||
|
||||
#[cfg(feature = "cranelift-jit")]
|
||||
#[test]
|
||||
fn identical_vm_and_jit_string_len() {
|
||||
// Prefer vtable on VM and host-bridge on JIT for parity
|
||||
std::env::set_var("NYASH_ABI_VTABLE", "1");
|
||||
std::env::set_var("NYASH_JIT_HOST_BRIDGE", "1");
|
||||
let module = make_string_len();
|
||||
|
||||
// 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;
|
||||
|
||||
// JIT
|
||||
let jit_out = crate::backend::cranelift_compile_and_execute(&module, "identical_string").expect("JIT exec");
|
||||
let jit_s = jit_out.to_string_box().value;
|
||||
|
||||
assert_eq!(vm_s, jit_s, "VM and JIT results should match for String.len");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user