2025-09-15 22:14:42 +09:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
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::parser::NyashParser;
|
2025-09-15 22:14:42 +09:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn vm_exec_simple_break() {
|
|
|
|
|
let code = r#"
|
|
|
|
|
loop(1) {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
return 1
|
|
|
|
|
"#;
|
|
|
|
|
let ast = NyashParser::parse_from_string(code).expect("parse");
|
|
|
|
|
let mut compiler = crate::mir::MirCompiler::new();
|
|
|
|
|
let result = compiler.compile(ast).expect("compile");
|
|
|
|
|
let mut vm = VM::new();
|
|
|
|
|
let out = vm.execute_module(&result.module).expect("vm exec");
|
|
|
|
|
assert_eq!(out.to_string_box().value, "1");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn vm_exec_continue_skips_body() {
|
2025-11-29 11:24:39 +09:00
|
|
|
// Phase 59b: Stage-3 parser required for local variable declarations
|
|
|
|
|
std::env::set_var("NYASH_PARSER_STAGE3", "1");
|
|
|
|
|
std::env::set_var("HAKO_PARSER_STAGE3", "1");
|
|
|
|
|
|
2025-09-15 22:14:42 +09:00
|
|
|
let code = r#"
|
|
|
|
|
local i = 0
|
|
|
|
|
local s = 0
|
|
|
|
|
loop(i < 5) {
|
|
|
|
|
i = i + 1
|
|
|
|
|
if i == 3 { continue }
|
|
|
|
|
s = s + 1
|
|
|
|
|
}
|
|
|
|
|
return s
|
|
|
|
|
"#;
|
|
|
|
|
let ast = NyashParser::parse_from_string(code).expect("parse");
|
|
|
|
|
let mut compiler = crate::mir::MirCompiler::new();
|
|
|
|
|
let result = compiler.compile(ast).expect("compile");
|
|
|
|
|
let mut vm = VM::new();
|
|
|
|
|
let out = vm.execute_module(&result.module).expect("vm exec");
|
|
|
|
|
assert_eq!(out.to_string_box().value, "4");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn vm_exec_break_inside_if() {
|
2025-11-29 11:24:39 +09:00
|
|
|
// Phase 59b: Stage-3 parser required for local variable declarations
|
|
|
|
|
std::env::set_var("NYASH_PARSER_STAGE3", "1");
|
|
|
|
|
std::env::set_var("HAKO_PARSER_STAGE3", "1");
|
|
|
|
|
|
2025-09-15 22:14:42 +09:00
|
|
|
let code = r#"
|
|
|
|
|
local i = 0
|
|
|
|
|
loop(i < 10) {
|
|
|
|
|
if i == 3 { break }
|
|
|
|
|
i = i + 1
|
|
|
|
|
}
|
|
|
|
|
return i
|
|
|
|
|
"#;
|
|
|
|
|
let ast = NyashParser::parse_from_string(code).expect("parse");
|
|
|
|
|
let mut compiler = crate::mir::MirCompiler::new();
|
|
|
|
|
let result = compiler.compile(ast).expect("compile");
|
|
|
|
|
let mut vm = VM::new();
|
|
|
|
|
let out = vm.execute_module(&result.module).expect("vm exec");
|
|
|
|
|
assert_eq!(out.to_string_box().value, "3");
|
|
|
|
|
}
|
|
|
|
|
}
|