Separate the IR evaluator, add an interesting stack-breaking case.
This commit is contained in:
@@ -120,15 +120,6 @@ proptest::proptest! {
|
||||
#[test]
|
||||
fn static_backend(program in Program::arbitrary()) {
|
||||
use crate::eval::PrimOpError;
|
||||
|
||||
let basic_result = program.eval().map(|(_,x)| x);
|
||||
|
||||
// windows `printf` is going to terminate lines with "\r\n", so we need to adjust
|
||||
// our test result here.
|
||||
#[cfg(target_family="windows")]
|
||||
let basic_result = basic_result.map(|x| x.replace('\n', "\r\n"));
|
||||
|
||||
if !matches!(basic_result, Err(EvalError::PrimOp(PrimOpError::MathFailure(_)))) {
|
||||
use pretty::DocAllocator;
|
||||
let allocator = pretty::Arena::new();
|
||||
let result = allocator.text("-------------")
|
||||
@@ -138,6 +129,28 @@ proptest::proptest! {
|
||||
result.render_raw(70, &mut pretty::IoWrite::new(std::io::stdout()))
|
||||
.expect("rendering works");
|
||||
|
||||
|
||||
eprintln!("BEFORE EVAL");
|
||||
let ir_evaluator = crate::ir::Evaluator::default();
|
||||
let basic_result = ir_evaluator.eval(program.clone()).map(|(_,o)| o);
|
||||
eprintln!("AFTER EVAL");
|
||||
|
||||
// windows `printf` is going to terminate lines with "\r\n", so we need to adjust
|
||||
// our test result here.
|
||||
#[cfg(target_family="windows")]
|
||||
let basic_result = basic_result.map(|x| x.replace('\n', "\r\n"));
|
||||
|
||||
if !matches!(basic_result, Err(EvalError::PrimOp(PrimOpError::MathFailure(_)))) {
|
||||
//use pretty::DocAllocator;
|
||||
//let allocator = pretty::Arena::new();
|
||||
//let result = allocator.text("-------------")
|
||||
// .append(allocator.line())
|
||||
// .append(program.pretty(&allocator))
|
||||
// .append(allocator.line());
|
||||
//result.render_raw(70, &mut pretty::IoWrite::new(std::io::stdout()))
|
||||
// .expect("rendering works");
|
||||
|
||||
eprintln!("BEFORE OM EVAL");
|
||||
let compiled_result = Backend::<ObjectModule>::eval(program);
|
||||
proptest::prop_assert_eq!(basic_result, compiled_result);
|
||||
}
|
||||
@@ -159,7 +172,8 @@ proptest::proptest! {
|
||||
// .render_colored(70, pretty::termcolor::StandardStream::stdout(pretty::termcolor::ColorChoice::Auto))
|
||||
// .expect("rendering works");
|
||||
|
||||
let basic_result = program.eval().map(|(_,x)| x);
|
||||
let ir_evaluator = crate::ir::Evaluator::default();
|
||||
let basic_result = ir_evaluator.eval(program.clone()).map(|(_,o)| o);
|
||||
|
||||
if !matches!(basic_result, Err(EvalError::PrimOp(PrimOpError::MathFailure(_)))) {
|
||||
let compiled_result = Backend::<JITModule>::eval(program);
|
||||
|
||||
@@ -500,7 +500,7 @@ impl<M: Module> Backend<M> {
|
||||
.into_iter()
|
||||
.unzip();
|
||||
|
||||
match *function {
|
||||
match function {
|
||||
ValueOrRef::Value(_, _, _) => {
|
||||
panic!("Can't use a value for a function")
|
||||
}
|
||||
@@ -568,10 +568,7 @@ impl<M: Module> Backend<M> {
|
||||
|
||||
Primitive::Negate => {
|
||||
assert_eq!(1, arguments.len());
|
||||
Ok((
|
||||
builder.ins().ineg(arguments[0]),
|
||||
argument_types[0],
|
||||
))
|
||||
Ok((builder.ins().ineg(arguments[0]), argument_types[0]))
|
||||
}
|
||||
|
||||
Primitive::Print => {
|
||||
|
||||
Reference in New Issue
Block a user