vasm now supports files
This commit is contained in:
@@ -4,19 +4,19 @@ use vcore::memory::{Memory, PeekPokeExt};
|
||||
use vcore::word::Word;
|
||||
use vcore::CPU;
|
||||
|
||||
fn cpu_test<'a, T: IntoIterator<Item = &'a str>>(code: T) -> CPU {
|
||||
fn cpu_test<T: IntoIterator<Item = String>>(code: T) -> CPU {
|
||||
let bin = assemble_snippet(code).unwrap();
|
||||
let mut cpu = vcore::cpu::CPU::new(Memory::with_program(bin));
|
||||
cpu.run_to_halt();
|
||||
cpu
|
||||
}
|
||||
|
||||
fn test_stack<'a, T: IntoIterator<Item = &'a str>>(code: T, expected_stack: Vec<i32>) {
|
||||
fn test_stack<T: IntoIterator<Item = String>>(code: T, expected_stack: Vec<i32>) {
|
||||
let cpu = cpu_test(code);
|
||||
assert_eq!(cpu.get_stack(), expected_stack);
|
||||
}
|
||||
|
||||
fn test_rstack<'a, T: IntoIterator<Item = &'a str>>(
|
||||
fn test_rstack<T: IntoIterator<Item = String>>(
|
||||
code: T,
|
||||
expected_stack: Vec<i32>,
|
||||
expected_rstack: Vec<i32>,
|
||||
@@ -26,7 +26,7 @@ fn test_rstack<'a, T: IntoIterator<Item = &'a str>>(
|
||||
assert_eq!(cpu.get_call(), expected_rstack);
|
||||
}
|
||||
|
||||
fn test_mem<'a, T: IntoIterator<Item = &'a str>>(
|
||||
fn test_mem<T: IntoIterator<Item = String>>(
|
||||
code: T,
|
||||
expected_memory: BTreeMap<u32, u8>,
|
||||
) -> CPU {
|
||||
@@ -45,7 +45,7 @@ fn test_arithmetic() {
|
||||
push 2
|
||||
add 3
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![5],
|
||||
);
|
||||
|
||||
@@ -55,7 +55,7 @@ fn test_arithmetic() {
|
||||
push 7
|
||||
mul 1000
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![7000],
|
||||
);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ fn test_call_stack() {
|
||||
hlt
|
||||
blah: mul 2
|
||||
ret"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![6],
|
||||
);
|
||||
|
||||
@@ -81,7 +81,7 @@ fn test_call_stack() {
|
||||
pushr
|
||||
pushr
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![10],
|
||||
vec![3, 4],
|
||||
);
|
||||
@@ -95,7 +95,7 @@ fn test_call_stack() {
|
||||
popr
|
||||
add
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![10, 7],
|
||||
vec![20],
|
||||
);
|
||||
@@ -106,7 +106,7 @@ fn test_call_stack() {
|
||||
call blah
|
||||
blah: pushr 3
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![],
|
||||
vec![5, 0x406, 3],
|
||||
);
|
||||
@@ -120,7 +120,7 @@ fn test_call_stack() {
|
||||
popr
|
||||
popr
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![5, 20, 20, 10],
|
||||
vec![],
|
||||
)
|
||||
@@ -139,7 +139,7 @@ fn test_comparison() {
|
||||
push 10
|
||||
lt 5
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![0, 1, 1, 0],
|
||||
);
|
||||
|
||||
@@ -155,7 +155,7 @@ fn test_comparison() {
|
||||
push 10
|
||||
alt -5
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![0, 1, 1, 0],
|
||||
);
|
||||
|
||||
@@ -164,7 +164,7 @@ fn test_comparison() {
|
||||
not 10
|
||||
not 0
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![0, 1],
|
||||
)
|
||||
}
|
||||
@@ -177,7 +177,7 @@ fn test_pick() {
|
||||
nop 20
|
||||
pick 1
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![10, 20, 10],
|
||||
);
|
||||
|
||||
@@ -188,7 +188,7 @@ fn test_pick() {
|
||||
pick 2
|
||||
pick 5
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![10, 20, 0, 0],
|
||||
)
|
||||
}
|
||||
@@ -202,7 +202,7 @@ fn test_store() {
|
||||
push 0x123456
|
||||
storew 203
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
[(201, 10), (203, 0x56), (204, 0x34), (205, 0x12)].into(),
|
||||
);
|
||||
}
|
||||
@@ -216,7 +216,7 @@ fn test_load() {
|
||||
hlt
|
||||
.org 0x500
|
||||
.db 0x123456"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![0x34, 0x123456],
|
||||
)
|
||||
}
|
||||
@@ -231,7 +231,7 @@ fn test_rotate() {
|
||||
push 300
|
||||
rot
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![10, 200, 300, 100],
|
||||
)
|
||||
}
|
||||
@@ -244,7 +244,7 @@ fn test_sdp() {
|
||||
pushr 20
|
||||
sdp
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
vec![10, 1021, 265],
|
||||
)
|
||||
}
|
||||
@@ -262,7 +262,7 @@ fn test_underflow() {
|
||||
onunder: push 200
|
||||
store 10
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
[(10, 200)].into(),
|
||||
);
|
||||
|
||||
@@ -277,7 +277,7 @@ fn test_underflow() {
|
||||
onrunder: push 200
|
||||
store 10
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
[(10, 200)].into(),
|
||||
);
|
||||
|
||||
@@ -292,7 +292,7 @@ fn test_underflow() {
|
||||
onunder: push 200
|
||||
store 10
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
[(10, 200)].into(),
|
||||
);
|
||||
}
|
||||
@@ -311,7 +311,7 @@ fn test_div_zero() {
|
||||
ondiv0: push 200
|
||||
store 10
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
[(10, 200)].into(),
|
||||
);
|
||||
|
||||
@@ -327,7 +327,7 @@ fn test_div_zero() {
|
||||
ondiv0: push 200
|
||||
store 10
|
||||
hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
[(10, 200)].into(),
|
||||
);
|
||||
}
|
||||
@@ -348,7 +348,7 @@ fn test_overflow() {
|
||||
push 3 ; boom!
|
||||
store ; never happens
|
||||
onover: hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
[(16, 1), (19, 2)].into(), // expect the two successful pushes to be still there
|
||||
);
|
||||
|
||||
@@ -378,7 +378,7 @@ fn test_simple_overflow() {
|
||||
add 5 ; full stack + argument!
|
||||
store ; never happens
|
||||
onover: hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
[(16, 1), (19, 2)].into(), // expect the two successful pushes to be still there
|
||||
);
|
||||
|
||||
@@ -408,7 +408,7 @@ fn test_overflow_promotion() {
|
||||
div ; This is a div 0, but there's no room to handle it, so it's promoted to overflow
|
||||
store ; never happens
|
||||
onover: hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
[(16, 1), (19, 0)].into(), // expect the two successful pushes to be still there
|
||||
);
|
||||
|
||||
@@ -434,7 +434,7 @@ fn test_invalid_opcode() {
|
||||
.db 0xf6 ; this isn't an instruction!
|
||||
store ; never happens
|
||||
onop: hlt"
|
||||
.lines(),
|
||||
.lines().map(String::from),
|
||||
[(256, 1), (259, 2)].into(), // expect the two successful pushes to be still there
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user