lua-users home
lua-l archive

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


On Sat, Aug 1, 2015 at 2:48 PM, Dibyendu Majumdar
<mobile@majumdar.org.uk> wrote:
> Hi
>
> One of the problems I have is how to improve the performance of  small
> Lua functions that don't do much but are there for convenience. The
> overhead of a Lua function call is quite high - so what I need is a
> way to inline the functions. Not being a compiler guru this is
> somewhat beyond my capabilities right now. So as a cheaper alternative
> I am thinking of introducing is support for macros as in C - allow
> user to define macros which are preprocessed textually before the
> parser runs. So I am looking for a small and fast opensource
> implementation of a macro preprocessor - the main capability I need is
> the equivalent of #define in C.
>
> The license needs to be liberal so that it is compatible with MIT
> license. It should be written in C so that I can integrate it in Ravi.
>
> If anyone here knows of an implementation that I should look at please
> let me know.
>
> Thanks and Regards
> Dibyendu
>

Hi,

I think it is not an ideal direction to evolve Ravi. C macros have
many disadvantages. And you make the language more complicated.
Optimizing inlinable functions is more interesting direction and it
doesn't require any changes in the language. And you should be a
compiler guru to develop a good language.

Here is some simple approach you can try. I am not a compiler guru, so
this approach may not work.

Find a function similar to macro definition and replace it with a
"macro" internally:

local function xxx(aaa)
  return bbb
end

->

#define xxx(aaa) bbb

where aaa is a list of arguments and bbb is an expression.

The following is required:
 * a set of xxx's upvalues must belong to the set of upvalues of a
code where xxx is inlined. It is satisfied if xxx is used in same
scope where it is defined
 * value of xxx must not change. If it is changed, it must be
de-inlined (and maybe reinlined) in all code using it. So you have to
track all such code.

-- 


Best regards,
Boris Nagaev