feat: JIT (WIP)
This commit is contained in:
96
src/jit/test.rs
Normal file
96
src/jit/test.rs
Normal file
@@ -0,0 +1,96 @@
|
||||
extern crate test;
|
||||
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
|
||||
use inkwell::context::Context;
|
||||
|
||||
use ecow::EcoString;
|
||||
use rpds::vector_sync;
|
||||
|
||||
use crate::compile::compile;
|
||||
use crate::ir::downgrade;
|
||||
use crate::ty::public::*;
|
||||
use crate::ty::common::Const;
|
||||
use crate::jit::JITContext;
|
||||
use crate::vm::VM;
|
||||
use crate::builtins::env;
|
||||
|
||||
|
||||
#[inline]
|
||||
fn test_expr(expr: &str, expected: Value) {
|
||||
let downgraded = downgrade(rnix::Root::parse(expr).tree().expr().unwrap()).unwrap();
|
||||
let prog = compile(downgraded);
|
||||
dbg!(&prog);
|
||||
let ctx = Context::create();
|
||||
let jit = JITContext::new(&ctx);
|
||||
let vm = VM::new(prog.thunks, prog.funcs, prog.symbols.into(), prog.symmap.into(), prog.consts, jit);
|
||||
let env = env(&vm);
|
||||
let value = vm.eval(prog.top_level.into_iter(), env).unwrap().to_public(&vm, &mut HashSet::new());
|
||||
assert_eq!(value, expected);
|
||||
}
|
||||
|
||||
macro_rules! map {
|
||||
($($k:expr => $v:expr),*) => {
|
||||
{
|
||||
#[allow(unused_mut)]
|
||||
let mut m = HashMap::new();
|
||||
$(
|
||||
m.insert($k, $v);
|
||||
)*
|
||||
m
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! thunk {
|
||||
() => {
|
||||
Value::Thunk
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! int {
|
||||
($e:expr) => {
|
||||
Value::Const(Const::Int($e))
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! float {
|
||||
($e:expr) => {
|
||||
Value::Const(Const::Float($e as f64))
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! boolean {
|
||||
($e:expr) => {
|
||||
Value::Const(Const::Bool($e))
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! string {
|
||||
($e:expr) => {
|
||||
Value::Const(Const::String(EcoString::from($e)))
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! symbol {
|
||||
($e:expr) => {
|
||||
Symbol::from($e.to_string())
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! list {
|
||||
($($x:tt)*) => (
|
||||
Value::List(List::new(vector_sync![$($x)*]))
|
||||
);
|
||||
}
|
||||
|
||||
macro_rules! attrs {
|
||||
($($x:tt)*) => (
|
||||
Value::AttrSet(AttrSet::new(map!{$($x)*}))
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_jit_const() {
|
||||
test_expr("let f = _: 1; in (f 1) + (f 1)", int!(2));
|
||||
}
|
||||
Reference in New Issue
Block a user