Successfully constructing a record
Not yet destructing it
This commit is contained in:
parent
a8efe40b57
commit
e750247134
@ -183,19 +183,24 @@ fn reduce_lambda(params: &Vec<FormalParam>, body: &Block, symbol_table: &SymbolT
|
||||
}
|
||||
|
||||
fn reduce_named_struct(name: &Rc<String>, fields: &Vec<(Rc<String>, Meta<Expression>)>, symbol_table: &SymbolTable) -> Expr {
|
||||
let (type_name, table_fields) = match symbol_table.lookup_by_name(name) {
|
||||
Some(Symbol { spec: SymbolSpec::RecordConstructor { members, type_name }, .. }) => (type_name, members),
|
||||
let (type_name, index, members_from_table) = match symbol_table.lookup_by_name(name) {
|
||||
Some(Symbol { spec: SymbolSpec::RecordConstructor { members, type_name, index }, .. }) => (type_name.clone(), index, members),
|
||||
_ => return Expr::ReductionError("Not a record constructor".to_string()),
|
||||
};
|
||||
/*
|
||||
let arity = table_fields.len();
|
||||
let f = Expr::Constructor {
|
||||
type_name, arity,
|
||||
};
|
||||
let args = fields.map(;
|
||||
let arity = members_from_table.len();
|
||||
|
||||
let mut args: Vec<(Rc<String>, Expr)> = fields.iter()
|
||||
.map(|(name, expr)| (name.clone(), expr.node().reduce(symbol_table)))
|
||||
.collect();
|
||||
|
||||
args.as_mut_slice()
|
||||
.sort_unstable_by(|(name1, _), (name2, _)| name1.cmp(name2)); //arbitrary - sorting by alphabetical order
|
||||
|
||||
let args = args.into_iter().map(|(_, expr)| expr).collect();
|
||||
|
||||
//TODO make sure this sorting actually works
|
||||
let f = box Expr::Constructor { type_name, name: name.clone(), tag: *index, arity, };
|
||||
Expr::Call { f, args }
|
||||
*/
|
||||
panic!("Still not done")
|
||||
}
|
||||
|
||||
fn reduce_call_expression(func: &Meta<Expression>, arguments: &Vec<Meta<InvocationArgument>>, symbol_table: &SymbolTable) -> Expr {
|
||||
|
@ -81,6 +81,7 @@ pub enum SymbolSpec {
|
||||
type_args: Vec<Rc<String>>,
|
||||
},
|
||||
RecordConstructor {
|
||||
index: usize,
|
||||
members: HashMap<Rc<String>, TypeName>,
|
||||
type_name: TypeName,
|
||||
},
|
||||
@ -93,7 +94,7 @@ impl fmt::Display for 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),
|
||||
RecordConstructor { type_name, ..} => write!(f, "RecordConstructor(<members> -> {})", type_name),
|
||||
RecordConstructor { type_name, index, ..} => write!(f, "RecordConstructor(idx: {})(<members> -> {})", index, type_name),
|
||||
Binding => write!(f, "Binding"),
|
||||
}
|
||||
}
|
||||
@ -226,7 +227,7 @@ impl SymbolTable {
|
||||
if duplicate_member_definitions.len() != 0 {
|
||||
return Err(format!("Duplicate member(s) in definition of type {}: {:?}", type_name, duplicate_member_definitions));
|
||||
}
|
||||
let spec = SymbolSpec::RecordConstructor { type_name: type_name.clone(), members };
|
||||
let spec = SymbolSpec::RecordConstructor { index, type_name: type_name.clone(), members };
|
||||
self.add_new_symbol(name, scope_name_stack, spec);
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user