From 774ddd665b574a0fd50d34f8038c26ea59ea63ae Mon Sep 17 00:00:00 2001 From: greg Date: Wed, 9 May 2018 02:27:57 -0700 Subject: [PATCH] Infrastructure to evaluate reduced AST --- schala-lang/src/ast_reducing.rs | 38 ++++++++++++++++++++++++++++++++- schala-lang/src/eval.rs | 9 ++++++++ schala-lang/src/lib.rs | 8 ++++++- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/schala-lang/src/ast_reducing.rs b/schala-lang/src/ast_reducing.rs index 6887b0c..a15a1d7 100644 --- a/schala-lang/src/ast_reducing.rs +++ b/schala-lang/src/ast_reducing.rs @@ -1,2 +1,38 @@ +use std::rc::Rc; -pub struct ReducedAST { } +use parsing::AST; + +pub struct ReducedAST(pub Vec); + +pub enum Stmt { + Binding { + name: Rc, + expr: Expr, + }, + Expr(Expr), +} + +pub enum Expr { + Literal(Lit), + Func(Func), + Call { + f: Func, + args: Vec, + }, +} + +pub enum Lit { + Int(u64), + Bool(bool), + StringLit(Rc), +} + +pub struct Func { + params: Vec>, + body: Vec, +} + + +pub fn perform_ast_reduction(input: &AST) -> Result { + Ok(ReducedAST(vec![])) +} diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 0dab7d0..b74797b 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -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 { + Ok("not done".to_string()) + } +} diff --git a/schala-lang/src/lib.rs b/schala-lang/src/lib.rs index f67fa5e..58c3504 100644 --- a/schala-lang/src/lib.rs +++ b/schala-lang/src/lib.rs @@ -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 { - 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 { + + 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, String> = evaluation_outputs