More named struct reduction work

This commit is contained in:
greg 2019-08-12 11:40:16 -07:00
parent e708c728d2
commit c9bfa2b540
2 changed files with 7 additions and 5 deletions

View File

@ -137,7 +137,7 @@ impl Expr {
match self {
ConditionalTargetSigilValue => replacement.clone(),
Unit | Lit(_) | Func(_) | Val(_) | Constructor { .. } |
CaseMatch { .. } | UnimplementedSigilValue => self,
CaseMatch { .. } | UnimplementedSigilValue | ReductionError(_) => self,
Tuple(exprs) => Tuple(exprs.into_iter().map(|e| e.replace_conditional_target_sigil(replacement)).collect()),
Call { f, args } => {
let new_args = args.into_iter().map(|e| e.replace_conditional_target_sigil(replacement)).collect();
@ -227,6 +227,7 @@ impl<'a> State<'a> {
CaseMatch { box cond, alternatives } => self.case_match_expression(cond, alternatives),
ConditionalTargetSigilValue => Ok(Node::Expr(ConditionalTargetSigilValue)),
UnimplementedSigilValue => Err(format!("Sigil value eval not implemented")),
ReductionError(err) => Err(format!("Reduction error: {}", err)),
}
}
}

View File

@ -53,7 +53,8 @@ pub enum Expr {
cond: Box<Expr>,
alternatives: Vec<Alternative>
},
UnimplementedSigilValue
UnimplementedSigilValue,
ReductionError(String),
}
pub type BoundVars = Vec<Option<Rc<String>>>; //remember that order matters here
@ -168,11 +169,11 @@ 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 { fields }, name, .. }) => (name, fields),
None => panic!("YOLO SWAGG"),
Some(Symbol { spec: SymbolSpec::RecordConstructor { members, type_name }, .. }) => (type_name, members),
_ => return Expr::ReductionError("Not a record constructor".to_string()),
};
/*
let arity = table_fields.len();
let f = Expr::Constructor {
type_name, arity,