HaxeFoundation/haxe — pull request #2360 by Herschel (2013-11-18 03:33:31+00:00)
Title: Add Int32 abstract for cross-platform 32-bit behavior

* The old Int32 divide function was Int32->Int32->Int32, but I changed it to Int32->Int32->Float to match with the standard division operator.

* I allow implict casting `from Int` and `to Int`, but maybe we want to make casting back to `Int` explicit.

* AS3 target also needed clamping. Even though the AVM has integer instructions and int types, a+b and a*b always promotes to Float in AS3.

* PHP installation can be 64-bit, so I sign-extend the results to match 32-bit behavior. `PHP_INT_SIZE` is used to determine the size of ints on the current php setup.

* genphp generates a _hx_shift_right function to guarantee 32-bit behavior for >>> on `Int`s for 64-bit PHP. This seems odd to me -- why should `Int` guarantee 32-bit semantics on some operators (>>>) and not others (+, *)? And also, it doesn't account for <<, which is still 64-bit. For example, `(1 << 32) >> 32` returns 1 on my php install. IMO, guaranteeing 32-bit behavior should be the job of Int32 for every operator. I've left genphp alone for now, though.

* I'm not exactly sure how to handle cpp. Right now the it uses standard C `int`, which is probably 32-bit on every place you can compile, but this isn't guaranteed. Even the old hxcpp CppInt32__ extern seems to assume `int` is 32-bits. Maybe hxcpp could expose `int32_t` that we could use as a coretype?

The unit tests pass for every platform I was able to test on: as3, cpp, flash, flash8, js, neko, php

Feedback appreciated