jserv / amacc

Small C Compiler generating ELF executable Arm architecture, supporting JIT execution
Other
1.01k stars 159 forks source link

How left shift handles negative number? #46

Closed alapha23 closed 5 years ago

alapha23 commented 5 years ago

It seems left shift on negative numbers are not handled properly.

Make check has error message as below:

- 4 << -1 = 0
?                ^
+ 4 << -1 = 2
?                 ^

I traced the source code and it seemed the negative numbers have not been taken into consideration in our semantics.

At line 618 of amacc.c

case Shl: next(); *++e = PSH; expr(Add); *++e = SHL; ty = INT; break;

So is it a bug or a feature of our compiler? Please do correct me if I missed out something.

jserv commented 5 years ago

Dupilcated by #39