From 30128d7d344c5e65c753248d0f244c8217557c62 Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 9 May 2018 03:04:01 -0700 Subject: [PATCH] Easy work --- schala-lang/src/ast_reducing.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/schala-lang/src/ast_reducing.rs b/schala-lang/src/ast_reducing.rs index cae1716..77035f3 100644 --- a/schala-lang/src/ast_reducing.rs +++ b/schala-lang/src/ast_reducing.rs @@ -16,7 +16,7 @@ pub enum Stmt { #[derive(Debug)] pub enum Expr { - Literal(Lit), + Lit(Lit), Func(Func), Call { f: Func, @@ -50,8 +50,16 @@ pub fn perform_ast_reduction(ast: &AST) -> Result { } fn reduce_expr(expr: &Expression) -> Result { - Ok(Stmt::Expr(Expr::Literal(Lit::Int(0)))) + use parsing::ExpressionType::*; + let ref input = expr.0; + let output_expr = match input { + &IntLiteral(ref n) => Expr::Lit(Lit::Int(*n)), + &StringLiteral(ref s) => Expr::Lit(Lit::StringLit(s.clone())), + &BoolLiteral(ref b) => Expr::Lit(Lit::Bool(*b)), + e => return Err(format!("{:?} not implemented in reduction", e)) + }; + Ok(Stmt::Expr(output_expr)) } fn reduce_decl(expr: &Declaration) -> Result { - Ok(Stmt::Expr(Expr::Literal(Lit::Int(0)))) + Ok(Stmt::Expr(Expr::Lit(Lit::Int(0)))) }