Re: How to implement dynamic typing?

"BGB / cr88192" <cr88192@hotmail.com>
Fri, 16 Apr 2010 11:11:57 -0700

          From comp.compilers

Related articles
[13 earlier articles]
Re: How to implement dynamic typing? harold.aptroot@gmail.com (Harold Aptroot) (2010-04-11)
Re: How to implement dynamic typing? cr88192@hotmail.com (BGB / cr88192) (2010-04-11)
Re: How to implement dynamic typing? cr88192@hotmail.com (BGB / cr88192) (2010-04-12)
Re: How to implement dynamic typing? gneuner2@comcast.net (George Neuner) (2010-04-13)
Re: How to implement dynamic typing? bartc@freeuk.com (bartc) (2010-04-14)
Re: How to implement dynamic typing? dot@dotat.at (Tony Finch) (2010-04-14)
Re: How to implement dynamic typing? cr88192@hotmail.com (BGB / cr88192) (2010-04-16)
Re: How to implement dynamic typing? gneuner2@comcast.net (George Neuner) (2010-04-18)
Re: How to implement dynamic typing? bartc@freeuk.com (bartc) (2010-04-18)
Re: How to implement dynamic typing? gneuner2@comcast.net (George Neuner) (2010-04-20)
Re: How to implement dynamic typing? mikelu-1004cc@mike.de (Mike Pall) (2010-04-21)
Re: How to implement dynamic typing? bartc@freeuk.com (bartc) (2010-04-21)
Re: How to implement dynamic typing? gneuner2@comcast.net (George Neuner) (2010-04-22)
[5 later articles]
| List of all articles for this month |
From: "BGB / cr88192" <cr88192@hotmail.com>
Newsgroups: comp.compilers
Date: Fri, 16 Apr 2010 11:11:57 -0700
Organization: albasani.net
References: 10-04-009 10-04-028 10-04-031 10-04-036 10-04-038
Keywords: types
Posted-Date: 18 Apr 2010 01:02:46 EDT

"Tony Finch" <dot@dotat.at> wrote in message
> George Neuner <gneuner2@comcast.net> wrote:


<snip>


> LuaJIT takes an interesting approach. Its only numeric type is the
> double precision floating point number. It uses different kinds of NAN
> as tags for the other types, with the pointer embedded in the
> mantissa.


nifty...




oddly, I would have likely never thought of this (I have instead gone the
opposite route: shoving custom lower-precision float values into pointers).


this strategy would likely work on both x86 (and 32-bit archs in general),
and on x86-64 (if one assumes the original 48-bit address space, where even
both Linux and Win64 use a somewhat smaller space than this).


for example (assuming +NaN vs -NaN):
0x7FF80yyy:xxxxxxxx //tag-value space
0x7FF9yyyy:xxxxxxxx //pointer-space (y=high pointer bits, 0 for x86)


ordering is to avoid a NULL/NaN clash, unless I were to "move" NULL:
0x7FF8yyyy:xxxxxxxx //pointer-space (y=high pointer bits, 0 for x86)
0x7FF90yyy:xxxxxxxx //tag-value space


NULL could be changed to another value, such as "UNDEFINED" or "EOL" (or I
could add another magic value, such as "AUXNULL").




this would require fudging some, as it does conflict with another mechanism
in use (on x86-64), namely my "spaces" mechanism, unless of course "spaces"
were moved into the NaN space by default (and the total space for "spaces"
was shaved down some, since as-is it is 56-bits wide, but each "space" is
limited to 48 bits).


note: "spaces" is the mechanism by which my GC/typesystem manages
non-pointer values embedded into the address space, which in my cases is
allocated linearly (a space is allocated for a number of built-in types, for
non-local / "wide" pointers, ...).




even then, one can still afford to pack the 48-bit flonum and fixnum spaces
into here.
0x7FFAyyyy:xxxxxxxx //flonum space
0x7FFByyyy:xxxxxxxx //fixnum space


(granted, it would be redundant to have these here, but given how my
"spaces" system works, it would likely be needed...).




maybe using +-NaN and +-Inf one can have a bigger space.


0x7FFyyyyy:xxxxxxxx //+ NaN/Inf space (assume special values for NaN and
Inf).
0xFFFyyyyy:xxxxxxxx //- NaN/Inf space (assume special values for NaN and
Inf).


total space size: 53 bits.




as-is, this would only be a minor tweak to my GC to add this feature
(although it would still require an API call to convert between pointers and
doubles, and would likely return a NULL if passed a numeric value).


the dynamic-typesystem code could wrap this converter, but likely also
convert numeric values (where numeric values end up in the somewhat-smaller
"flonum" space).


I know of a few places where a this feature could be extra helpful...


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.