pharo-vm
pharo-vm copied to clipboard
(&) bitAnd vs integerAnd
C lang defines two ways to perform an AND operation: one for booleans and the other for integers (keep the sign).
To represent this difference, there are two methods in Slang &&
and bitAnd:
.
Sometimes, we fail to choose the correct method, overpassing the checks in Slang and the C compiler.
For example, https://github.com/Alamvic/druid/commit/de7af6f9e0b8ef33b788caefe70c5530019e915d#diff-df143dcb625fab9632c19e459636eca5ed081f3f308b742420b793b23c86ef95L78.
It would be nice to infer the use of &&
based on the receiver (or arguments) type and compile as expected or at least alert the developers that there is some undefined behaviour
(then they can clarify with some unambiguous operation).
Related are: https://github.com/pharo-project/pharo-vm/pull/523 and #446 by @hernanmd. I think you should take a look at the discussions there.
Before this used to do the wrong translation using the wrong type (the developer has to guess which is which). And we forbid it at compile time to avoid this kind of issues.
So what we do?
AFAIK, @ivojawer (gsoc student) will probably do another pass on those issues to enhance the situation:
- make & translate as bitAnd if the receiver and arguments are integers
- make & translate as and: if the receiver and arguments are booleans
- throw a type error otherwise?