Infrastructure to evaluate reduced AST

This commit is contained in:
greg 2018-05-09 02:27:57 -07:00
parent 0bb0ecea76
commit 774ddd665b
3 changed files with 53 additions and 2 deletions

View File

@ -1,2 +1,38 @@
use std::rc::Rc;
pub struct ReducedAST { }
use parsing::AST;
pub struct ReducedAST(pub Vec<Stmt>);
pub enum Stmt {
Binding {
name: Rc<String>,
expr: Expr,
},
Expr(Expr),
}
pub enum Expr {
Literal(Lit),
Func(Func),
Call {
f: Func,
args: Vec<Expr>,
},
}
pub enum Lit {
Int(u64),
Bool(bool),
StringLit(Rc<String>),
}
pub struct Func {
params: Vec<Rc<String>>,
body: Vec<Stmt>,
}
pub fn perform_ast_reduction(input: &AST) -> Result<ReducedAST, String> {
Ok(ReducedAST(vec![]))
}

View File

@ -5,6 +5,7 @@ use std::fmt::Write;
use itertools::Itertools;
use parsing::{AST, Statement, Declaration, Expression, Variant, ExpressionType};
use ast_reducing::ReducedAST;
use builtin::{BinOp, PrefixOp};
pub struct State<'a> {
@ -315,3 +316,11 @@ impl<'a> State<'a> {
})
}
}
/* BELOW HERE NEW STUFF */
impl<'a> State<'a> {
pub fn evaluate_new(&mut self, input: ReducedAST) -> Result<String, String> {
Ok("not done".to_string())
}
}

View File

@ -94,10 +94,16 @@ 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> {
Ok((ast_reducing::ReducedAST { }, input))
let output = ast_reducing::perform_ast_reduction(&input)?;
Ok((output, input))
}
fn eval(handle: &mut Schala, input: TempASTReduction, _comp: Option<&mut UnfinishedComputation>) -> Result<String, String> {
let new_input = input.0;
let _new_eval_output = handle.state.evaluate_new(new_input);
/* old-style eval */
let input = input.1;
let evaluation_outputs = handle.state.evaluate(input);
let text_output: Result<Vec<String>, String> = evaluation_outputs