SymbolTable: Add Record type
This commit is contained in:
parent
c225e469ee
commit
c0111e30bc
@ -482,6 +482,7 @@ impl<'a> State<'a> {
|
|||||||
},
|
},
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
},
|
},
|
||||||
|
SymbolSpec::RecordConstructor { .. } => return Err(format!("This shouldn't be a record!")),
|
||||||
},
|
},
|
||||||
/* see if it's an ordinary variable TODO make variables go in symbol table */
|
/* see if it's an ordinary variable TODO make variables go in symbol table */
|
||||||
None => match self.values.lookup(&name) {
|
None => match self.values.lookup(&name) {
|
||||||
|
@ -44,6 +44,9 @@ pub enum SymbolSpec {
|
|||||||
type_name: Rc<String>,
|
type_name: Rc<String>,
|
||||||
type_args: Vec<Rc<String>>,
|
type_args: Vec<Rc<String>>,
|
||||||
},
|
},
|
||||||
|
RecordConstructor {
|
||||||
|
fields: HashMap<Rc<String>, Rc<String>>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for SymbolSpec {
|
impl fmt::Display for SymbolSpec {
|
||||||
@ -52,6 +55,7 @@ impl fmt::Display for SymbolSpec {
|
|||||||
match self {
|
match self {
|
||||||
Func(type_names) => write!(f, "Func({:?})", type_names),
|
Func(type_names) => write!(f, "Func({:?})", type_names),
|
||||||
DataConstructor { index, type_name, type_args } => write!(f, "DataConstructor(idx: {})({:?} -> {})", index, type_args, type_name),
|
DataConstructor { index, type_name, type_args } => write!(f, "DataConstructor(idx: {})({:?} -> {})", index, type_args, type_name),
|
||||||
|
RecordConstructor { fields } => write!(f, "RecordConstructor( <fields> )"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,7 +128,14 @@ impl SymbolTable {
|
|||||||
let symbol = Symbol { name: variant_name.clone(), spec };
|
let symbol = Symbol { name: variant_name.clone(), spec };
|
||||||
self.values.insert(variant_name.clone(), symbol);
|
self.values.insert(variant_name.clone(), symbol);
|
||||||
},
|
},
|
||||||
Variant::Record { .. } => return Err(format!("Record types not supported yet")),
|
//TODO if there is only one variant, and it is a record, it doesn't need to have an
|
||||||
|
//explicit name
|
||||||
|
Variant::Record { name, members } => {
|
||||||
|
let fields = HashMap::new();
|
||||||
|
let spec = SymbolSpec::RecordConstructor { fields };
|
||||||
|
let symbol = Symbol { name: name.clone(), spec };
|
||||||
|
self.values.insert(name.clone(), symbol);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user