diff --git a/schala-lang/src/ast_reducing.rs b/schala-lang/src/ast_reducing.rs index a15a1d7..cae1716 100644 --- a/schala-lang/src/ast_reducing.rs +++ b/schala-lang/src/ast_reducing.rs @@ -1,9 +1,11 @@ use std::rc::Rc; -use parsing::AST; +use parsing::{AST, Expression, Declaration}; +#[derive(Debug)] pub struct ReducedAST(pub Vec); +#[derive(Debug)] pub enum Stmt { Binding { name: Rc, @@ -12,6 +14,7 @@ pub enum Stmt { Expr(Expr), } +#[derive(Debug)] pub enum Expr { Literal(Lit), Func(Func), @@ -21,18 +24,34 @@ pub enum Expr { }, } +#[derive(Debug)] pub enum Lit { Int(u64), Bool(bool), StringLit(Rc), } +#[derive(Debug)] pub struct Func { params: Vec>, body: Vec, } - -pub fn perform_ast_reduction(input: &AST) -> Result { - Ok(ReducedAST(vec![])) +pub fn perform_ast_reduction(ast: &AST) -> Result { + use parsing::Statement::*; + let mut output = vec![]; + for statement in ast.0.iter() { + match statement { + &ExpressionStatement(ref expr) => output.push(reduce_expr(expr)?), + &Declaration(ref decl) => output.push(reduce_decl(decl)?), + } + } + Ok(ReducedAST(output)) +} + +fn reduce_expr(expr: &Expression) -> Result { + Ok(Stmt::Expr(Expr::Literal(Lit::Int(0)))) +} +fn reduce_decl(expr: &Declaration) -> Result { + Ok(Stmt::Expr(Expr::Literal(Lit::Int(0)))) } diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index 58c3504..be25ded 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -95,6 +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 = ast_reducing::perform_ast_reduction(&input)?; + println!("REDUCED: {:?}", output); Ok((output, input)) }