maximecb / uvm

Fun, portable, minimalistic virtual machine.
Apache License 2.0
538 stars 19 forks source link

Postfix increment and decrement operator not working #10

Open hd-COO7 opened 1 year ago

hd-COO7 commented 1 year ago

Prefix increment/decrement operator seems to be working fine but postfix increment/decrement operator throws error. Code to reproduce

int i =0;
while(i < 5) {
    i++;
}

This behaviour is not limited to any type. Was able to reproduce this for pointers was well in similar fashion

calroc commented 1 year ago

Also --var; as a statement by itself compiles but doesn't seem to actually decrement the variable.

maximecb commented 1 year ago

Also --var; as a statement by itself compiles but doesn't seem to actually decrement the variable.

Oh that must be because it evaluates to the negation of the negation of. Should be super easy to implement prefix decrement since there's already an implementation of ++var. PR welcome.

If you do add a PR, make sure to add one or more tests as well. There are tests in codegen.rs and under ncc/tests/expressions.c.

maximecb commented 1 year ago

Prefix increment/decrement operator seems to be working fine but postfix increment/decrement operator throws error. Code to reproduce

int i =0;
while(i < 5) {
    i++;
}

This behaviour is not limited to any type. Was able to reproduce this for pointers was well in similar fashion

At the moment we have pre-increment but not post-increment because it's slightly trickier to implement. PR welcome.

maximecb commented 1 year ago

Also --var; as a statement by itself compiles but doesn't seem to actually decrement the variable.

Just added prefix decrement, --var works now.