mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Disable eval for now
This commit is contained in:
parent
6abec2b0f2
commit
38a4ac5c5c
4 changed files with 100 additions and 99 deletions
13
src/eval.rs
13
src/eval.rs
|
@ -1,6 +1,7 @@
|
|||
use expr::{Expr, Operator, Pattern, Ident};
|
||||
use expr::{Expr, Pattern, Ident};
|
||||
use expr::Pattern::*;
|
||||
use expr::Operator::*;
|
||||
use operator::Operator::*;
|
||||
use operator::Operator;
|
||||
use std::rc::Rc;
|
||||
use std::fmt;
|
||||
use im_rc::hashmap::HashMap;
|
||||
|
@ -52,7 +53,7 @@ pub fn scoped_eval(expr: Expr, vars: &Scope) -> Evaluated {
|
|||
Expr::Str(string) => Str(string),
|
||||
Expr::Frac(numerator, denominator) => Frac(fraction_from_i64s(numerator, denominator)),
|
||||
Expr::Char(ch) => Char(ch),
|
||||
Expr::Closure(args, body) => Closure(args, body, vars.clone()),
|
||||
Expr::Closure(args, body) => Closure(args.into_iter().map(|e| e.value).collect(), Box::new(body.value), vars.clone()),
|
||||
Expr::EmptyRecord => EmptyRecord,
|
||||
|
||||
// Resolve variable names
|
||||
|
@ -65,7 +66,7 @@ pub fn scoped_eval(expr: Expr, vars: &Scope) -> Evaluated {
|
|||
let mut output = String::new();
|
||||
|
||||
for (string, var_name) in pairs.into_iter() {
|
||||
match vars.get(&var_name) {
|
||||
match vars.get(&var_name.value) {
|
||||
Some(resolved) => {
|
||||
match **resolved {
|
||||
Str(ref var_string) => {
|
||||
|
@ -73,11 +74,11 @@ pub fn scoped_eval(expr: Expr, vars: &Scope) -> Evaluated {
|
|||
output.push_str(var_string.as_str());
|
||||
},
|
||||
_ => {
|
||||
return EvalError(TypeMismatch(var_name));
|
||||
return EvalError(TypeMismatch(var_name.value));
|
||||
}
|
||||
}
|
||||
},
|
||||
None => { return EvalError(UnrecognizedVarName(var_name)); }
|
||||
None => { return EvalError(UnrecognizedVarName(var_name.value)); }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
pub mod expr;
|
||||
pub mod parse;
|
||||
pub mod parse_state;
|
||||
pub mod eval;
|
||||
// pub mod eval;
|
||||
pub mod fast_fraction;
|
||||
// mod ena;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use expr::Operator;
|
||||
use operator::Operator;
|
||||
use expr::{Expr, Pattern, Ident};
|
||||
|
||||
use std::char;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#[macro_use] extern crate pretty_assertions;
|
||||
// #[macro_use] extern crate pretty_assertions;
|
||||
extern crate combine;
|
||||
extern crate fraction;
|
||||
|
||||
|
@ -6,102 +6,102 @@ extern crate roc;
|
|||
|
||||
#[cfg(test)]
|
||||
mod test_eval {
|
||||
use roc::expr::Operator::*;
|
||||
use roc::expr::Pattern::*;
|
||||
use roc::expr::Expr::*;
|
||||
use roc::eval::eval;
|
||||
use roc::eval::Evaluated;
|
||||
use fraction::Fraction;
|
||||
// use roc::operator::Operator::*;
|
||||
// use roc::expr::Pattern::*;
|
||||
// use roc::expr::Expr::*;
|
||||
// use roc::eval::eval;
|
||||
// use roc::eval::Evaluated;
|
||||
// use fraction::Fraction;
|
||||
|
||||
#[test]
|
||||
fn one_plus_one() {
|
||||
assert_eq!(
|
||||
eval(Operator(Box::new(Int(1)), Plus, Box::new(Int(1)))),
|
||||
Evaluated::Int(2)
|
||||
);
|
||||
}
|
||||
// #[test]
|
||||
// fn one_plus_one() {
|
||||
// assert_eq!(
|
||||
// eval(Operator(Box::new(Int(1)), Plus, Box::new(Int(1)))),
|
||||
// Evaluated::Int(2)
|
||||
// );
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn point_one_plus_point_two() {
|
||||
// 0.1 + 0.2 == 0.3 THAT'S WHAT'S UP
|
||||
assert_eq!(
|
||||
eval(Operator(Box::new(Frac(1, 10)), Plus, Box::new(Frac(2, 10)))),
|
||||
Evaluated::Frac(Fraction::new(3u64, 10u64))
|
||||
);
|
||||
}
|
||||
// #[test]
|
||||
// fn point_one_plus_point_two() {
|
||||
// // 0.1 + 0.2 == 0.3 THAT'S WHAT'S UP
|
||||
// assert_eq!(
|
||||
// eval(Operator(Box::new(Frac(1, 10)), Plus, Box::new(Frac(2, 10)))),
|
||||
// Evaluated::Frac(Fraction::new(3u64, 10u64))
|
||||
// );
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn addition_reduces() {
|
||||
assert_eq!(
|
||||
eval(Operator(Box::new(Frac(1, 3)), Plus, Box::new(Frac(7, 14)))),
|
||||
Evaluated::Frac(Fraction::new(5u64, 6u64))
|
||||
);
|
||||
}
|
||||
// #[test]
|
||||
// fn addition_reduces() {
|
||||
// assert_eq!(
|
||||
// eval(Operator(Box::new(Frac(1, 3)), Plus, Box::new(Frac(7, 14)))),
|
||||
// Evaluated::Frac(Fraction::new(5u64, 6u64))
|
||||
// );
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn division_reduces() {
|
||||
assert_eq!(
|
||||
eval(Operator(Box::new(Frac(1, 3)), Slash, Box::new(Frac(7, 14)))),
|
||||
Evaluated::ApplyVariant(
|
||||
"Ok".to_string(),
|
||||
Some(vec![Evaluated::Frac(Fraction::new(2u64, 3u64))])
|
||||
)
|
||||
);
|
||||
}
|
||||
// #[test]
|
||||
// fn division_reduces() {
|
||||
// assert_eq!(
|
||||
// eval(Operator(Box::new(Frac(1, 3)), Slash, Box::new(Frac(7, 14)))),
|
||||
// Evaluated::ApplyVariant(
|
||||
// "Ok".to_string(),
|
||||
// Some(vec![Evaluated::Frac(Fraction::new(2u64, 3u64))])
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn division_by_zero() {
|
||||
assert_eq!(
|
||||
eval(Operator(Box::new(Frac(1, 10)), Slash, Box::new(Frac(0, 10)))),
|
||||
Evaluated::ApplyVariant(
|
||||
"Err".to_string(),
|
||||
Some(vec![Evaluated::ApplyVariant("DivisionByZero".to_string(), None)])
|
||||
)
|
||||
);
|
||||
}
|
||||
// #[test]
|
||||
// fn division_by_zero() {
|
||||
// assert_eq!(
|
||||
// eval(Operator(Box::new(Frac(1, 10)), Slash, Box::new(Frac(0, 10)))),
|
||||
// Evaluated::ApplyVariant(
|
||||
// "Err".to_string(),
|
||||
// Some(vec![Evaluated::ApplyVariant("DivisionByZero".to_string(), None)])
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn string_interpolation() {
|
||||
assert_eq!(
|
||||
eval(
|
||||
Assign(Identifier("foo".to_string()), Box::new(Str("one".to_string())),
|
||||
Box::new(Assign(Identifier("bar".to_string()), Box::new(Str("two".to_string())),
|
||||
Box::new(Assign(Identifier("baz".to_string()), Box::new(Str("three".to_string())),
|
||||
Box::new(InterpolatedStr(
|
||||
// "hi_\(foo)_\(bar)_\(baz)_string!"
|
||||
vec![
|
||||
("hi_".to_string(), "foo".to_string()),
|
||||
("_".to_string(), "bar".to_string()),
|
||||
("_".to_string(), "baz".to_string()),
|
||||
],
|
||||
"_string!".to_string()
|
||||
))
|
||||
)))))
|
||||
),
|
||||
Evaluated::Str("hi_one_two_three_string!".to_string())
|
||||
);
|
||||
}
|
||||
// #[test]
|
||||
// fn string_interpolation() {
|
||||
// assert_eq!(
|
||||
// eval(
|
||||
// Assign(Identifier("foo".to_string()), Box::new(Str("one".to_string())),
|
||||
// Box::new(Assign(Identifier("bar".to_string()), Box::new(Str("two".to_string())),
|
||||
// Box::new(Assign(Identifier("baz".to_string()), Box::new(Str("three".to_string())),
|
||||
// Box::new(InterpolatedStr(
|
||||
// // "hi_\(foo)_\(bar)_\(baz)_string!"
|
||||
// vec![
|
||||
// ("hi_".to_string(), "foo".to_string()),
|
||||
// ("_".to_string(), "bar".to_string()),
|
||||
// ("_".to_string(), "baz".to_string()),
|
||||
// ],
|
||||
// "_string!".to_string()
|
||||
// ))
|
||||
// )))))
|
||||
// ),
|
||||
// Evaluated::Str("hi_one_two_three_string!".to_string())
|
||||
// );
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn if_else() {
|
||||
assert_eq!(
|
||||
eval(
|
||||
If(Box::new(ApplyVariant("True".to_string(), None)),
|
||||
Box::new(Operator(Box::new(Int(1)), Plus, Box::new(Int(2)))),
|
||||
Box::new(Operator(Box::new(Int(4)), Plus, Box::new(Int(5))))
|
||||
)
|
||||
),
|
||||
Evaluated::Int(3)
|
||||
);
|
||||
// #[test]
|
||||
// fn if_else() {
|
||||
// assert_eq!(
|
||||
// eval(
|
||||
// If(Box::new(ApplyVariant("True".to_string(), None)),
|
||||
// Box::new(Operator(Box::new(Int(1)), Plus, Box::new(Int(2)))),
|
||||
// Box::new(Operator(Box::new(Int(4)), Plus, Box::new(Int(5))))
|
||||
// )
|
||||
// ),
|
||||
// Evaluated::Int(3)
|
||||
// );
|
||||
|
||||
assert_eq!(
|
||||
eval(
|
||||
If(Box::new(ApplyVariant("False".to_string(), None)),
|
||||
Box::new(Operator(Box::new(Int(1)), Plus, Box::new(Int(2)))),
|
||||
Box::new(Operator(Box::new(Int(4)), Plus, Box::new(Int(5))))
|
||||
)
|
||||
),
|
||||
Evaluated::Int(9)
|
||||
);
|
||||
}
|
||||
// assert_eq!(
|
||||
// eval(
|
||||
// If(Box::new(ApplyVariant("False".to_string(), None)),
|
||||
// Box::new(Operator(Box::new(Int(1)), Plus, Box::new(Int(2)))),
|
||||
// Box::new(Operator(Box::new(Int(4)), Plus, Box::new(Int(5))))
|
||||
// )
|
||||
// ),
|
||||
// Evaluated::Int(9)
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue