2018-05-09 02:27:57 -07:00
|
|
|
use std::rc::Rc;
|
2018-05-09 02:02:17 -07:00
|
|
|
|
2018-10-16 01:38:41 -07:00
|
|
|
use ast::{AST, Statement, Expression, ExpressionType, Declaration, Discriminator, IfExpressionBody, Pattern, PatternLiteral, Guard, HalfExpr};
|
2018-06-12 03:02:50 -07:00
|
|
|
use symbol_table::{Symbol, SymbolSpec, SymbolTable};
|
2018-05-09 17:02:10 -07:00
|
|
|
use builtin::{BinOp, PrefixOp};
|
2018-05-09 02:27:57 -07:00
|
|
|
|
2018-05-09 02:49:49 -07:00
|
|
|
#[derive(Debug)]
|
2018-05-09 02:27:57 -07:00
|
|
|
pub struct ReducedAST(pub Vec<Stmt>);
|
|
|
|
|
2018-05-11 17:24:11 -07:00
|
|
|
#[derive(Debug, Clone)]
|
2018-05-09 02:27:57 -07:00
|
|
|
pub enum Stmt {
|
2018-05-13 17:24:21 -07:00
|
|
|
PreBinding {
|
|
|
|
name: Rc<String>,
|
|
|
|
func: Func,
|
|
|
|
},
|
2018-05-09 02:27:57 -07:00
|
|
|
Binding {
|
|
|
|
name: Rc<String>,
|
2018-05-11 02:24:38 -07:00
|
|
|
constant: bool,
|
2018-05-09 02:27:57 -07:00
|
|
|
expr: Expr,
|
|
|
|
},
|
|
|
|
Expr(Expr),
|
2018-05-13 17:24:21 -07:00
|
|
|
Noop,
|
2018-05-09 02:27:57 -07:00
|
|
|
}
|
|
|
|
|
2018-05-11 17:24:11 -07:00
|
|
|
#[derive(Debug, Clone)]
|
2018-05-09 02:27:57 -07:00
|
|
|
pub enum Expr {
|
2018-05-12 00:59:50 -07:00
|
|
|
Unit,
|
2018-05-09 03:04:01 -07:00
|
|
|
Lit(Lit),
|
2018-05-12 12:56:39 -07:00
|
|
|
Tuple(Vec<Expr>),
|
2018-05-09 02:27:57 -07:00
|
|
|
Func(Func),
|
2018-05-11 17:24:11 -07:00
|
|
|
Val(Rc<String>),
|
2018-08-05 19:14:02 -07:00
|
|
|
Constructor {
|
2018-08-05 14:23:08 -07:00
|
|
|
type_name: Rc<String>,
|
2018-08-05 17:15:58 -07:00
|
|
|
name: Rc<String>,
|
2018-08-05 14:23:08 -07:00
|
|
|
tag: usize,
|
2018-08-05 16:04:52 -07:00
|
|
|
arity: usize,
|
2018-08-05 14:23:08 -07:00
|
|
|
},
|
2018-05-09 02:27:57 -07:00
|
|
|
Call {
|
2018-05-11 23:34:26 -07:00
|
|
|
f: Box<Expr>,
|
2018-05-09 02:27:57 -07:00
|
|
|
args: Vec<Expr>,
|
|
|
|
},
|
2018-05-12 03:51:42 -07:00
|
|
|
Assign {
|
|
|
|
val: Box<Expr>,
|
|
|
|
expr: Box<Expr>,
|
|
|
|
},
|
2018-05-12 13:51:12 -07:00
|
|
|
Conditional {
|
|
|
|
cond: Box<Expr>,
|
|
|
|
then_clause: Vec<Stmt>,
|
|
|
|
else_clause: Vec<Stmt>,
|
|
|
|
},
|
2018-10-29 01:50:43 -07:00
|
|
|
ConditionalTargetSigilValue,
|
2018-08-14 12:37:18 -07:00
|
|
|
CaseMatch {
|
2018-07-24 03:12:00 -07:00
|
|
|
cond: Box<Expr>,
|
2018-08-05 14:23:08 -07:00
|
|
|
alternatives: Vec<Alternative>
|
2018-07-24 03:12:00 -07:00
|
|
|
},
|
2018-05-11 00:45:32 -07:00
|
|
|
UnimplementedSigilValue
|
2018-05-09 02:27:57 -07:00
|
|
|
}
|
|
|
|
|
2018-08-05 14:23:08 -07:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Alternative {
|
2018-08-14 21:17:43 -07:00
|
|
|
pub tag: Option<usize>,
|
2018-10-30 18:39:25 -07:00
|
|
|
pub subpatterns: Vec<Option<Subpattern>>,
|
2018-10-19 17:43:22 -07:00
|
|
|
pub guard: Option<Expr>,
|
2018-08-14 21:17:43 -07:00
|
|
|
pub bound_vars: Vec<Option<Rc<String>>>, //remember that order matters here
|
|
|
|
pub item: Vec<Stmt>,
|
2018-08-05 14:23:08 -07:00
|
|
|
}
|
|
|
|
|
2018-10-18 01:54:36 -07:00
|
|
|
impl Alternative {
|
|
|
|
fn default(item: Vec<Stmt>) -> Alternative {
|
2018-10-19 17:43:22 -07:00
|
|
|
Alternative { tag: None, subpatterns: vec![], guard: None, bound_vars: vec![], item }
|
2018-10-18 01:54:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-30 18:39:25 -07:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Subpattern {
|
|
|
|
pub tag: Option<usize>,
|
2018-10-30 18:46:06 -07:00
|
|
|
pub subpatterns: Vec<Option<Subpattern>>,
|
2018-10-30 18:39:25 -07:00
|
|
|
pub bound_vars: Vec<Option<Rc<String>>>,
|
|
|
|
pub guard: Option<Expr>,
|
|
|
|
}
|
|
|
|
|
2018-05-11 17:24:11 -07:00
|
|
|
#[derive(Debug, Clone)]
|
2018-05-09 02:27:57 -07:00
|
|
|
pub enum Lit {
|
2018-05-11 00:38:40 -07:00
|
|
|
Nat(u64),
|
|
|
|
Int(i64),
|
2018-05-09 17:02:10 -07:00
|
|
|
Float(f64),
|
2018-05-09 02:27:57 -07:00
|
|
|
Bool(bool),
|
|
|
|
StringLit(Rc<String>),
|
|
|
|
}
|
|
|
|
|
2018-05-11 17:24:11 -07:00
|
|
|
#[derive(Debug, Clone)]
|
2018-05-11 00:38:40 -07:00
|
|
|
pub enum Func {
|
|
|
|
BuiltIn(Rc<String>),
|
|
|
|
UserDefined {
|
2018-05-11 23:23:54 -07:00
|
|
|
name: Option<Rc<String>>,
|
2018-05-11 00:38:40 -07:00
|
|
|
params: Vec<Rc<String>>,
|
|
|
|
body: Vec<Stmt>,
|
|
|
|
}
|
2018-05-09 02:27:57 -07:00
|
|
|
}
|
|
|
|
|
2018-05-10 23:41:51 -07:00
|
|
|
impl AST {
|
2018-06-12 02:56:28 -07:00
|
|
|
pub fn reduce(&self, symbol_table: &SymbolTable) -> ReducedAST {
|
2018-05-10 23:41:51 -07:00
|
|
|
let mut output = vec![];
|
|
|
|
for statement in self.0.iter() {
|
2018-06-12 02:56:28 -07:00
|
|
|
output.push(statement.reduce(symbol_table));
|
2018-05-09 02:49:49 -07:00
|
|
|
}
|
2018-05-11 00:45:32 -07:00
|
|
|
ReducedAST(output)
|
2018-05-09 02:49:49 -07:00
|
|
|
}
|
|
|
|
}
|
2018-05-09 02:27:57 -07:00
|
|
|
|
2018-05-11 22:44:21 -07:00
|
|
|
impl Statement {
|
2018-06-12 02:56:28 -07:00
|
|
|
fn reduce(&self, symbol_table: &SymbolTable) -> Stmt {
|
2018-06-04 19:25:40 -07:00
|
|
|
use ast::Statement::*;
|
2018-05-11 22:44:21 -07:00
|
|
|
match self {
|
2018-06-12 02:56:28 -07:00
|
|
|
ExpressionStatement(expr) => Stmt::Expr(expr.reduce(symbol_table)),
|
|
|
|
Declaration(decl) => decl.reduce(symbol_table),
|
2018-05-11 22:44:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-10 23:41:51 -07:00
|
|
|
impl Expression {
|
2018-06-12 02:56:28 -07:00
|
|
|
fn reduce(&self, symbol_table: &SymbolTable) -> Expr {
|
2018-06-04 19:25:40 -07:00
|
|
|
use ast::ExpressionType::*;
|
2018-05-10 23:41:51 -07:00
|
|
|
let ref input = self.0;
|
2018-05-11 00:45:32 -07:00
|
|
|
match input {
|
2018-05-12 01:44:03 -07:00
|
|
|
NatLiteral(n) => Expr::Lit(Lit::Nat(*n)),
|
2018-05-11 23:26:02 -07:00
|
|
|
FloatLiteral(f) => Expr::Lit(Lit::Float(*f)),
|
|
|
|
StringLiteral(s) => Expr::Lit(Lit::StringLit(s.clone())),
|
|
|
|
BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)),
|
2018-06-12 02:56:28 -07:00
|
|
|
BinExp(binop, lhs, rhs) => binop.reduce(symbol_table, lhs, rhs),
|
|
|
|
PrefixExp(op, arg) => op.reduce(symbol_table, arg),
|
2018-08-07 17:09:53 -07:00
|
|
|
Value(name) => match symbol_table.lookup_by_name(name) {
|
|
|
|
Some(Symbol { spec: SymbolSpec::DataConstructor { index, type_args, type_name}, .. }) => Expr::Constructor {
|
|
|
|
type_name: type_name.clone(),
|
|
|
|
name: name.clone(),
|
|
|
|
tag: index.clone(),
|
|
|
|
arity: type_args.len(),
|
|
|
|
},
|
|
|
|
_ => Expr::Val(name.clone()),
|
2018-06-12 03:02:50 -07:00
|
|
|
},
|
2018-05-11 23:34:26 -07:00
|
|
|
Call { f, arguments } => Expr::Call {
|
2018-06-12 02:56:28 -07:00
|
|
|
f: Box::new(f.reduce(symbol_table)),
|
|
|
|
args: arguments.iter().map(|arg| arg.reduce(symbol_table)).collect(),
|
2018-05-11 02:58:14 -07:00
|
|
|
},
|
2018-06-12 02:56:28 -07:00
|
|
|
TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.reduce(symbol_table)).collect()),
|
2018-07-24 03:12:00 -07:00
|
|
|
IfExpression { discriminator, body } => reduce_if_expression(discriminator, body, symbol_table),
|
2018-05-12 12:56:39 -07:00
|
|
|
_ => Expr::UnimplementedSigilValue,
|
2018-05-11 00:45:32 -07:00
|
|
|
}
|
2018-05-10 23:41:51 -07:00
|
|
|
}
|
2018-05-09 02:49:49 -07:00
|
|
|
}
|
2018-05-10 23:41:51 -07:00
|
|
|
|
2018-07-24 03:12:00 -07:00
|
|
|
fn reduce_if_expression(discriminator: &Discriminator, body: &IfExpressionBody, symbol_table: &SymbolTable) -> Expr {
|
|
|
|
let cond = Box::new(match *discriminator {
|
|
|
|
Discriminator::Simple(ref expr) => expr.reduce(symbol_table),
|
2018-10-20 00:55:37 -07:00
|
|
|
Discriminator::BinOp(ref _expr, ref _binop) => panic!("Can't yet handle binop discriminators")
|
2018-07-24 03:12:00 -07:00
|
|
|
});
|
|
|
|
match *body {
|
|
|
|
IfExpressionBody::SimpleConditional(ref then_clause, ref else_clause) => {
|
|
|
|
let then_clause = then_clause.iter().map(|expr| expr.reduce(symbol_table)).collect();
|
|
|
|
let else_clause = match else_clause {
|
|
|
|
None => vec![],
|
|
|
|
Some(stmts) => stmts.iter().map(|expr| expr.reduce(symbol_table)).collect(),
|
|
|
|
};
|
|
|
|
Expr::Conditional { cond, then_clause, else_clause }
|
|
|
|
},
|
|
|
|
IfExpressionBody::SimplePatternMatch(ref pat, ref then_clause, ref else_clause) => {
|
|
|
|
let then_clause = then_clause.iter().map(|expr| expr.reduce(symbol_table)).collect();
|
|
|
|
let else_clause = match else_clause {
|
|
|
|
None => vec![],
|
|
|
|
Some(stmts) => stmts.iter().map(|expr| expr.reduce(symbol_table)).collect(),
|
|
|
|
};
|
2018-08-13 23:28:03 -07:00
|
|
|
|
2018-08-05 18:01:42 -07:00
|
|
|
let alternatives = vec![
|
2018-10-29 01:50:43 -07:00
|
|
|
pat.to_alternative(then_clause, symbol_table),
|
2018-10-18 01:54:36 -07:00
|
|
|
Alternative::default(else_clause),
|
2018-08-05 18:01:42 -07:00
|
|
|
];
|
|
|
|
|
2018-08-14 12:37:18 -07:00
|
|
|
Expr::CaseMatch {
|
2018-08-05 18:01:42 -07:00
|
|
|
cond,
|
|
|
|
alternatives,
|
2018-07-25 03:05:40 -07:00
|
|
|
}
|
2018-07-24 03:12:00 -07:00
|
|
|
},
|
2018-08-15 09:34:00 -07:00
|
|
|
IfExpressionBody::GuardList(ref guard_arms) => {
|
2018-10-19 11:02:10 -07:00
|
|
|
let mut alternatives = vec![];
|
|
|
|
for arm in guard_arms {
|
|
|
|
match arm.guard {
|
|
|
|
Guard::Pat(ref p) => {
|
|
|
|
let item = arm.body.iter().map(|expr| expr.reduce(symbol_table)).collect();
|
2018-10-29 01:50:43 -07:00
|
|
|
let alt = p.to_alternative(item, symbol_table);
|
2018-10-19 11:02:10 -07:00
|
|
|
alternatives.push(alt);
|
|
|
|
},
|
|
|
|
Guard::HalfExpr(HalfExpr { op: _, expr: _ }) => {
|
|
|
|
return Expr::UnimplementedSigilValue
|
|
|
|
}
|
2018-08-24 16:04:18 -07:00
|
|
|
}
|
2018-10-19 11:02:10 -07:00
|
|
|
}
|
2018-08-15 18:32:44 -07:00
|
|
|
Expr::CaseMatch { cond, alternatives }
|
2018-08-15 09:34:00 -07:00
|
|
|
}
|
2018-07-24 03:12:00 -07:00
|
|
|
}
|
|
|
|
}
|
2018-10-19 17:27:06 -07:00
|
|
|
/* ig var pat
|
|
|
|
* x is SomeBigOldEnum(_, x, Some(t))
|
|
|
|
*/
|
|
|
|
|
2018-10-30 18:53:34 -07:00
|
|
|
fn handle_symbol(symbol: &Symbol, subpatterns: &Vec<Pattern>) -> Subpattern {
|
|
|
|
use self::Pattern::*;
|
|
|
|
let tag = match symbol.spec {
|
|
|
|
SymbolSpec::DataConstructor { index, .. } => index.clone(),
|
|
|
|
_ => panic!("Symbol is not a data constructor - this should've been caught in type-checking"),
|
|
|
|
};
|
|
|
|
let bound_vars = subpatterns.iter().map(|p| match p {
|
|
|
|
Literal(PatternLiteral::VarPattern(var)) => Some(var.clone()),
|
|
|
|
_ => None,
|
|
|
|
}).collect();
|
2018-07-24 03:12:00 -07:00
|
|
|
|
2018-10-30 18:53:34 -07:00
|
|
|
/*
|
|
|
|
let guard_equality_exprs: Vec<Expr> = subpatterns.iter().map(|p| match p {
|
|
|
|
Literal(lit) => match lit {
|
|
|
|
_ => unimplemented!()
|
|
|
|
},
|
|
|
|
_ => unimplemented!()
|
|
|
|
}).collect();
|
|
|
|
*/
|
2018-10-15 19:54:17 -07:00
|
|
|
|
2018-10-30 18:53:34 -07:00
|
|
|
let guard = None;
|
|
|
|
let subpatterns = vec![];
|
2018-10-19 17:27:06 -07:00
|
|
|
|
2018-10-30 18:53:34 -07:00
|
|
|
Subpattern {
|
|
|
|
tag: Some(tag),
|
|
|
|
subpatterns,
|
|
|
|
guard,
|
|
|
|
bound_vars,
|
|
|
|
}
|
|
|
|
}
|
2018-10-15 19:54:17 -07:00
|
|
|
|
2018-10-30 18:53:34 -07:00
|
|
|
impl Pattern {
|
|
|
|
fn to_alternative(&self, item: Vec<Stmt>, symbol_table: &SymbolTable) -> Alternative {
|
|
|
|
use self::Pattern::*;
|
2018-08-24 16:04:18 -07:00
|
|
|
match self {
|
|
|
|
TupleStruct(name, subpatterns) => {
|
2018-10-15 19:54:17 -07:00
|
|
|
let symbol = symbol_table.lookup_by_name(name).expect(&format!("Symbol {} not found", name));
|
2018-10-30 18:46:06 -07:00
|
|
|
let s = handle_symbol(symbol, subpatterns);
|
|
|
|
Alternative {
|
|
|
|
tag: s.tag,
|
|
|
|
subpatterns: s.subpatterns,
|
|
|
|
guard: s.guard,
|
|
|
|
bound_vars: s.bound_vars,
|
|
|
|
item
|
|
|
|
}
|
2018-08-24 16:04:18 -07:00
|
|
|
},
|
2018-10-20 00:55:37 -07:00
|
|
|
TuplePattern(_items) => {
|
2018-08-24 16:04:18 -07:00
|
|
|
unimplemented!()
|
|
|
|
},
|
|
|
|
Record(_name, _pairs) => {
|
|
|
|
unimplemented!()
|
|
|
|
},
|
2018-10-18 01:54:36 -07:00
|
|
|
Ignored => Alternative::default(item),
|
2018-10-30 18:53:34 -07:00
|
|
|
Literal(lit) => {
|
|
|
|
let s = lit.to_subpattern(symbol_table);
|
|
|
|
Alternative {
|
|
|
|
tag: s.tag,
|
|
|
|
subpatterns: s.subpatterns,
|
|
|
|
bound_vars: s.bound_vars,
|
|
|
|
guard: s.guard,
|
|
|
|
item
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PatternLiteral {
|
|
|
|
fn to_subpattern(&self, symbol_table: &SymbolTable) -> Subpattern {
|
|
|
|
use self::PatternLiteral::*;
|
|
|
|
match self {
|
|
|
|
NumPattern { neg, num } => {
|
|
|
|
let comparison = Expr::Lit(match (neg, num) {
|
|
|
|
(false, ExpressionType::NatLiteral(n)) => Lit::Nat(*n),
|
|
|
|
(false, ExpressionType::FloatLiteral(f)) => Lit::Float(*f),
|
|
|
|
(true, ExpressionType::NatLiteral(n)) => Lit::Int(-1*(*n as i64)),
|
|
|
|
(true, ExpressionType::FloatLiteral(f)) => Lit::Float(-1.0*f),
|
|
|
|
_ => panic!("This should never happen")
|
|
|
|
});
|
|
|
|
let guard = Some(Expr::Call {
|
|
|
|
f: Box::new(Expr::Func(Func::BuiltIn(Rc::new("==".to_string())))),
|
|
|
|
args: vec![comparison, Expr::ConditionalTargetSigilValue],
|
|
|
|
});
|
|
|
|
Subpattern {
|
|
|
|
tag: None,
|
|
|
|
subpatterns: vec![],
|
|
|
|
guard,
|
|
|
|
bound_vars: vec![],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
StringPattern(_s) => unimplemented!(),
|
|
|
|
BoolPattern(b) => {
|
|
|
|
let guard = Some(if *b {
|
|
|
|
Expr::ConditionalTargetSigilValue
|
|
|
|
} else {
|
|
|
|
Expr::Call {
|
|
|
|
f: Box::new(Expr::Func(Func::BuiltIn(Rc::new("!".to_string())))),
|
|
|
|
args: vec![Expr::ConditionalTargetSigilValue]
|
2018-10-15 19:54:17 -07:00
|
|
|
}
|
2018-10-30 18:53:34 -07:00
|
|
|
});
|
|
|
|
Subpattern {
|
|
|
|
tag: None,
|
|
|
|
subpatterns: vec![],
|
|
|
|
guard,
|
|
|
|
bound_vars: vec![],
|
2018-10-15 19:54:17 -07:00
|
|
|
}
|
2018-08-24 16:04:18 -07:00
|
|
|
},
|
2018-10-30 18:53:34 -07:00
|
|
|
VarPattern(var) => match symbol_table.lookup_by_name(var) {
|
|
|
|
Some(symbol) => handle_symbol(symbol, &vec![]),
|
|
|
|
None => Subpattern {
|
|
|
|
tag: None,
|
|
|
|
subpatterns: vec![],
|
|
|
|
guard: None,
|
|
|
|
bound_vars: vec![Some(var.clone())],
|
|
|
|
}
|
|
|
|
}
|
2018-08-24 16:04:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-10 23:41:51 -07:00
|
|
|
impl Declaration {
|
2018-06-12 02:56:28 -07:00
|
|
|
fn reduce(&self, symbol_table: &SymbolTable) -> Stmt {
|
2018-05-11 02:24:38 -07:00
|
|
|
use self::Declaration::*;
|
2018-06-04 19:25:40 -07:00
|
|
|
use ::ast::Signature;
|
2018-05-11 02:24:38 -07:00
|
|
|
match self {
|
2018-06-12 02:56:28 -07:00
|
|
|
Binding {name, constant, expr } => Stmt::Binding { name: name.clone(), constant: *constant, expr: expr.reduce(symbol_table) },
|
2018-05-13 17:24:21 -07:00
|
|
|
FuncDecl(Signature { name, params, .. }, statements) => Stmt::PreBinding {
|
2018-05-11 22:44:21 -07:00
|
|
|
name: name.clone(),
|
2018-05-13 17:24:21 -07:00
|
|
|
func: Func::UserDefined {
|
|
|
|
name: Some(name.clone()),
|
2018-05-11 22:44:21 -07:00
|
|
|
params: params.iter().map(|param| param.0.clone()).collect(),
|
2018-06-12 02:56:28 -07:00
|
|
|
body: statements.iter().map(|stmt| stmt.reduce(symbol_table)).collect(),
|
2018-05-13 17:24:21 -07:00
|
|
|
}
|
2018-05-11 22:44:21 -07:00
|
|
|
},
|
2018-07-12 02:07:52 -07:00
|
|
|
TypeDecl { .. } => Stmt::Noop,
|
2018-07-18 16:01:59 -07:00
|
|
|
TypeAlias(_, _) => Stmt::Noop,
|
|
|
|
Interface { .. } => Stmt::Noop,
|
|
|
|
Impl { .. } => Stmt::Expr(Expr::UnimplementedSigilValue),
|
2018-05-11 02:24:38 -07:00
|
|
|
_ => Stmt::Expr(Expr::UnimplementedSigilValue)
|
|
|
|
}
|
2018-05-10 23:41:51 -07:00
|
|
|
}
|
2018-05-09 02:27:57 -07:00
|
|
|
}
|
2018-05-09 17:02:10 -07:00
|
|
|
|
2018-05-10 23:41:51 -07:00
|
|
|
impl BinOp {
|
2018-06-12 02:56:28 -07:00
|
|
|
fn reduce(&self, symbol_table: &SymbolTable, lhs: &Box<Expression>, rhs: &Box<Expression>) -> Expr {
|
2018-05-12 03:51:42 -07:00
|
|
|
if **self.sigil() == "=" {
|
|
|
|
Expr::Assign {
|
2018-06-12 02:56:28 -07:00
|
|
|
val: Box::new(lhs.reduce(symbol_table)),
|
|
|
|
expr: Box::new(rhs.reduce(symbol_table)),
|
2018-05-12 03:51:42 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let f = Box::new(Expr::Func(Func::BuiltIn(self.sigil().clone())));
|
2018-06-12 02:56:28 -07:00
|
|
|
Expr::Call { f, args: vec![lhs.reduce(symbol_table), rhs.reduce(symbol_table)]}
|
2018-05-12 03:51:42 -07:00
|
|
|
}
|
2018-05-10 23:41:51 -07:00
|
|
|
}
|
2018-05-09 17:02:10 -07:00
|
|
|
}
|
|
|
|
|
2018-05-10 23:41:51 -07:00
|
|
|
impl PrefixOp {
|
2018-06-12 02:56:28 -07:00
|
|
|
fn reduce(&self, symbol_table: &SymbolTable, arg: &Box<Expression>) -> Expr {
|
2018-05-11 23:34:26 -07:00
|
|
|
let f = Box::new(Expr::Func(Func::BuiltIn(self.sigil().clone())));
|
2018-06-12 02:56:28 -07:00
|
|
|
Expr::Call { f, args: vec![arg.reduce(symbol_table)]}
|
2018-05-10 23:41:51 -07:00
|
|
|
}
|
2018-05-09 17:02:10 -07:00
|
|
|
}
|