build_boot for tests

This commit is contained in:
2023-11-07 21:59:05 -06:00
parent f03f6f15a4
commit 62d340e507
7 changed files with 132 additions and 3 deletions
+2 -1
View File
@@ -7,4 +7,5 @@ edition = "2021"
[dependencies]
vcore = { path = "../vcore" }
vasm_core = { path = "../vasm_core" }
vasm_core = { path = "../vasm_core" }
forge_core = { path = "../forge_core" }
+45
View File
@@ -0,0 +1,45 @@
use vasm_core::assemble_snippet;
use vcore::memory::{Memory, PeekPokeExt};
use vcore::word::Word;
use vcore::CPU;
fn run_forge(src: &str) -> CPU {
let asm = forge_core::compiler::build_boot(src).unwrap();
let bin = assemble_snippet(asm).unwrap();
let mut cpu = CPU::new(Memory::with_program(bin));
cpu.run_to_halt();
cpu
}
fn main_return(src: &str) -> i32 {
let mut cpu = run_forge(src);
cpu.pop_data().into()
}
#[test]
fn basic_forge_test() {
assert_eq!(
main_return("fn main() { return 2 + 3; }"),
5
)
}
// TODO The reason this fails is that functions don't copy their args to the frame when they enter.
// The fix is for fns to know their arity and to do that copy before the body, probably as some
// subroutine call itself (push frame, push arity, call blah, which is written in asm)
// #[test]
// fn loop_test() {
// assert_eq!(
// main_return(
// "fn triangle(rows) {
// var total = 0;
// repeat (rows) n {
// total = total + (n + 1);
// }
// return total;
// }
//
// fn main() { return triangle(5); }"),
// 15
// )
// }
+1
View File
@@ -1,2 +1,3 @@
#[cfg(test)]
mod integration_tests;
mod forge_tests;