2025-09-04 03:41:02 +09:00
|
|
|
use crate::backend::VM;
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
use crate::mir::MirCompiler;
|
|
|
|
|
use crate::parser::NyashParser;
|
2025-09-04 03:41:02 +09:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn lambda_value_then_call_returns_increment() {
|
|
|
|
|
// Nyash code:
|
|
|
|
|
// f = function(a) { return a + 1 }
|
|
|
|
|
// f(41)
|
|
|
|
|
let code = r#"
|
|
|
|
|
f = function(a) {
|
|
|
|
|
return a + 1
|
|
|
|
|
}
|
|
|
|
|
f(41)
|
|
|
|
|
"#;
|
|
|
|
|
let ast = NyashParser::parse_from_string(code).expect("parse");
|
|
|
|
|
let mut mc = MirCompiler::new();
|
|
|
|
|
let cr = mc.compile(ast).expect("mir");
|
|
|
|
|
// Execute on VM
|
|
|
|
|
let mut vm = VM::new();
|
|
|
|
|
let out = vm.execute_module(&cr.module).expect("vm exec");
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
// execute_module returns Box<dyn NyashBox>, so downcast to IntegerBox
|
|
|
|
|
use crate::box_trait::IntegerBox;
|
|
|
|
|
if let Some(ib) = out.as_any().downcast_ref::<IntegerBox>() {
|
|
|
|
|
assert_eq!(ib.value, 42);
|
|
|
|
|
} else {
|
|
|
|
|
panic!("Expected IntegerBox(42), got {:?}", out);
|
|
|
|
|
}
|
2025-09-04 03:41:02 +09:00
|
|
|
}
|