feat: Add dual-mode design doc and VM/MIR improvements
- Add comprehensive dual-mode design document (script vs application mode) - Update phase 9.8 documentation with implementation progress - Enhance VM with improved error handling and debugging - Add MIR verification improvements - Add test cases for MIR/VM POC 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -44,6 +44,61 @@ mod tests {
|
||||
let _ = vm.execute_module(&module).expect("VM should execute module");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vm_exec_typeop_cast_int_float() {
|
||||
let mut func = make_main();
|
||||
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(3) });
|
||||
|
||||
let v1 = func.next_value_id();
|
||||
func.get_block_mut(bb).unwrap().add_instruction(MirInstruction::TypeOp { dst: v1, op: crate::mir::TypeOpKind::Cast, value: v0, ty: MirType::Float });
|
||||
func.get_block_mut(bb).unwrap().add_instruction(MirInstruction::Return { value: None });
|
||||
|
||||
let mut module = MirModule::new("test".to_string());
|
||||
module.add_function(func);
|
||||
let mut vm = VM::new();
|
||||
let _ = vm.execute_module(&module).expect("int->float cast should succeed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vm_exec_typeop_cast_float_int() {
|
||||
let mut func = make_main();
|
||||
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::Float(3.7) });
|
||||
|
||||
let v1 = func.next_value_id();
|
||||
func.get_block_mut(bb).unwrap().add_instruction(MirInstruction::TypeOp { dst: v1, op: crate::mir::TypeOpKind::Cast, value: v0, ty: MirType::Integer });
|
||||
func.get_block_mut(bb).unwrap().add_instruction(MirInstruction::Return { value: None });
|
||||
|
||||
let mut module = MirModule::new("test".to_string());
|
||||
module.add_function(func);
|
||||
let mut vm = VM::new();
|
||||
let _ = vm.execute_module(&module).expect("float->int cast should succeed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vm_exec_typeop_cast_invalid_should_error() {
|
||||
let mut func = make_main();
|
||||
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::String("x".to_string()) });
|
||||
|
||||
let v1 = func.next_value_id();
|
||||
func.get_block_mut(bb).unwrap().add_instruction(MirInstruction::TypeOp { dst: v1, op: crate::mir::TypeOpKind::Cast, value: v0, ty: MirType::Integer });
|
||||
func.get_block_mut(bb).unwrap().add_instruction(MirInstruction::Return { value: None });
|
||||
|
||||
let mut module = MirModule::new("test".to_string());
|
||||
module.add_function(func);
|
||||
let mut vm = VM::new();
|
||||
let res = vm.execute_module(&module);
|
||||
assert!(res.is_err(), "invalid cast should return error");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vm_exec_legacy_typecheck_cast() {
|
||||
let mut func = make_main();
|
||||
|
||||
Reference in New Issue
Block a user