Use term "tag" consistently with type u32
This commit is contained in:
parent
264fc2ae58
commit
0c6d2be95a
@ -139,9 +139,9 @@ impl<'a> Reducer<'a> {
|
|||||||
NamedStruct { name, fields } => {
|
NamedStruct { name, fields } => {
|
||||||
let symbol = self.symbol_table.lookup_symbol(&name.id).unwrap();
|
let symbol = self.symbol_table.lookup_symbol(&name.id).unwrap();
|
||||||
let constructor = match symbol.spec() {
|
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,
|
type_id,
|
||||||
tag: index as u32,
|
tag,
|
||||||
}),
|
}),
|
||||||
e => return Expression::ReductionError(format!("Bad symbol for NamedStruct: {:?}", e)),
|
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())),
|
GlobalBinding => Expression::Lookup(Lookup::GlobalVar(def_id.unwrap())),
|
||||||
LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id.unwrap())),
|
LocalVariable => Expression::Lookup(Lookup::LocalVar(def_id.unwrap())),
|
||||||
FunctionParam(n) => Expression::Lookup(Lookup::Param(n)),
|
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,
|
type_id,
|
||||||
arity: arity as u32, //TODO fix up these modifiers
|
arity: arity as u32,
|
||||||
tag: index as u32,
|
tag,
|
||||||
}),
|
}),
|
||||||
RecordConstructor { .. } => {
|
RecordConstructor { .. } => {
|
||||||
Expression::ReductionError(format!("The symbol for value {:?} is unexpectdly a RecordConstructor", qualified_name))
|
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) => {
|
ast::Pattern::TupleStruct(name, subpatterns) => {
|
||||||
let symbol = symbol_table.lookup_symbol(&name.id).unwrap();
|
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))
|
let items: Result<Vec<Pattern>, PatternError> = subpatterns.iter().map(|pat| pat.reduce(symbol_table))
|
||||||
.into_iter().collect();
|
.into_iter().collect();
|
||||||
let items = items?;
|
let items = items?;
|
||||||
Pattern::Tuple {
|
Pattern::Tuple {
|
||||||
tag: Some(tag as u32),
|
tag: Some(tag),
|
||||||
subpatterns: items,
|
subpatterns: items,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -364,9 +364,9 @@ impl ast::Pattern {
|
|||||||
ast::Pattern::VarOrName(name) => {
|
ast::Pattern::VarOrName(name) => {
|
||||||
let symbol = symbol_table.lookup_symbol(&name.id).unwrap();
|
let symbol = symbol_table.lookup_symbol(&name.id).unwrap();
|
||||||
match symbol.spec() {
|
match symbol.spec() {
|
||||||
SymbolSpec::DataConstructor { index: tag, type_id: _, arity: _ } => {
|
SymbolSpec::DataConstructor { tag, type_id: _, arity: _ } => {
|
||||||
Pattern::Tuple {
|
Pattern::Tuple {
|
||||||
tag: Some(tag as u32),
|
tag: Some(tag),
|
||||||
subpatterns: vec![]
|
subpatterns: vec![]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -380,7 +380,7 @@ impl ast::Pattern {
|
|||||||
ast::Pattern::Record(name, _specified_members/*Vec<(Rc<String>, Pattern)>*/) => {
|
ast::Pattern::Record(name, _specified_members/*Vec<(Rc<String>, Pattern)>*/) => {
|
||||||
let symbol = symbol_table.lookup_symbol(&name.id).unwrap();
|
let symbol = symbol_table.lookup_symbol(&name.id).unwrap();
|
||||||
match symbol.spec() {
|
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())
|
spec => return Err(format!("Unexpected Record pattern symbol: {:?}", spec).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -276,12 +276,12 @@ impl fmt::Display for Symbol {
|
|||||||
pub enum SymbolSpec {
|
pub enum SymbolSpec {
|
||||||
Func,
|
Func,
|
||||||
DataConstructor {
|
DataConstructor {
|
||||||
index: usize,
|
tag: u32,
|
||||||
arity: usize,
|
arity: usize,
|
||||||
type_id: TypeId,
|
type_id: TypeId,
|
||||||
},
|
},
|
||||||
RecordConstructor {
|
RecordConstructor {
|
||||||
index: usize,
|
tag: u32,
|
||||||
members: HashMap<Rc<String>, TypeId>,
|
members: HashMap<Rc<String>, TypeId>,
|
||||||
type_id: TypeId,
|
type_id: TypeId,
|
||||||
},
|
},
|
||||||
@ -296,20 +296,20 @@ impl fmt::Display for SymbolSpec {
|
|||||||
match self {
|
match self {
|
||||||
Func => write!(f, "Func"),
|
Func => write!(f, "Func"),
|
||||||
DataConstructor {
|
DataConstructor {
|
||||||
index,
|
tag,
|
||||||
type_id,
|
type_id,
|
||||||
arity,
|
arity,
|
||||||
} => write!(
|
} => write!(
|
||||||
f,
|
f,
|
||||||
"DataConstructor(idx: {}, arity: {}, type: {})",
|
"DataConstructor(tag: {}, arity: {}, type: {})",
|
||||||
index, arity, type_id
|
tag, arity, type_id
|
||||||
),
|
),
|
||||||
RecordConstructor {
|
RecordConstructor {
|
||||||
type_id, index, ..
|
type_id, tag, ..
|
||||||
} => write!(
|
} => write!(
|
||||||
f,
|
f,
|
||||||
"RecordConstructor(idx: {})(<members> -> {})",
|
"RecordConstructor(tag: {})(<members> -> {})",
|
||||||
index, type_id
|
tag, type_id
|
||||||
),
|
),
|
||||||
GlobalBinding => write!(f, "GlobalBinding"),
|
GlobalBinding => write!(f, "GlobalBinding"),
|
||||||
LocalVariable => write!(f, "Local variable"),
|
LocalVariable => write!(f, "Local variable"),
|
||||||
@ -527,6 +527,7 @@ impl SymbolTable {
|
|||||||
scope_stack.push(new_scope);
|
scope_stack.push(new_scope);
|
||||||
|
|
||||||
for (index, variant) in variants.iter().enumerate() {
|
for (index, variant) in variants.iter().enumerate() {
|
||||||
|
let tag = index as u32;
|
||||||
let Variant { name, kind, id } = variant;
|
let Variant { name, kind, id } = variant;
|
||||||
let type_id = TypeId::lookup_name(name.as_ref());
|
let type_id = TypeId::lookup_name(name.as_ref());
|
||||||
|
|
||||||
@ -534,7 +535,7 @@ impl SymbolTable {
|
|||||||
VariantKind::UnitStruct => {
|
VariantKind::UnitStruct => {
|
||||||
let fq_name = Fqsn::from_scope_stack(scope_stack.as_ref(), name.clone());
|
let fq_name = Fqsn::from_scope_stack(scope_stack.as_ref(), name.clone());
|
||||||
let spec = SymbolSpec::DataConstructor {
|
let spec = SymbolSpec::DataConstructor {
|
||||||
index,
|
tag,
|
||||||
arity: 0,
|
arity: 0,
|
||||||
type_id,
|
type_id,
|
||||||
};
|
};
|
||||||
@ -543,7 +544,7 @@ impl SymbolTable {
|
|||||||
VariantKind::TupleStruct(items) => {
|
VariantKind::TupleStruct(items) => {
|
||||||
let fq_name = Fqsn::from_scope_stack(scope_stack.as_ref(), name.clone());
|
let fq_name = Fqsn::from_scope_stack(scope_stack.as_ref(), name.clone());
|
||||||
let spec = SymbolSpec::DataConstructor {
|
let spec = SymbolSpec::DataConstructor {
|
||||||
index,
|
tag,
|
||||||
arity: items.len(),
|
arity: items.len(),
|
||||||
type_id,
|
type_id,
|
||||||
};
|
};
|
||||||
@ -571,7 +572,7 @@ impl SymbolTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let spec = SymbolSpec::RecordConstructor {
|
let spec = SymbolSpec::RecordConstructor {
|
||||||
index,
|
tag,
|
||||||
type_id,
|
type_id,
|
||||||
members: members
|
members: members
|
||||||
.iter()
|
.iter()
|
||||||
|
Loading…
Reference in New Issue
Block a user