More work on named struct

commented for now becuase I need to fix things in the symbol table
This commit is contained in:
greg 2019-08-12 10:59:04 -07:00
parent aae2ee53cd
commit a600d34712
1 changed files with 16 additions and 4 deletions

View File

@ -33,7 +33,7 @@ pub enum Expr {
type_name: Rc<String>, type_name: Rc<String>,
name: Rc<String>, name: Rc<String>,
tag: usize, tag: usize,
arity: usize, arity: usize, // n.b. arity here is always the value from the symbol table - if it doesn't match what it's being called with, that's an eval error, eval will handle it
}, },
Call { Call {
f: Box<Expr>, f: Box<Expr>,
@ -150,7 +150,7 @@ impl Expression {
TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.node().reduce(symbol_table)).collect()), TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.node().reduce(symbol_table)).collect()),
IfExpression { discriminator, body } => reduce_if_expression(discriminator, body, symbol_table), IfExpression { discriminator, body } => reduce_if_expression(discriminator, body, symbol_table),
Lambda { params, body, .. } => reduce_lambda(params, body, symbol_table), Lambda { params, body, .. } => reduce_lambda(params, body, symbol_table),
NamedStruct { name, fields } => reduce_named_struct(name, fields), NamedStruct { name, fields } => reduce_named_struct(name, fields, symbol_table),
Index { .. } => Expr::UnimplementedSigilValue, Index { .. } => Expr::UnimplementedSigilValue,
WhileExpression { .. } => Expr::UnimplementedSigilValue, WhileExpression { .. } => Expr::UnimplementedSigilValue,
ForExpression { .. } => Expr::UnimplementedSigilValue, ForExpression { .. } => Expr::UnimplementedSigilValue,
@ -167,8 +167,20 @@ fn reduce_lambda(params: &Vec<FormalParam>, body: &Block, symbol_table: &SymbolT
}) })
} }
fn reduce_named_struct(name: &Rc<String>, fields: &Vec<(Rc<String>, Meta<Expression>)>) -> Expr { fn reduce_named_struct(name: &Rc<String>, fields: &Vec<(Rc<String>, Meta<Expression>)>, symbol_table: &SymbolTable) -> Expr {
panic!() /*
let (type_name, table_fields) = match symbol_table.lookup_by_name(name) {
Some(Symbol { spec: SymbolSpec::RecordConstructor { fields }, name, .. }) => (name, fields),
None => panic!("YOLO SWAGG"),
};
let arity = table_fields.len();
let f = Expr::Constructor {
type_name, arity,
};
let args = fields.map(;
Expr::Call { f, args }
*/
panic!("Still not done")
} }
fn reduce_call_expression(func: &Meta<Expression>, arguments: &Vec<Meta<InvocationArgument>>, symbol_table: &SymbolTable) -> Expr { fn reduce_call_expression(func: &Meta<Expression>, arguments: &Vec<Meta<InvocationArgument>>, symbol_table: &SymbolTable) -> Expr {