Put type names into symbol table
This commit is contained in:
parent
97b59d7e70
commit
26fa4a29ec
@ -489,6 +489,7 @@ impl<'a> State<'a> {
|
||||
Some(Binding { val, .. }) => val.clone(),
|
||||
None => return Err(format!("Symbol {} exists in symbol table but not in evaluator table", name))
|
||||
}
|
||||
SymbolSpec::Type { name } => return Err(format!("Symbol {} not in scope", name)),
|
||||
},
|
||||
//TODO ideally this should be returning a runtime error if this is ever None, but it's not
|
||||
//handling all bindings correctly yet
|
||||
|
@ -145,7 +145,10 @@ pub enum SymbolSpec {
|
||||
members: HashMap<Rc<String>, TypeName>,
|
||||
type_name: TypeName,
|
||||
},
|
||||
Binding
|
||||
Binding,
|
||||
Type {
|
||||
name: TypeName
|
||||
},
|
||||
}
|
||||
|
||||
impl fmt::Display for SymbolSpec {
|
||||
@ -156,6 +159,7 @@ impl fmt::Display for SymbolSpec {
|
||||
DataConstructor { index, type_name, type_args } => write!(f, "DataConstructor(idx: {})({:?} -> {})", index, type_args, type_name),
|
||||
RecordConstructor { type_name, index, ..} => write!(f, "RecordConstructor(idx: {})(<members> -> {})", index, type_name),
|
||||
Binding => write!(f, "Binding"),
|
||||
Type { name } => write!(f, "Type <{}>", name),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -246,6 +250,13 @@ impl SymbolTable {
|
||||
use crate::ast::{TypeIdentifier, Variant};
|
||||
let TypeBody(variants) = body;
|
||||
let ref type_name = type_name.name;
|
||||
|
||||
|
||||
let type_spec = SymbolSpec::Type {
|
||||
name: type_name.clone(),
|
||||
};
|
||||
self.add_new_symbol(type_name, &scope_name_stack, type_spec);
|
||||
|
||||
scope_name_stack.push(ScopeSegment{
|
||||
name: type_name.clone(),
|
||||
kind: ScopeSegmentKind::Type,
|
||||
|
@ -21,7 +21,8 @@ macro_rules! values_in_table {
|
||||
|
||||
#[test]
|
||||
fn basic_symbol_table() {
|
||||
values_in_table! { "let a = 10; fn b() { 20 }", &fqsn!("b"; tr) }
|
||||
values_in_table! { "let a = 10; fn b() { 20 }", &fqsn!("b"; tr) };
|
||||
values_in_table! { "type Option<T> = Some(T) | None", &fqsn!("Option"; tr) };
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user