Reduce complexity of DataConstructor

This commit is contained in:
Greg Shuflin 2021-10-19 16:50:08 -07:00
parent 736aa8aad2
commit 3c4d31c963
2 changed files with 6 additions and 6 deletions

View File

@ -190,11 +190,11 @@ impl<'a> Reducer<'a> {
match spec {
SymbolSpec::RecordConstructor { .. } => Expr::ReductionError(format!("AST reducer doesn't expect a RecordConstructor here")),
SymbolSpec::DataConstructor { index, type_args, type_name } => Expr::Constructor {
SymbolSpec::DataConstructor { index, arity, type_name } => Expr::Constructor {
type_name: type_name.clone(),
name: local_name.clone(),
tag: index.clone(),
arity: type_args.len(),
arity: *arity,
},
SymbolSpec::Func(_) => Expr::Sym(local_name.clone()),
SymbolSpec::Binding => Expr::Sym(local_name.clone()), //TODO not sure if this is right, probably needs to eventually be fqsn

View File

@ -151,8 +151,8 @@ pub enum SymbolSpec {
Func(Vec<TypeName>),
DataConstructor {
index: usize,
arity: usize,
type_name: TypeName, //TODO this eventually needs to be some kind of ID
type_args: Vec<Rc<String>>, //TODO this should be a lookup table into type information, it's not the concern of the symbol table
},
RecordConstructor {
index: usize,
@ -167,7 +167,7 @@ impl fmt::Display for SymbolSpec {
use self::SymbolSpec::*;
match self {
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, arity } => write!(f, "DataConstructor(idx: {}, arity: {}, type: {})", index, arity, type_name),
RecordConstructor { type_name, index, ..} => write!(f, "RecordConstructor(idx: {})(<members> -> {})", index, type_name),
Binding => write!(f, "Binding"),
}
@ -298,8 +298,8 @@ impl SymbolTable {
let fq_name = FQSN::from_scope_stack(scope_stack.as_ref(), name.as_ref().to_owned());
let spec = SymbolSpec::DataConstructor {
index,
arity: 0,
type_name: name.clone(),
type_args: vec![],
};
register(fq_name, spec);
},
@ -307,8 +307,8 @@ impl SymbolTable {
let fq_name = FQSN::from_scope_stack(scope_stack.as_ref(), name.as_ref().to_owned());
let spec = SymbolSpec::DataConstructor {
index,
arity: items.len(),
type_name: name.clone(),
type_args: items.iter().map(|_| Rc::new("DUMMY_TYPE_ID".to_string())).collect()
};
register(fq_name, spec);
},