WIP ISA Unit tests
Some checks failed
per-push tests / test-frontend (push) Blocked by required conditions
per-push tests / timed-decomposer-parse (push) Blocked by required conditions
per-push tests / test-utility (push) Blocked by required conditions
per-push tests / test-backend (push) Blocked by required conditions
per-push tests / build (push) Has been cancelled
Some checks failed
per-push tests / test-frontend (push) Blocked by required conditions
per-push tests / timed-decomposer-parse (push) Blocked by required conditions
per-push tests / test-utility (push) Blocked by required conditions
per-push tests / test-backend (push) Blocked by required conditions
per-push tests / build (push) Has been cancelled
Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
parent
609e65a8db
commit
ee1f680485
1 changed files with 28 additions and 114 deletions
142
hyphae/src/vm.rs
142
hyphae/src/vm.rs
|
|
@ -588,120 +588,9 @@ impl VM {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use core::array;
|
||||
use super::*;
|
||||
use crate::instr;
|
||||
|
||||
const ISA_TESTS: [Option<Vec<(VM, TestResult)>>; instr::TOTAL_INSTRUCTIONS] = [
|
||||
// TRAP
|
||||
None,
|
||||
// BIND
|
||||
None,
|
||||
// UNBIND
|
||||
None,
|
||||
// BOUND
|
||||
None,
|
||||
// PUSH
|
||||
None,
|
||||
// POP
|
||||
None,
|
||||
// ENTER
|
||||
None,
|
||||
// EXIT
|
||||
None,
|
||||
// LOAD
|
||||
None,
|
||||
// DUPL
|
||||
None,
|
||||
// CLEAR
|
||||
None,
|
||||
// NOP
|
||||
None,
|
||||
// HALT
|
||||
None,
|
||||
// PANIC
|
||||
None,
|
||||
// JMP
|
||||
None,
|
||||
// JMPIF
|
||||
None,
|
||||
// EQ
|
||||
None,
|
||||
// LT
|
||||
None,
|
||||
// GT
|
||||
None,
|
||||
// LTE
|
||||
None,
|
||||
// GTE
|
||||
None,
|
||||
// BOOL_NOT
|
||||
None,
|
||||
// BOOL_AND
|
||||
None,
|
||||
// BOOL_OR
|
||||
None,
|
||||
// BYTE_AND
|
||||
None,
|
||||
// BYTE_OR
|
||||
None,
|
||||
// XOR
|
||||
None,
|
||||
// BYTE_NOT
|
||||
None,
|
||||
// ADD
|
||||
None,
|
||||
// SUB
|
||||
None,
|
||||
// MUL
|
||||
None,
|
||||
// FDIV
|
||||
None,
|
||||
// IDIV
|
||||
None,
|
||||
// POW
|
||||
None,
|
||||
// MODULO
|
||||
None,
|
||||
// REM
|
||||
None,
|
||||
// INC
|
||||
None,
|
||||
// DEC
|
||||
None,
|
||||
// CTON
|
||||
None,
|
||||
// NTOC
|
||||
None,
|
||||
// NTOI
|
||||
None,
|
||||
// NTOE
|
||||
None,
|
||||
// CONST
|
||||
None,
|
||||
// MKVEC
|
||||
None,
|
||||
// MKBVEC
|
||||
None,
|
||||
// INDEX
|
||||
None,
|
||||
// LENGTH
|
||||
None,
|
||||
// SUBSL
|
||||
None,
|
||||
// INSER
|
||||
None,
|
||||
// CONS
|
||||
None,
|
||||
// CAR
|
||||
None,
|
||||
// CDR
|
||||
None,
|
||||
// CONCAT
|
||||
None,
|
||||
// S_APPEND
|
||||
None,
|
||||
];
|
||||
use crate::instr as i;
|
||||
use crate::util::{Program, Instruction, Operand};
|
||||
|
||||
fn has_stack(state: &VM, idx: usize, target: Gc<Datum>) -> bool {
|
||||
*(state.stack[idx]) == *target
|
||||
|
|
@ -763,9 +652,34 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn add_trap_tests(tests: &mut [Option<Vec<(VM, TestResult)>>]) {
|
||||
tests[i::TRAP.0 as usize] = Some(vec![
|
||||
// call a trap function and check its output
|
||||
(VM::from(Program(vec![
|
||||
Instruction(i::TRAP, vec![Operand(Address::Numer, 0)])
|
||||
])).with_traps(Some(vec![
|
||||
Arc::from(|state: &mut VM| {
|
||||
state.expr = Datum::Bool(true).into()
|
||||
})
|
||||
])).to_owned(),
|
||||
|
||||
TestResult{
|
||||
expr: Some(Datum::Bool(true).into()),
|
||||
stack: vec![],
|
||||
syms: vec![],
|
||||
errr: None,
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_isa_tests() {
|
||||
for i in &ISA_TESTS.to_vec() {
|
||||
let mut isa_tests: [Option<Vec<(VM, TestResult)>>; i::TOTAL_INSTRUCTIONS] =
|
||||
array::from_fn(|_| None);
|
||||
|
||||
add_trap_tests(&mut isa_tests);
|
||||
|
||||
for i in &isa_tests.to_vec() {
|
||||
let Some(test_case) = i else {
|
||||
assert!(false); // dont let untested instructions happen
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue