Some ADT work
This commit is contained in:
parent
33c22c8bbc
commit
c65907388d
@ -267,8 +267,12 @@ impl<'a> State<'a> {
|
||||
let symbol_table = self.symbol_table_handle.borrow();
|
||||
Ok(match symbol_table.values.get(&name) {
|
||||
Some(Symbol { name, spec }) => match spec {
|
||||
SymbolSpec::Custom(_typename) => {
|
||||
Expr::Lit(Lit::Custom(name.clone()))
|
||||
SymbolSpec::DataConstructor { type_name, type_args } => {
|
||||
if type_args.len() == 0 {
|
||||
Expr::Lit(Lit::Custom(name.clone()))
|
||||
} else {
|
||||
return Err(format!("This data constructor thing not done"))
|
||||
}
|
||||
},
|
||||
SymbolSpec::Func => match self.values.lookup(&name) {
|
||||
Some(Binding { val: Expr::Func(UserDefined { name, params, body }), .. }) => {
|
||||
|
@ -24,7 +24,11 @@ pub struct Symbol {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SymbolSpec {
|
||||
Func, Custom(String)
|
||||
Func,
|
||||
DataConstructor {
|
||||
type_name: Rc<String>,
|
||||
type_args: Vec<Rc<String>>,
|
||||
},
|
||||
}
|
||||
|
||||
impl SymbolTable {
|
||||
@ -42,14 +46,28 @@ impl SymbolTable {
|
||||
Symbol { name: signature.name.clone(), spec: SymbolSpec::Func }
|
||||
);
|
||||
},
|
||||
TypeDecl(TypeSingletonName { name, ..}, TypeBody(variants)) => {
|
||||
TypeDecl(TypeSingletonName { name, params}, TypeBody(variants)) => {
|
||||
for var in variants {
|
||||
match var {
|
||||
Variant::UnitStruct(variant_name) => {
|
||||
//TODO will have to make this a function to this type eventually
|
||||
let spec = SymbolSpec::Custom(format!("{}", name));
|
||||
let spec = SymbolSpec::DataConstructor {
|
||||
type_name: name.clone(),
|
||||
type_args: vec![],
|
||||
};
|
||||
self.values.insert(variant_name.clone(), Symbol { name: variant_name.clone(), spec });
|
||||
},
|
||||
Variant::TupleStruct(variant_name, tuple_members) => {
|
||||
let type_args = vec![
|
||||
|
||||
];
|
||||
let spec = SymbolSpec::DataConstructor {
|
||||
type_name: name.clone(),
|
||||
type_args
|
||||
};
|
||||
let symbol = Symbol { name: variant_name.clone(), spec };
|
||||
self.values.insert(variant_name.clone(), symbol);
|
||||
},
|
||||
e => return Err(format!("{:?} not supported in typing yet", e)),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user