Start AST-reducing
This commit is contained in:
parent
774ddd665b
commit
6c718e5d4f
@ -1,9 +1,11 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use parsing::AST;
|
||||
use parsing::{AST, Expression, Declaration};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ReducedAST(pub Vec<Stmt>);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Stmt {
|
||||
Binding {
|
||||
name: Rc<String>,
|
||||
@ -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<String>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Func {
|
||||
params: Vec<Rc<String>>,
|
||||
body: Vec<Stmt>,
|
||||
}
|
||||
|
||||
|
||||
pub fn perform_ast_reduction(input: &AST) -> Result<ReducedAST, String> {
|
||||
Ok(ReducedAST(vec![]))
|
||||
pub fn perform_ast_reduction(ast: &AST) -> Result<ReducedAST, String> {
|
||||
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<Stmt, String> {
|
||||
Ok(Stmt::Expr(Expr::Literal(Lit::Int(0))))
|
||||
}
|
||||
fn reduce_decl(expr: &Declaration) -> Result<Stmt, String> {
|
||||
Ok(Stmt::Expr(Expr::Literal(Lit::Int(0))))
|
||||
}
|
||||
|
@ -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<TempASTReduction, String> {
|
||||
let output = ast_reducing::perform_ast_reduction(&input)?;
|
||||
println!("REDUCED: {:?}", output);
|
||||
Ok((output, input))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user