Start work on named struct

This commit is contained in:
Greg Shuflin 2021-10-26 15:30:42 -07:00
parent e4592ddfb2
commit 264fc2ae58
3 changed files with 29 additions and 1 deletions

View File

@ -136,7 +136,28 @@ impl<'a> Reducer<'a> {
body: self.function_internal_block(body), body: self.function_internal_block(body),
}) })
}, },
NamedStruct { .. } => Expression::ReductionError("NamedStruct not implemented".to_string()), //self.reduce_named_struct(name, fields), 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 {
type_id,
tag: index as u32,
}),
e => return Expression::ReductionError(format!("Bad symbol for NamedStruct: {:?}", e)),
};
//TODO need to order the fields correctly, which needs symbol table information
// Until this happens, NamedStructs won't work
let mut ordered_args = vec![];
for (_name, _type_id) in fields {
unimplemented!()
}
Expression::Call {
f: Box::new(constructor),
args: ordered_args,
}
},
Index { .. } => Expression::ReductionError("Index expr not implemented".to_string()), Index { .. } => Expression::ReductionError("Index expr not implemented".to_string()),
WhileExpression { .. } => Expression::ReductionError("While expr not implemented".to_string()), WhileExpression { .. } => Expression::ReductionError("While expr not implemented".to_string()),
ForExpression { .. } => Expression::ReductionError("For expr not implemented".to_string()), ForExpression { .. } => Expression::ReductionError("For expr not implemented".to_string()),

View File

@ -98,6 +98,10 @@ pub enum Callable {
arity: u32, arity: u32,
tag: u32 tag: u32
}, },
RecordConstructor {
type_id: TypeId,
tag: u32,
},
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -358,6 +358,9 @@ impl<'a> State<'a> {
items: evaluated_args items: evaluated_args
}) })
} }
Callable::RecordConstructor { type_id: _, tag: _ } => {
unimplemented!()
}
} }
} }