diff --git a/schala-lang/src/ast_reducing.rs b/schala-lang/src/ast_reducing.rs index b44295a..4492d1f 100644 --- a/schala-lang/src/ast_reducing.rs +++ b/schala-lang/src/ast_reducing.rs @@ -23,6 +23,7 @@ pub enum Expr { f: Func, args: Vec, }, + UnimplementedSigilValue } #[derive(Debug)] @@ -44,51 +45,50 @@ pub enum Func { } impl AST { - pub fn reduce(&self) -> Result { + pub fn reduce(&self) -> ReducedAST { use parsing::Statement::*; let mut output = vec![]; for statement in self.0.iter() { match statement { - &ExpressionStatement(ref expr) => output.push(Stmt::Expr(expr.reduce()?)), - &Declaration(ref decl) => output.push(decl.reduce()?), + &ExpressionStatement(ref expr) => output.push(Stmt::Expr(expr.reduce())), + &Declaration(ref decl) => output.push(decl.reduce()), } } - Ok(ReducedAST(output)) + ReducedAST(output) } } impl Expression { - fn reduce(&self) -> Result { + fn reduce(&self) -> Expr { use parsing::ExpressionType::*; let ref input = self.0; - let output_expr = match input { + match input { &IntLiteral(ref n) => Expr::Lit(Lit::Nat(*n)), //TODO I should rename IntLiteral if I want the Nat/Int distinction, which I do &FloatLiteral(ref f) => Expr::Lit(Lit::Float(*f)), &StringLiteral(ref s) => Expr::Lit(Lit::StringLit(s.clone())), &BoolLiteral(ref b) => Expr::Lit(Lit::Bool(*b)), - &BinExp(ref binop, ref lhs, ref rhs) => binop.reduce(lhs, rhs)?, - &PrefixExp(ref op, ref arg) => op.reduce(arg)?, - e => return Err(format!("{:?} not implemented in reduction", e)) - }; - Ok(output_expr) + &BinExp(ref binop, ref lhs, ref rhs) => binop.reduce(lhs, rhs), + &PrefixExp(ref op, ref arg) => op.reduce(arg), + e => Expr::UnimplementedSigilValue, + } } } impl Declaration { - fn reduce(&self) -> Result { - Ok(Stmt::Expr(Expr::Lit(Lit::Int(0)))) + fn reduce(&self) -> Stmt { + Stmt::Expr(Expr::UnimplementedSigilValue) } } impl BinOp { - fn reduce(&self, lhs: &Box, rhs: &Box) -> Result { + fn reduce(&self, lhs: &Box, rhs: &Box) -> Expr { let f = Func::BuiltIn(self.sigil().clone()); - Ok(Expr::Call { f, args: vec![lhs.reduce()?, rhs.reduce()?]}) + Expr::Call { f, args: vec![lhs.reduce(), rhs.reduce()]} } } impl PrefixOp { - fn reduce(&self, arg: &Box) -> Result { - Err(format!("NOTDONE")) + fn reduce(&self, arg: &Box) -> Expr { + Expr::UnimplementedSigilValue } } diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index b344fd1..c0b6180 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -95,8 +95,7 @@ fn typechecking(handle: &mut Schala, input: parsing::AST, comp: Option<&mut Unfi type TempASTReduction = (ast_reducing::ReducedAST, parsing::AST); fn ast_reducing(handle: &mut Schala, input: parsing::AST, comp: Option<&mut UnfinishedComputation>) -> Result { - let output = input.reduce()?; - println!("REDUCED: {:?}", output); + let output = input.reduce(); Ok((output, input)) } @@ -106,8 +105,8 @@ fn eval(handle: &mut Schala, input: TempASTReduction, _comp: Option<&mut Unfinis 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), - } + Err(ref s) => println!("NEW Err> {}", s), + }; /* old-style eval */ let input = input.1;