diff options
author | David Li <li.davidm96@gmail.com> | 2017-11-26 19:33:08 -0500 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2017-11-26 19:33:08 -0500 |
commit | 376a1217a63291fb6714430b1a4dfd64909906c9 (patch) | |
tree | 5c6889993b19e51e4a05e9d70054e5434b0ef8ae | |
parent | 00945be8de227e2a6f56819e5864b58559e37ee6 (diff) |
Translate binop (only num + num)
-rw-r--r-- | src/semantic/analysis.rs | 4 | ||||
-rw-r--r-- | src/semantic/translate.rs | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/semantic/analysis.rs b/src/semantic/analysis.rs index cf19351..09832c4 100644 --- a/src/semantic/analysis.rs +++ b/src/semantic/analysis.rs @@ -218,8 +218,8 @@ fn trans_exp<'a, F: frame::Frame>( &Add => { match (left_ty, right_ty) { (Ty::Int, Ty::Int) => { - err!(exp, TypeError::Unimplemented) - // Ok(Ty::Int) + Ok((tr.make_binop(ir::Binop::Plus, left_exp, right_exp), + Ty::Int)) } (Ty::String, Ty::String) => { err!(exp, TypeError::Unimplemented) diff --git a/src/semantic/translate.rs b/src/semantic/translate.rs index 179eb62..bcbad3a 100644 --- a/src/semantic/translate.rs +++ b/src/semantic/translate.rs @@ -48,4 +48,13 @@ impl<F: frame::Frame> Translate<F> { pub fn make_num(&mut self, num: u64) -> Expression { Expression::Exp(ir::Expression::Const(num)) } + + pub fn make_binop(&mut self, op: ir::Binop, + left: Expression, right: Expression) -> Expression { + match (left, right) { + (Expression::Exp(left), Expression::Exp(right)) => + Expression::Exp(ir::Expression::Binop(op, Box::new(left), Box::new(right))), + _ => panic!("Can't make binop from Void"), + } + } } |