From bd1eed884fe47654c161266929fd846ae20ca4e4 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 11 May 2018 01:56:12 -0700 Subject: [PATCH] State type manipulations --- schala-lang/src/eval.rs | 24 +++++++++++++----------- schala-lang/src/util.rs | 7 +++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 5d24af6..e88bf00 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -4,14 +4,20 @@ use std::fmt::Write; use itertools::Itertools; -use parsing::{AST, Statement, Declaration, Expression, Variant, ExpressionType}; +use util::StateStack; use ast_reducing::{ReducedAST, Stmt, Expr, Lit, Func}; use builtin::{BinOp, PrefixOp}; pub struct State<'a> { - parent_frame: Option<&'a State<'a>>, - values: HashMap, ValueEntry>, + values: StateStack<'a, Rc, ValueEntry> } + +impl<'a> State<'a> { + pub fn new() -> State<'a> { + State { values: StateStack::new(Some(format!("global"))) } + } +} + /* impl<'a> State<'a> { @@ -32,16 +38,19 @@ impl<'a> State<'a> { #[derive(Debug)] enum ValueEntry { Binding { - val: FullyEvaluatedExpr, + val: /*FullyEvaluatedExpr*/ Expr, }, + /* Function { param_names: Vec>, body: Vec, } + */ } type EvalResult = Result; +/* #[derive(Debug, PartialEq, Clone)] enum FullyEvaluatedExpr { UnsignedInt(u64), @@ -57,7 +66,6 @@ enum FullyEvaluatedExpr { List(Vec) } -/* impl FullyEvaluatedExpr { fn to_string(&self) -> String { use self::FullyEvaluatedExpr::*; @@ -98,12 +106,6 @@ impl FullyEvaluatedExpr { } */ -impl<'a> State<'a> { - pub fn new() -> State<'a> { - State { parent_frame: None, values: HashMap::new() } - } -} - /* pub fn new_with_parent(parent: &'a State<'a>) -> State<'a> { diff --git a/schala-lang/src/util.rs b/schala-lang/src/util.rs index 2289e9e..33217f3 100644 --- a/schala-lang/src/util.rs +++ b/schala-lang/src/util.rs @@ -10,6 +10,13 @@ pub struct StateStack<'a, T: 'a, V: 'a> where T: Hash + Eq { } impl<'a, T, V> StateStack<'a, T, V> where T: Hash + Eq { + pub fn new(name: Option) -> StateStack<'a, T, V> where T: Hash + Eq { + StateStack { + parent: None, + values: HashMap::new(), + scope_name: name + } + } pub fn insert(&mut self, key: T, value: V) where T: Hash + Eq { self.values.insert(key, value); }