@@ -8,7 +8,7 @@ use std::{borrow::Cow, mem::forget, ops::Deref};
88use bumpalo:: { Bump , collections:: Vec } ;
99use parser:: {
1010 Atom , BinaryOperator , BinaryPlaceOperator , Body , Expr , ExprNode , Place , SimpleStatement ,
11- Statement , UnaryOperator , Variable ,
11+ Statement , UnaryOperator , UnaryPlaceOperator , Variable ,
1212} ;
1313
1414use crate :: {
@@ -225,6 +225,39 @@ impl<'a> Code<'a> {
225225
226226 self . free_reg ( lhs) ;
227227 }
228+ ExprNode :: UnaryPlaceOperation ( op, place) => {
229+ let rhs = self . alloc_reg ( ) ;
230+ let one = self . register_const ( Value :: Float ( 1. ) ) ;
231+ self . bc . emit ( Instruction :: LoadConst ( ( * rhs, one) ) ) ;
232+ self . load_place ( dest, place) ;
233+
234+ let second_op = match op {
235+ UnaryPlaceOperator :: IncrementL | UnaryPlaceOperator :: IncrementR => {
236+ Instruction :: Add
237+ }
238+ UnaryPlaceOperator :: DecrementL | UnaryPlaceOperator :: DecrementR => {
239+ Instruction :: Subtract
240+ }
241+ } ;
242+ match op {
243+ UnaryPlaceOperator :: IncrementL | UnaryPlaceOperator :: DecrementL => {
244+ self . bc . emit ( second_op ( ( dest, dest, * rhs) ) ) ;
245+ self . store_place ( place, dest) ;
246+ }
247+ UnaryPlaceOperator :: IncrementR | UnaryPlaceOperator :: DecrementR => {
248+ // force dest to concrete num:
249+ let tmp = self . alloc_reg ( ) ;
250+ let zero = self . register_const ( Value :: Float ( 0. ) ) ;
251+ self . bc . emit ( Instruction :: LoadConst ( ( * tmp, zero) ) ) ;
252+ self . bc . emit ( Instruction :: Add ( ( dest, dest, * tmp) ) ) ;
253+
254+ self . bc . emit ( second_op ( ( * tmp, dest, * rhs) ) ) ;
255+ self . store_place ( place, * tmp) ;
256+ self . free_reg ( tmp) ;
257+ }
258+ }
259+ self . free_reg ( rhs) ;
260+ }
228261 _ => todo ! ( ) ,
229262 } ,
230263 }
0 commit comments