diff options
Diffstat (limited to 'src/semantic')
-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"), + } + } } |