A special, built-in value type: a 64-bit "fixnum"

Brian Goetz brian.goetz at oracle.com
Wed Apr 22 12:47:49 UTC 2015


This would be the basis for an “Any”-like type.  Dynamic languages use the “primitive or reference” trick all the time.  If you have a number, if it’s small, you’d like to represent it as an int, but if it overflows, you need to overflow to an object.  Implementations tend to resort to having an array of primitives and an array of refs, and for each index, use one or the other (generally if the ref is null, use the primitive.)

On Apr 22, 2015, at 2:41 PM, Vitaly Davidovich <vitalyd at gmail.com> wrote:

> Can you provide a somewhat concrete example where this would be useful?
> 
> sent from my phone
> On Apr 22, 2015 7:12 AM, "Ron Pressler" <ron at paralleluniverse.co> wrote:
> 
>> Hi.
>> I'd like to propose that the Valhalla project include a single special,
>> built-in value type: a 64-bit "fixnum". The value has a single bit
>> discriminating between a reference or a 63-bit long. It will, of course, be
>> treated correctly by the GC.
>> 
>> For completeness, a couple of static helper functions may be introduced.
>> One that takes a long and, preserving the sign, truncates it to 63 bits,
>> throwing an exception in the case of an overflow, and the other taking a
>> double and truncating down to 63 bits, truncating precision by one bit (and
>> another for the reverse 63-bit double -> double operation).
>> 
>> I believe this will be immensely useful for some applications that
>> currently require two separate arrays to store a value of either a
>> primitive or a reference, yet would require minimal work for GC support. Of
>> course, this proposal can be extended to directly support any 63-bit (or
>> smaller) value type, but even in its minimal form it is extremely useful.
>> 
>> Ron
>> 



More information about the valhalla-dev mailing list