pharo-vm icon indicating copy to clipboard operation
pharo-vm copied to clipboard

(&) bitAnd vs integerAnd

Open PalumboN opened this issue 1 year ago • 3 comments

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).

PalumboN avatar Aug 01 '23 14:08 PalumboN

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.

guillep avatar Aug 02 '23 09:08 guillep

So what we do?

hernanmd avatar Aug 02 '23 12:08 hernanmd

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?

guillep avatar Aug 02 '23 12:08 guillep