Rename StateStack -> ScopeStack

This commit is contained in:
greg 2018-08-19 21:31:28 -07:00
parent 0d13b5e3bc
commit f00fee0e37
3 changed files with 13 additions and 14 deletions

View File

@ -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<String>, ValueEntry>,
values: ScopeStack<'a, Rc<String>, ValueEntry>,
symbol_table_handle: Rc<RefCell<SymbolTable>>,
}
@ -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<RefCell<SymbolTable>>) -> 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);

View File

@ -10,7 +10,7 @@ use itertools::Itertools;
*/
use ast;
use util::StateStack;
use util::ScopeStack;
use symbol_table::{SymbolSpec, SymbolTable};
pub type TypeName = Rc<String>;
@ -80,14 +80,14 @@ impl TypeEnv {
}
pub struct TypeContext<'a> {
values: StateStack<'a, TypeName, Type>,
values: ScopeStack<'a, TypeName, Type>,
symbol_table_handle: Rc<RefCell<SymbolTable>>,
global_env: TypeEnv
}
impl<'a> TypeContext<'a> {
pub fn new(symbol_table_handle: Rc<RefCell<SymbolTable>>) -> 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 {

View File

@ -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<T, V>,
scope_name: Option<String>
}
impl<'a, T, V> StateStack<'a, T, V> where T: Hash + Eq {
pub fn new(name: Option<String>) -> 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<String>) -> 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<String>) -> StateStack<'a, T, V> where T: Hash + Eq {
StateStack {
pub fn new_scope(&'a self, name: Option<String>) -> ScopeStack<'a, T, V> where T: Hash + Eq {
ScopeStack {
parent: Some(self),
values: HashMap::default(),
scope_name: name,