[fine] A wild VM appears!

Untested though
This commit is contained in:
John Doty 2024-01-14 09:28:05 -08:00
parent 53f18e729b
commit 866830b485
8 changed files with 464 additions and 26 deletions

View file

@ -2,6 +2,7 @@ use fine::compiler::{compile, Function, Module};
use fine::parser::SyntaxTree;
use fine::semantics::{check, Error, Semantics, Type};
use fine::tokens::Lines;
use fine::vm::{eval, Context};
use pretty_assertions::assert_eq;
use std::fmt::Write as _;
@ -258,4 +259,23 @@ fn assert_no_errors(tree: &SyntaxTree, lines: &Lines) {
);
}
#[allow(dead_code)]
fn assert_eval_ok(tree: &SyntaxTree, lines: &Lines, expected: &str) {
let semantics = Semantics::new(tree, lines);
let module = compile(&semantics);
let main_function = module.functions[module.init].clone();
let mut context = Context::new(module.clone());
match eval(&mut context, main_function, vec![]) {
Ok(v) => {
let actual = format!("{:?}", v);
semantic_assert_eq!(&semantics, None, expected, &actual, "module evaluated");
}
Err(e) => {
semantic_panic!(&semantics, None, "error occurred while running: {:?}", e);
}
}
}
include!(concat!(env!("OUT_DIR"), "/generated_tests.rs"));