Use proper symbol_table lookup in eval

This commit is contained in:
greg 2019-08-30 19:03:52 -07:00
parent 16dc973aa6
commit f6dcd7f0b8
3 changed files with 14 additions and 7 deletions

View File

@ -8,7 +8,7 @@ use itertools::Itertools;
use crate::util::ScopeStack;
use crate::reduced_ast::{BoundVars, ReducedAST, Stmt, Expr, Lit, Func, Alternative, Subpattern};
use crate::symbol_table::{SymbolSpec, Symbol, SymbolTable};
use crate::symbol_table::{SymbolSpec, Symbol, SymbolTable, ScopeSegment, ScopeSegmentKind, FullyQualifiedSymbolName};
use crate::builtin::Builtin;
mod test;
@ -466,7 +466,7 @@ impl<'a> State<'a> {
//in the values table
let symbol_table = self.symbol_table_handle.borrow();
let value = symbol_table.lookup_by_name(&name);
let value = symbol_table.lookup_by_path(&fqsn!(name ; tr));
Ok(match value {
Some(Symbol { name, spec, .. }) => match spec {
//TODO I'll need this type_name later to do a table lookup

View File

@ -31,6 +31,7 @@ mod debugging;
mod tokenizing;
mod ast;
mod parsing;
#[macro_use]
mod symbol_table;
mod builtin;
mod reduced_ast;

View File

@ -12,7 +12,7 @@ type LineNumber = u32;
type SymbolTrackTable = HashMap<Rc<String>, LineNumber>;
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
pub struct FullyQualifiedSymbolName(Vec<ScopeSegment>);
pub struct FullyQualifiedSymbolName(pub Vec<ScopeSegment>);
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct ScopeSegment {
@ -20,6 +20,12 @@ pub struct ScopeSegment {
kind: ScopeSegmentKind,
}
impl ScopeSegment {
pub fn new(name: Rc<String>, kind: ScopeSegmentKind) -> ScopeSegment {
ScopeSegment { name, kind }
}
}
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum ScopeSegmentKind {
Function,
@ -33,10 +39,10 @@ macro_rules! fqsn {
{
let mut vec = vec![];
$(
vec.push(ScopeSegment {
name: Rc::new($name.to_string()),
kind: sym_path_kind!($kind),
});
vec.push(ScopeSegment::new(
Rc::new($name.to_string()),
sym_path_kind!($kind),
));
)*
FullyQualifiedSymbolName(vec)
}