Some work

This commit is contained in:
greg 2018-05-11 00:25:43 -07:00
parent 16a463b1a0
commit 87c3b8e234
2 changed files with 14 additions and 11 deletions

View File

@ -5,7 +5,7 @@ use std::fmt::Write;
use itertools::Itertools; use itertools::Itertools;
use parsing::{AST, Statement, Declaration, Expression, Variant, ExpressionType}; use parsing::{AST, Statement, Declaration, Expression, Variant, ExpressionType};
use ast_reducing::ReducedAST; use ast_reducing::{ReducedAST, Stmt, Expr, Lit};
use builtin::{BinOp, PrefixOp}; use builtin::{BinOp, PrefixOp};
pub struct State<'a> { pub struct State<'a> {
@ -319,18 +319,21 @@ impl<'a> State<'a> {
/* BELOW HERE NEW STUFF */ /* BELOW HERE NEW STUFF */
impl Expr {
fn to_repl(&self) -> String {
format!("{:?}", self)
}
}
impl<'a> State<'a> { impl<'a> State<'a> {
pub fn evaluate_new(&mut self, ast: ReducedAST) -> Vec<Result<String, String>> { pub fn evaluate_new(&mut self, ast: ReducedAST, repl: bool) -> Vec<Result<String, String>> {
use ast_reducing::*; use ast_reducing::*;
let mut acc = vec![]; let mut acc = vec![];
for statement in ast.0 { for statement in ast.0 {
match self.eval_statement_new(statement) { match self.statement(statement) {
Ok(output) => { Ok(Some(ref output)) if repl => acc.push(Ok(output.to_repl())),
if let Some(fully_evaluated) = output { Ok(_) => (),
acc.push(Ok(fully_evaluated/*.to_string()*/));
}
},
Err(error) => { Err(error) => {
acc.push(Err(format!("Eval error: {}", error))); acc.push(Err(format!("Eval error: {}", error)));
return acc; return acc;
@ -340,7 +343,7 @@ impl<'a> State<'a> {
acc acc
} }
fn eval_statement_new(&mut self, stmt: ::ast_reducing::Stmt) -> Result<Option<String>, String> { fn statement(&mut self, stmt: ::ast_reducing::Stmt) -> Result<Option<Expr>, String> {
Ok(Some(format!("stmt - {:?}", stmt))) Ok(Some(Expr::Lit(Lit::Int(1))))
} }
} }

View File

@ -103,7 +103,7 @@ fn ast_reducing(handle: &mut Schala, input: parsing::AST, comp: Option<&mut Unfi
fn eval(handle: &mut Schala, input: TempASTReduction, _comp: Option<&mut UnfinishedComputation>) -> Result<String, String> { fn eval(handle: &mut Schala, input: TempASTReduction, _comp: Option<&mut UnfinishedComputation>) -> Result<String, String> {
let new_input = input.0; let new_input = input.0;
let new_eval_output = handle.state.evaluate_new(new_input); let new_eval_output = handle.state.evaluate_new(new_input, true);
match new_eval_output[0] { match new_eval_output[0] {
Ok(ref s) => println!("NEW OUTPUT> {}", s), Ok(ref s) => println!("NEW OUTPUT> {}", s),
Err(ref e) => println!("NEW ERR> {}", e), Err(ref e) => println!("NEW ERR> {}", e),