From a6c86d64474bf2b11dd9069c70bc057ccb3708ec Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 10 Oct 2019 17:06:41 -0700 Subject: [PATCH] Some work --- schala-lang/language/src/reduced_ast.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/schala-lang/language/src/reduced_ast.rs b/schala-lang/language/src/reduced_ast.rs index ae3b7ba..c83d714 100644 --- a/schala-lang/language/src/reduced_ast.rs +++ b/schala-lang/language/src/reduced_ast.rs @@ -18,6 +18,7 @@ use std::str::FromStr; use crate::ast::*; use crate::symbol_table::{Symbol, SymbolSpec, SymbolTable, FullyQualifiedSymbolName}; use crate::builtin::Builtin; +use crate::util::deref_optional_box; #[derive(Debug)] pub struct ReducedAST(pub Vec); @@ -178,7 +179,7 @@ impl<'a> Reducer<'a> { }, Call { f, arguments } => self.reduce_call_expression(f, arguments), TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| self.expression(e)).collect()), - IfExpression { discriminator, body } => self.reduce_if_expression(discriminator, body), + IfExpression { discriminator, body } => self.reduce_if_expression(deref_optional_box(discriminator), body), Lambda { params, body, .. } => self.reduce_lambda(params, body), NamedStruct { name, fields } => self.reduce_named_struct(name, fields), Index { .. } => Expr::UnimplementedSigilValue, @@ -232,16 +233,17 @@ impl<'a> Reducer<'a> { } } - fn reduce_if_expression(&mut self, discriminator: &Discriminator, body: &IfExpressionBody) -> Expr { + fn reduce_if_expression(&mut self, discriminator: Option<&Expression>, body: &IfExpressionBody) -> Expr { let symbol_table = self.symbol_table; - let cond = Box::new(match *discriminator { - Discriminator::Simple(ref expr) => self.expression(expr), - Discriminator::BinOp(ref _expr, ref _binop) => panic!("Can't yet handle binop discriminators") + let cond = Box::new(match discriminator { + Some(expr) => self.expression(expr), + None => Expr::Lit(Lit::Bool(true)), }); + match *body { - IfExpressionBody::SimpleConditional(ref then_clause, ref else_clause) => { - let then_clause = self.block(then_clause); - let else_clause = match else_clause { + IfExpressionBody::SimpleConditional { then_case, else_case } => { + let then_clause = self.block(then_case); + let else_clause = match else_case { None => vec![], Some(stmts) => self.block(stmts), };