lua-users home
lua-l archive

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


Hi,

I am trying to get a minimal Lua VM to run on Cortex M4. I do not need the parser, only byte code execution.

I have done all the changes in https://www.lua.org/notes/ltn002.html

Also I removed all libraries except base:
/*
** these libs are loaded by lua.c and are readily available to any Lua
** program
*/
static const luaL_Reg loadedlibs[] = {
  {"_G", luaopen_base},
//  {LUA_LOADLIBNAME, luaopen_package},
//  {LUA_COLIBNAME, luaopen_coroutine},
//  {LUA_TABLIBNAME, luaopen_table},
//  {LUA_IOLIBNAME, luaopen_io},
//  {LUA_OSLIBNAME, luaopen_os},
//  {LUA_STRLIBNAME, luaopen_string},
 // {LUA_MATHLIBNAME, luaopen_math},
 // {LUA_UTF8LIBNAME, luaopen_utf8},
//  {LUA_DBLIBNAME, luaopen_debug},
#if defined(LUA_COMPAT_BITLIB)
  {LUA_BITLIBNAME, luaopen_bit32},
#endif
  {NULL, NULL}
};

This reduced the size to 63k for the Lua executable with maximum release optimization for x86 msvc 2015 and on cortex m4 its about 59k

I generally need only table indexing and function calls, so I compiled one of the common scripts which I intend to run on the cortex m4, and saw that it does not use most opcodes(I used chunkspy to decompile and see the opcodes). 

I may need Lua's other language features later, so I decided to try optimizing its VM first.

So now I am removing some of the opcodes, which maybe a bit risky(I am commenting out the relevant vmcase in lvm.c).

What are my other options to reduce the size? I would like to bring down the Lua executable's size to about 10k like eLua!

I am not directly using eLua as it seems to have a number of other things apart from Lua which may not be easy to remove(haven't checked in detail though)

I am also trying out Lua 4.0 to see if I can get a smaller size

Thanks for your help.
Abhijit