From 1e7f5bbd2523f3a62b65fbe51476f21348b03a80 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 4 Aug 2018 16:07:29 -0700 Subject: [PATCH] WIP --- schala-lang/src/reduced_ast.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/schala-lang/src/reduced_ast.rs b/schala-lang/src/reduced_ast.rs index 58cbb13..4341896 100644 --- a/schala-lang/src/reduced_ast.rs +++ b/schala-lang/src/reduced_ast.rs @@ -24,14 +24,14 @@ pub enum Stmt { #[derive(Debug, Clone)] pub enum Expr { - Unit, Lit(Lit), - Tuple(Vec), Func(Func), - Val(Rc), + Tuple(Vec), Constructor { - name: Rc, + variant: usize, + expr: Box, }, + Val(Rc), Call { f: Box, args: Vec, @@ -52,6 +52,10 @@ pub enum Expr { UnimplementedSigilValue } +pub enum Pat { + Ignored +} + #[derive(Debug, Clone)] pub enum Lit { Nat(u64), @@ -83,7 +87,7 @@ impl AST { } impl Statement { - fn reduce(&self, symbol_table: &SymbolTable) -> Stmt { + fn reduce(&self, symbol_table: &SymbolTable) -> Stmt { use ast::Statement::*; match self { ExpressionStatement(expr) => Stmt::Expr(expr.reduce(symbol_table)), @@ -103,10 +107,12 @@ impl Expression { BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)), BinExp(binop, lhs, rhs) => binop.reduce(symbol_table, lhs, rhs), PrefixExp(op, arg) => op.reduce(symbol_table, arg), + //remember Some(5) is a CallExpr + // => ast: Ok(AST([ExpressionStatement(Expression(Call { f: Expression(Value("Some"), None), arguments: [Expression(NatLiteral(5), None)] }, None))])) Value(name) => { match symbol_table.values.get(name) { Some(Symbol { spec: SymbolSpec::DataConstructor { type_args, .. }, .. }) => { - Expr::Constructor { name: name.clone() } + Expr::Constructor { type_name: name.clone() } }, _ => Expr::Val(name.clone()), } @@ -154,6 +160,18 @@ fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody, } } +impl Pattern { + fn reduce(&self, symbol_table: &SymbolTable) -> Pat { + match self { + Pattern::Ignored => Pat::Ignored, + Pattern::TuplePattern(_) => panic!(), + Pattern::Literal(_) => panic!(), + Pattern::TupleStruct(_, _) => panic!(), + Pattern::Record(_, _) => panic!(), + } + } +} + impl Declaration { fn reduce(&self, symbol_table: &SymbolTable) -> Stmt { use self::Declaration::*;