diff --git a/schala-lang/language/src/eval.rs b/schala-lang/language/src/eval.rs index ff052b3..8f3fe88 100644 --- a/schala-lang/language/src/eval.rs +++ b/schala-lang/language/src/eval.rs @@ -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)), } } } diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index f563bc1..03400e2 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -53,7 +53,8 @@ pub enum Expr { cond: Box, alternatives: Vec }, - UnimplementedSigilValue + UnimplementedSigilValue, + ReductionError(String), } pub type BoundVars = Vec>>; //remember that order matters here @@ -168,11 +169,11 @@ fn reduce_lambda(params: &Vec, body: &Block, symbol_table: &SymbolT } fn reduce_named_struct(name: &Rc, fields: &Vec<(Rc, Meta)>, 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,