116 lines
2.2 KiB
Rust
116 lines
2.2 KiB
Rust
#![allow(unused)]
|
|
|
|
extern crate test;
|
|
|
|
use bumpalo::Bump;
|
|
use gc_arena::Arena;
|
|
use hashbrown::{HashMap, HashSet};
|
|
|
|
use inkwell::context::Context;
|
|
|
|
use ecow::EcoString;
|
|
use rpds::vector_sync;
|
|
|
|
use crate::builtins::env;
|
|
use crate::compile::compile;
|
|
use crate::ir::downgrade;
|
|
use crate::jit::JITContext;
|
|
use crate::ty::common::Const;
|
|
use crate::ty::public::*;
|
|
use crate::vm::VM;
|
|
|
|
#[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(), vm.bump.alloc(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));
|
|
test_expr("let f = _: 1; in (f 1) == (f 1)", boolean!(true));
|
|
}
|
|
|
|
#[test]
|
|
fn test_arith() {
|
|
test_expr("let f = _: -(-1); in (f 1) + (f 1)", int!(2));
|
|
}
|