codefrau / SqueakJS

A Squeak Smalltalk VM in Javascript
https://squeak.js.org
MIT License
371 stars 76 forks source link

Support for 61-bit SmallIntegers in 64-bit images #161

Closed LinqLover closed 7 months ago

LinqLover commented 7 months ago

This is not meant to be merged at the moment but rather to document an open issue. I was confused that when opening 64-bit images in SqueakJS, arithmetic primitives are unable to work with 61-bit numbers as in the OSVM. In this PR, I attempted to fix this by making the relevant constants dynamic depending on the image, but then realized that JS numbers have a smaller value range than Squeak 64-bit SmallIntegers. We could use bigints instead but these require explicit conversions for all arithmetic operations with normal numbers, which would clutter the code base and slow things down.

Thus, the open questions are:

If this feature is not possible or a good idea, maybe this decision should be documented somewhere (such as directly at the constants) before the next person stumbles about this again. :D

LinqLover commented 7 months ago

Forgot to mention another issue with not supporting 61-bit SmallIntegers in 64-bit images: IIRC this caused problems for me when running the image-side simulator in SqueakJS because there were some larger SmallIntegers in the headers of some methods that could not be accessed correctly. Sorry, can't reproduce ...

codefrau commented 7 months ago

SqueakJS converts 64 bit images to 32 bits on load. I don't see a point in supporting 64 bits at runtime since it would not get any faster, but a lot more complex.

We could support converting to 64 bits when saving. I haven't really had the need for that yet though.

codefrau commented 7 months ago

(I'm happy to be convinced otherwise if you want to explore this in your fork – but there are quite a few places where the "number" == SmallInteger is used, not the least in the JIT, so I can't imagine this being a change that does not make everything a lot more complex.)

Re BigInt – I'm not generally opposed to that. Happy to start using more modern JS features that were not around in 2013 when this project started. This could be really useful in a LargeInteger plugin for example – or by handling LargeIntegers natively (like we handle boxed floats).