feat(phase-5.4): Update test files for MIR 26 instruction set

- Updated mir_phase7_async_ops.rs to use NewBox/BoxCall instead of FutureNew/Await
- Updated mir_phase6_vm_ref_ops.rs to use new instruction format
- Moved deprecated test wasm_poc2_box_operations.rs to archive

Part of Phase 5-4 completion
This commit is contained in:
Moe Charm
2025-08-17 14:41:52 +09:00
parent 2a762d94a1
commit dd6f237539
3 changed files with 47 additions and 31 deletions

View File

@ -6,10 +6,10 @@
use nyash_rust::mir::{ use nyash_rust::mir::{
MirModule, MirFunction, FunctionSignature, MirType, EffectMask, MirModule, MirFunction, FunctionSignature, MirType, EffectMask,
BasicBlock, BasicBlockId, ValueId, MirInstruction, ConstValue BasicBlock, BasicBlockId, ValueId, MirInstruction, ConstValue, AtomicOrdering
}; };
use nyash_rust::backend::{VM, VMValue}; use nyash_rust::backend::VM;
use nyash_rust::box_trait::{IntegerBox, NyashBox}; use nyash_rust::box_trait::IntegerBox;
#[test] #[test]
fn test_mir_phase6_vm_ref_ops() { fn test_mir_phase6_vm_ref_ops() {
@ -45,6 +45,7 @@ fn test_mir_phase6_vm_ref_ops() {
let obj_ref = ValueId::new(1); let obj_ref = ValueId::new(1);
let one_val = ValueId::new(2); let one_val = ValueId::new(2);
let x_val = ValueId::new(3); let x_val = ValueId::new(3);
let print_func = ValueId::new(4);
// Add instructions // Add instructions
@ -54,10 +55,18 @@ fn test_mir_phase6_vm_ref_ops() {
value: ConstValue::String("Obj".to_string()), value: ConstValue::String("Obj".to_string()),
}); });
// %1 = ref_new %0 // %4 = const "@print" (for intrinsic call)
block.add_instruction(MirInstruction::RefNew { block.add_instruction(MirInstruction::Const {
dst: print_func,
value: ConstValue::String("@print".to_string()),
});
// %1 = new Obj()
// Phase 5: RefNew is deprecated - use NewBox instead
block.add_instruction(MirInstruction::NewBox {
dst: obj_ref, dst: obj_ref,
box_val: obj_type_val, box_type: "Obj".to_string(),
args: vec![],
}); });
// %2 = const 1 // %2 = const 1
@ -66,28 +75,34 @@ fn test_mir_phase6_vm_ref_ops() {
value: ConstValue::Integer(1), value: ConstValue::Integer(1),
}); });
// barrier_write %1 // atomic_fence release
block.add_instruction(MirInstruction::BarrierWrite { // Phase 5: BarrierWrite is deprecated - use AtomicFence instead
ptr: obj_ref, block.add_instruction(MirInstruction::AtomicFence {
ordering: AtomicOrdering::Release,
}); });
// ref_set %1, "x", %2 // %1.x = %2
block.add_instruction(MirInstruction::RefSet { // Phase 5: RefSet is deprecated - use BoxFieldStore instead
reference: obj_ref, block.add_instruction(MirInstruction::BoxFieldStore {
box_val: obj_ref,
field: "x".to_string(), field: "x".to_string(),
value: one_val, value: one_val,
}); });
// %3 = ref_get %1, "x" // %3 = %1.x
block.add_instruction(MirInstruction::RefGet { // Phase 5: RefGet is deprecated - use BoxFieldLoad instead
block.add_instruction(MirInstruction::BoxFieldLoad {
dst: x_val, dst: x_val,
reference: obj_ref, box_val: obj_ref,
field: "x".to_string(), field: "x".to_string(),
}); });
// print %3 // call @print(%3)
block.add_instruction(MirInstruction::Print { // Phase 5: Print is deprecated - use Call @print instead
value: x_val, block.add_instruction(MirInstruction::Call {
dst: None,
func: print_func,
args: vec![x_val],
effects: EffectMask::IO, effects: EffectMask::IO,
}); });
@ -168,13 +183,14 @@ fn test_barrier_no_op() {
value: ConstValue::Integer(42), value: ConstValue::Integer(42),
}); });
// Test barrier instructions (should be no-ops) // Test atomic fence instructions (replace barriers)
block.add_instruction(MirInstruction::BarrierRead { // Phase 5: BarrierRead/BarrierWrite are deprecated - use AtomicFence
ptr: test_val, block.add_instruction(MirInstruction::AtomicFence {
ordering: AtomicOrdering::Acquire,
}); });
block.add_instruction(MirInstruction::BarrierWrite { block.add_instruction(MirInstruction::AtomicFence {
ptr: test_val, ordering: AtomicOrdering::Release,
}); });
block.add_instruction(MirInstruction::Return { block.add_instruction(MirInstruction::Return {

View File

@ -107,17 +107,17 @@ fn test_mir_phase7_basic_nowait_await() {
.flat_map(|block| &block.instructions) .flat_map(|block| &block.instructions)
.collect(); .collect();
// Should contain FutureNew instruction // Phase 5: FutureNew is deprecated - should contain NewBox "FutureBox" instead
let has_future_new = instructions.iter().any(|inst| { let has_future_box = instructions.iter().any(|inst| {
matches!(inst, nyash_rust::mir::MirInstruction::FutureNew { .. }) matches!(inst, nyash_rust::mir::MirInstruction::NewBox { box_type, .. } if box_type == "FutureBox")
}); });
assert!(has_future_new, "MIR should contain FutureNew instruction"); assert!(has_future_box, "MIR should contain NewBox FutureBox instruction");
// Should contain Await instruction // Phase 5: Await is deprecated - should contain BoxCall "await" instead
let has_await = instructions.iter().any(|inst| { let has_await_call = instructions.iter().any(|inst| {
matches!(inst, nyash_rust::mir::MirInstruction::Await { .. }) matches!(inst, nyash_rust::mir::MirInstruction::BoxCall { method, .. } if method == "await")
}); });
assert!(has_await, "MIR should contain Await instruction"); assert!(has_await_call, "MIR should contain BoxCall await instruction");
// Test VM execution // Test VM execution
let mut vm = VM::new(); let mut vm = VM::new();