Rename StateStack -> ScopeStack
This commit is contained in:
parent
0d13b5e3bc
commit
f00fee0e37
@ -6,12 +6,12 @@ use std::io;
|
|||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use util::StateStack;
|
use util::ScopeStack;
|
||||||
use reduced_ast::{ReducedAST, Stmt, Expr, Lit, Func};
|
use reduced_ast::{ReducedAST, Stmt, Expr, Lit, Func};
|
||||||
use symbol_table::{SymbolSpec, Symbol, SymbolTable};
|
use symbol_table::{SymbolSpec, Symbol, SymbolTable};
|
||||||
|
|
||||||
pub struct State<'a> {
|
pub struct State<'a> {
|
||||||
values: StateStack<'a, Rc<String>, ValueEntry>,
|
values: ScopeStack<'a, Rc<String>, ValueEntry>,
|
||||||
symbol_table_handle: Rc<RefCell<SymbolTable>>,
|
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
|
//TODO add a more concise way of getting a new frame
|
||||||
impl<'a> State<'a> {
|
impl<'a> State<'a> {
|
||||||
pub fn new(symbol_table_handle: Rc<RefCell<SymbolTable>>) -> 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!("print", values);
|
||||||
builtin_binding!("println", values);
|
builtin_binding!("println", values);
|
||||||
builtin_binding!("getline", values);
|
builtin_binding!("getline", values);
|
||||||
|
@ -10,7 +10,7 @@ use itertools::Itertools;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use ast;
|
use ast;
|
||||||
use util::StateStack;
|
use util::ScopeStack;
|
||||||
use symbol_table::{SymbolSpec, SymbolTable};
|
use symbol_table::{SymbolSpec, SymbolTable};
|
||||||
|
|
||||||
pub type TypeName = Rc<String>;
|
pub type TypeName = Rc<String>;
|
||||||
@ -80,14 +80,14 @@ impl TypeEnv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct TypeContext<'a> {
|
pub struct TypeContext<'a> {
|
||||||
values: StateStack<'a, TypeName, Type>,
|
values: ScopeStack<'a, TypeName, Type>,
|
||||||
symbol_table_handle: Rc<RefCell<SymbolTable>>,
|
symbol_table_handle: Rc<RefCell<SymbolTable>>,
|
||||||
global_env: TypeEnv
|
global_env: TypeEnv
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TypeContext<'a> {
|
impl<'a> TypeContext<'a> {
|
||||||
pub fn new(symbol_table_handle: Rc<RefCell<SymbolTable>>) -> TypeContext<'static> {
|
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 {
|
pub fn debug_types(&self) -> String {
|
||||||
|
@ -2,17 +2,16 @@ use std::collections::HashMap;
|
|||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::cmp::Eq;
|
use std::cmp::Eq;
|
||||||
|
|
||||||
//TODO rename this ScopeStack
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub struct StateStack<'a, T: 'a, V: 'a> where T: Hash + Eq {
|
pub struct ScopeStack<'a, T: 'a, V: 'a> where T: Hash + Eq {
|
||||||
parent: Option<&'a StateStack<'a, T, V>>,
|
parent: Option<&'a ScopeStack<'a, T, V>>,
|
||||||
values: HashMap<T, V>,
|
values: HashMap<T, V>,
|
||||||
scope_name: Option<String>
|
scope_name: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T, V> StateStack<'a, T, V> where T: Hash + Eq {
|
impl<'a, T, V> ScopeStack<'a, T, V> where T: Hash + Eq {
|
||||||
pub fn new(name: Option<String>) -> StateStack<'a, T, V> where T: Hash + Eq {
|
pub fn new(name: Option<String>) -> ScopeStack<'a, T, V> where T: Hash + Eq {
|
||||||
StateStack {
|
ScopeStack {
|
||||||
parent: None,
|
parent: None,
|
||||||
values: HashMap::new(),
|
values: HashMap::new(),
|
||||||
scope_name: name
|
scope_name: name
|
||||||
@ -29,8 +28,8 @@ impl<'a, T, V> StateStack<'a, T, V> where T: Hash + Eq {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO rename new_scope
|
//TODO rename new_scope
|
||||||
pub fn new_scope(&'a self, name: Option<String>) -> StateStack<'a, T, V> where T: Hash + Eq {
|
pub fn new_scope(&'a self, name: Option<String>) -> ScopeStack<'a, T, V> where T: Hash + Eq {
|
||||||
StateStack {
|
ScopeStack {
|
||||||
parent: Some(self),
|
parent: Some(self),
|
||||||
values: HashMap::default(),
|
values: HashMap::default(),
|
||||||
scope_name: name,
|
scope_name: name,
|
||||||
|
Loading…
Reference in New Issue
Block a user