From f00fee0e37e42d969f5f8371095a36d496470bc2 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 19 Aug 2018 21:31:28 -0700 Subject: [PATCH] Rename StateStack -> ScopeStack --- schala-lang/src/eval.rs | 6 +++--- schala-lang/src/typechecking.rs | 6 +++--- schala-lang/src/util.rs | 15 +++++++-------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 3ae69a5..8315ed9 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -6,12 +6,12 @@ use std::io; use itertools::Itertools; -use util::StateStack; +use util::ScopeStack; use reduced_ast::{ReducedAST, Stmt, Expr, Lit, Func}; use symbol_table::{SymbolSpec, Symbol, SymbolTable}; pub struct State<'a> { - values: StateStack<'a, Rc, ValueEntry>, + values: ScopeStack<'a, Rc, ValueEntry>, symbol_table_handle: Rc>, } @@ -24,7 +24,7 @@ macro_rules! builtin_binding { //TODO add a more concise way of getting a new frame impl<'a> State<'a> { pub fn new(symbol_table_handle: Rc>) -> State<'a> { - let mut values = StateStack::new(Some(format!("global"))); + let mut values = ScopeStack::new(Some(format!("global"))); builtin_binding!("print", values); builtin_binding!("println", values); builtin_binding!("getline", values); diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index f8ce6bf..2d09d84 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -10,7 +10,7 @@ use itertools::Itertools; */ use ast; -use util::StateStack; +use util::ScopeStack; use symbol_table::{SymbolSpec, SymbolTable}; pub type TypeName = Rc; @@ -80,14 +80,14 @@ impl TypeEnv { } pub struct TypeContext<'a> { - values: StateStack<'a, TypeName, Type>, + values: ScopeStack<'a, TypeName, Type>, symbol_table_handle: Rc>, global_env: TypeEnv } impl<'a> TypeContext<'a> { pub fn new(symbol_table_handle: Rc>) -> TypeContext<'static> { - TypeContext { values: StateStack::new(None), global_env: TypeEnv::default(), symbol_table_handle } + TypeContext { values: ScopeStack::new(None), global_env: TypeEnv::default(), symbol_table_handle } } pub fn debug_types(&self) -> String { diff --git a/schala-lang/src/util.rs b/schala-lang/src/util.rs index e9df6b5..e0520ca 100644 --- a/schala-lang/src/util.rs +++ b/schala-lang/src/util.rs @@ -2,17 +2,16 @@ use std::collections::HashMap; use std::hash::Hash; use std::cmp::Eq; -//TODO rename this ScopeStack #[derive(Default, Debug)] -pub struct StateStack<'a, T: 'a, V: 'a> where T: Hash + Eq { - parent: Option<&'a StateStack<'a, T, V>>, +pub struct ScopeStack<'a, T: 'a, V: 'a> where T: Hash + Eq { + parent: Option<&'a ScopeStack<'a, T, V>>, values: HashMap, scope_name: Option } -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 { +impl<'a, T, V> ScopeStack<'a, T, V> where T: Hash + Eq { + pub fn new(name: Option) -> ScopeStack<'a, T, V> where T: Hash + Eq { + ScopeStack { parent: None, values: HashMap::new(), scope_name: name @@ -29,8 +28,8 @@ impl<'a, T, V> StateStack<'a, T, V> where T: Hash + Eq { } } //TODO rename new_scope - pub fn new_scope(&'a self, name: Option) -> StateStack<'a, T, V> where T: Hash + Eq { - StateStack { + pub fn new_scope(&'a self, name: Option) -> ScopeStack<'a, T, V> where T: Hash + Eq { + ScopeStack { parent: Some(self), values: HashMap::default(), scope_name: name,