Use term "tag" consistently with type u32

This commit is contained in:
Greg Shuflin 2021-10-26 15:45:41 -07:00
parent 264fc2ae58
commit 0c6d2be95a
2 changed files with 22 additions and 21 deletions

View File

@ -139,9 +139,9 @@ impl<'a> Reducer<'a> {
NamedStruct { name, fields } => {
let symbol = self.symbol_table.lookup_symbol(&name.id).unwrap();
let constructor = match symbol.spec() {
SymbolSpec::RecordConstructor { index, members: _, type_id } => Expression::Callable(Callable::RecordConstructor {
SymbolSpec::RecordConstructor { tag, members: _, type_id } => Expression::Callable(Callable::RecordConstructor {
type_id,
tag: index as u32,
tag,
}),
e => return Expression::ReductionError(format!("Bad symbol for NamedStruct: {:?}", e)),
};
@ -311,10 +311,10 @@ impl<'a> Reducer<'a> {
GlobalBinding => Expression::Lookup(Lookup::GlobalVar(def_id.unwrap())),
LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id.unwrap())),
FunctionParam(n) => Expression::Lookup(Lookup::Param(n)),
DataConstructor { index, arity, type_id } => Expression::Callable(Callable::DataConstructor {
DataConstructor { tag, arity, type_id } => Expression::Callable(Callable::DataConstructor {
type_id,
arity: arity as u32, //TODO fix up these modifiers
tag: index as u32,
arity: arity as u32,
tag,
}),
RecordConstructor { .. } => {
Expression::ReductionError(format!("The symbol for value {:?} is unexpectdly a RecordConstructor", qualified_name))
@ -349,12 +349,12 @@ impl ast::Pattern {
}),
ast::Pattern::TupleStruct(name, subpatterns) => {
let symbol = symbol_table.lookup_symbol(&name.id).unwrap();
if let SymbolSpec::DataConstructor { index: tag, type_id: _, arity: _ } = symbol.spec() {
if let SymbolSpec::DataConstructor { tag, type_id: _, arity: _ } = symbol.spec() {
let items: Result<Vec<Pattern>, PatternError> = subpatterns.iter().map(|pat| pat.reduce(symbol_table))
.into_iter().collect();
let items = items?;
Pattern::Tuple {
tag: Some(tag as u32),
tag: Some(tag),
subpatterns: items,
}
} else {
@ -364,9 +364,9 @@ impl ast::Pattern {
ast::Pattern::VarOrName(name) => {
let symbol = symbol_table.lookup_symbol(&name.id).unwrap();
match symbol.spec() {
SymbolSpec::DataConstructor { index: tag, type_id: _, arity: _ } => {
SymbolSpec::DataConstructor { tag, type_id: _, arity: _ } => {
Pattern::Tuple {
tag: Some(tag as u32),
tag: Some(tag),
subpatterns: vec![]
}
},
@ -380,7 +380,7 @@ impl ast::Pattern {
ast::Pattern::Record(name, _specified_members/*Vec<(Rc<String>, Pattern)>*/) => {
let symbol = symbol_table.lookup_symbol(&name.id).unwrap();
match symbol.spec() {
SymbolSpec::RecordConstructor { index: _, members: _, type_id: _ } => unimplemented!(),
SymbolSpec::RecordConstructor { tag: _, members: _, type_id: _ } => unimplemented!(),
spec => return Err(format!("Unexpected Record pattern symbol: {:?}", spec).into())
}
}

View File

@ -276,12 +276,12 @@ impl fmt::Display for Symbol {
pub enum SymbolSpec {
Func,
DataConstructor {
index: usize,
tag: u32,
arity: usize,
type_id: TypeId,
},
RecordConstructor {
index: usize,
tag: u32,
members: HashMap<Rc<String>, TypeId>,
type_id: TypeId,
},
@ -296,20 +296,20 @@ impl fmt::Display for SymbolSpec {
match self {
Func => write!(f, "Func"),
DataConstructor {
index,
tag,
type_id,
arity,
} => write!(
f,
"DataConstructor(idx: {}, arity: {}, type: {})",
index, arity, type_id
"DataConstructor(tag: {}, arity: {}, type: {})",
tag, arity, type_id
),
RecordConstructor {
type_id, index, ..
type_id, tag, ..
} => write!(
f,
"RecordConstructor(idx: {})(<members> -> {})",
index, type_id
"RecordConstructor(tag: {})(<members> -> {})",
tag, type_id
),
GlobalBinding => write!(f, "GlobalBinding"),
LocalVariable => write!(f, "Local variable"),
@ -527,6 +527,7 @@ impl SymbolTable {
scope_stack.push(new_scope);
for (index, variant) in variants.iter().enumerate() {
let tag = index as u32;
let Variant { name, kind, id } = variant;
let type_id = TypeId::lookup_name(name.as_ref());
@ -534,7 +535,7 @@ impl SymbolTable {
VariantKind::UnitStruct => {
let fq_name = Fqsn::from_scope_stack(scope_stack.as_ref(), name.clone());
let spec = SymbolSpec::DataConstructor {
index,
tag,
arity: 0,
type_id,
};
@ -543,7 +544,7 @@ impl SymbolTable {
VariantKind::TupleStruct(items) => {
let fq_name = Fqsn::from_scope_stack(scope_stack.as_ref(), name.clone());
let spec = SymbolSpec::DataConstructor {
index,
tag,
arity: items.len(),
type_id,
};
@ -571,7 +572,7 @@ impl SymbolTable {
}
let spec = SymbolSpec::RecordConstructor {
index,
tag,
type_id,
members: members
.iter()