lua-users home
lua-l archive

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


I implemented integer and number array types in Ravi - the main
objective was to improve JIT compilation and inline code generation
for access to array elements.

One of the other enhancements I have been thinking about for a while
is to efficiently support aggregate types. Mainly the idea I have been
playing around with is to implement such types using tables - but with
numeric indices. The reason for using a numeric index is to help
generate efficient code. For example a 'get' operation could be
inlined thus:

if (l_castS2U(key - 1) < t->sizearray)
    v = &t->array[key - 1];
    v = luaH_getint(t, key);

The problem with numeric indices is readability and error-proneness.
It is more readable to say:


than say:


But if there was a way to assign symbolic names to numeric values then
maybe one could write:

constant name = 1


The compiler would know that name is a constant and replace
Employee->name with Employee[1]. The use of the '->' syntax is to
distinguish between this transformation versus the standard Lua syntax
of accessing elements by key. One can envisage a macro pre-compiler
that does this transformation allowing the transformed code to just
work as regular Lua code.

The second aspect of this is that the compiler needs to know that the
variable is an array type so that it can generate efficient code.
Extending the static typing in Ravi is one way to do it:

local Employee : [] = { 'dibyendu', 'majumdar' }

Above could be how an array of dynamic types is declared.

I apologise in advance for sharing this very half baked idea - I am
sure people will find holes in this thinking immediately. Anyway I
would be interested to hear your views.