lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Lua has 10 types (as far "none" is a type too?)

Nil and boolean and none can share one type. In the >48bit field.
#define LUA_TNONE       (-1)
#define LUA_TNIL        0
#define LUA_TBOOLEAN        1

Number doesnt need an encoding therre, its everything non NAN, or NAN as in NAN.
#define LUA_TNUMBER     3

Leaves 6 types with pointers.

#define LUA_TLIGHTUSERDATA  2
#define LUA_TSTRING     4
#define LUA_TTABLE      5
#define LUA_TFUNCTION       6
#define LUA_TUSERDATA       7
#define LUA_TTHREAD     8

6+1 (for NIL; BOOLEAN and NONE) = 7, 3 bit suffice ;-)

On Fri, Jul 8, 2011 at 6:18 AM, Miles Bader <miles@gnu.org> wrote:
> Axel Kittenberger <axkibe@gmail.com> writes:
>>> Though you then need to get slightly more creative about encoding the
>>> type. A double has 52 bits of mantissa; with 48 taken for a
>>> pointer-sized value, and 1 taken to ensure a quiet NaN, you only have
>>> 3 bits left to encode the type. If you borrow the sign bit as well,
>>> then you have 4 bits. For reference, the current implementation in 5.2
>>> beta uses 6 bits for encoding type.
>>
>> Dont you need just 1 bit to encode if its a pointer or something else.
>> Or 2 bits for the various different pointer types Lua has (light user
>> data vs "heavy" user data, etc.).
>
> There are a fair number of immediate types that contain pointers.
>
> Many of them point to Lua internal objects (table, string, function,
> etc), which can all share a header in the object that contains another
> tag field to distinguish among them.  However pointer immediates which
> point to external objects need to have unique tags in the immediate
> value.
>
> [See my previous post in this thread for a bit more detail.]
>
> -Miles
>
> --
> "Yorton, Wressle, and Gospel Oak, the richness of your heritage is ended.
> We shall not stop at you again; for Dr Beeching stops at nothing."
>