diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 47818ef..332b562 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -5,7 +5,7 @@ use std::fmt::Write; use itertools::Itertools; use parsing::{AST, Statement, Declaration, Expression, Variant, ExpressionType}; -use ast_reducing::ReducedAST; +use ast_reducing::{ReducedAST, Stmt, Expr, Lit}; use builtin::{BinOp, PrefixOp}; pub struct State<'a> { @@ -319,18 +319,21 @@ impl<'a> State<'a> { /* BELOW HERE NEW STUFF */ +impl Expr { + fn to_repl(&self) -> String { + format!("{:?}", self) + } +} + impl<'a> State<'a> { - pub fn evaluate_new(&mut self, ast: ReducedAST) -> Vec> { + pub fn evaluate_new(&mut self, ast: ReducedAST, repl: bool) -> Vec> { use ast_reducing::*; let mut acc = vec![]; for statement in ast.0 { - match self.eval_statement_new(statement) { - Ok(output) => { - if let Some(fully_evaluated) = output { - acc.push(Ok(fully_evaluated/*.to_string()*/)); - } - }, + match self.statement(statement) { + Ok(Some(ref output)) if repl => acc.push(Ok(output.to_repl())), + Ok(_) => (), Err(error) => { acc.push(Err(format!("Eval error: {}", error))); return acc; @@ -340,7 +343,7 @@ impl<'a> State<'a> { acc } - fn eval_statement_new(&mut self, stmt: ::ast_reducing::Stmt) -> Result, String> { - Ok(Some(format!("stmt - {:?}", stmt))) + fn statement(&mut self, stmt: ::ast_reducing::Stmt) -> Result, String> { + Ok(Some(Expr::Lit(Lit::Int(1)))) } } diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index 2b228fc..b344fd1 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -103,7 +103,7 @@ fn ast_reducing(handle: &mut Schala, input: parsing::AST, comp: Option<&mut Unfi fn eval(handle: &mut Schala, input: TempASTReduction, _comp: Option<&mut UnfinishedComputation>) -> Result { let new_input = input.0; - let new_eval_output = handle.state.evaluate_new(new_input); + let new_eval_output = handle.state.evaluate_new(new_input, true); match new_eval_output[0] { Ok(ref s) => println!("NEW OUTPUT> {}", s), Err(ref e) => println!("NEW ERR> {}", e),