diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index e88bf00..d6f32ba 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -18,6 +18,21 @@ impl<'a> State<'a> { } } +#[derive(Debug)] +enum ValueEntry { + Binding { + val: /*FullyEvaluatedExpr*/ Expr, + }, + /* + Function { + param_names: Vec>, + body: Vec, + } + */ +} + +type EvalResult = Result; + /* impl<'a> State<'a> { @@ -35,20 +50,6 @@ impl<'a> State<'a> { } */ -#[derive(Debug)] -enum ValueEntry { - Binding { - val: /*FullyEvaluatedExpr*/ Expr, - }, - /* - Function { - param_names: Vec>, - body: Vec, - } - */ -} - -type EvalResult = Result; /* #[derive(Debug, PartialEq, Clone)] @@ -363,7 +364,7 @@ impl<'a> State<'a> { acc } - fn statement(&mut self, stmt: Stmt) -> Result, String> { + fn statement(&mut self, stmt: Stmt) -> EvalResult> { match stmt { Stmt::Binding { .. } => { //TODO mutate some state here @@ -373,7 +374,7 @@ impl<'a> State<'a> { } } - fn expression(&mut self, expr: Expr) -> Result { + fn expression(&mut self, expr: Expr) -> EvalResult { use self::Expr::*; match expr { literal @ Lit(_) => Ok(literal), @@ -382,7 +383,7 @@ impl<'a> State<'a> { } } - fn apply_function(&mut self, f: Func, args: Vec) -> Result { + fn apply_function(&mut self, f: Func, args: Vec) -> EvalResult { match f { Func::BuiltIn(sigil) => self.apply_builtin(sigil, args), Func::UserDefined { params, body } => { @@ -391,7 +392,7 @@ impl<'a> State<'a> { } } - fn apply_builtin(&mut self, name: Rc, args: Vec) -> Result { + fn apply_builtin(&mut self, name: Rc, args: Vec) -> EvalResult { use self::Expr::*; use self::Lit::*; let evaled_args: Result, String> = args.into_iter().map(|arg| self.expression(arg)).collect();