bit-hack/c-compiler

Support post increment / decrement

Closed this issue · 1 comments

Support the post increment / decrement operators.

These operators are a little more tricky to emit because of the single-pass nature of the compiler. It means we need to perform the increment operation but save the old value.

x++;

It would have to turn into the following long-winded instruction sequence:

GETAL 1  ; get address of x
DEREF    ; dereference it to get the old value (leave this on the stack)
GETAL 1  ; get address of x again
DUP      ; duplicate it for lhs and rhs
DEREF    ; dereference rhs
CONST 1  ; constant of 1
ADD      ; add to increment the rhs value
ASSIGN   ; assign to lhs
DROP     ; drop result of assignment leaving old value

These operators are now supported.