Some work

This commit is contained in:
greg 2019-10-10 17:06:41 -07:00
parent 8d3639ab8e
commit a6c86d6447

View File

@ -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<Stmt>);
@ -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),
};