From c637a922a9524902ecf8648181c4e3b84f5f8edd Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 5 Aug 2018 14:23:08 -0700 Subject: [PATCH] Start implementing constructors/matches as per Implementing Functional Programming Languages by Peyton-Jones --- schala-lang/src/reduced_ast.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/schala-lang/src/reduced_ast.rs b/schala-lang/src/reduced_ast.rs index 58cbb13..7523807 100644 --- a/schala-lang/src/reduced_ast.rs +++ b/schala-lang/src/reduced_ast.rs @@ -29,6 +29,11 @@ pub enum Expr { Tuple(Vec), Func(Func), Val(Rc), + NewConstructor { + type_name: Rc, + tag: usize, + arg: Box, + }, Constructor { name: Rc, }, @@ -47,11 +52,18 @@ pub enum Expr { }, Match { cond: Box, - arms: Vec<(Pattern, Vec)> + alternatives: Vec }, UnimplementedSigilValue } +#[derive(Debug, Clone)] +pub struct Alternative { + tag: usize, + bound_vars: (), + item: Vec, +} + #[derive(Debug, Clone)] pub enum Lit { Nat(u64), @@ -142,11 +154,19 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody, None => vec![], Some(stmts) => stmts.iter().map(|expr| expr.reduce(symbol_table)).collect(), }; - Expr::Match { + Expr::Match { //TODO this still doesn't work right cond, - arms: vec![ - (pat.clone(), then_clause), - (Pattern::Ignored, else_clause) + alternatives: vec![ + Alternative { + tag: 0, + bound_vars: (), + item: then_clause, + }, + Alternative { + tag: 1, + bound_vars: (), + item: else_clause, + }, ], } },