mirror of
https://github.com/elua/elua.git
synced 2025-01-08 20:56:17 +08:00
d54659b572
This patch adds more RAM optimizations to eLua: - direct file memory mapping: files in ROMFS will be read directly from Flash, without allocating any additional buffers. This doesn't help with RAM consumption in itself, but enables the set of optimizations below. - pseudo read-only strings. These are still TStrings, but the actual string content can point directly to Flash. Original Lua strings are kept in TStrings structures (lobject.h): typedef union TString { L_Umaxalign dummy; /* ensures maximum alignment for strings */ struct { CommonHeader; lu_byte reserved; unsigned int hash; size_t len; } tsv; } TString; The actual string content comes right after the union TString above. Pseudo RO strings have the same header, but instead of having the string content after TString, they have a pointer that points to the actual string content (which should exist in a RO memory (Flash) that is directly accesbile from the MCU bus (like its internal Flash memory)). lua_newlstr detects automatically if it should create a regular string or a pseudo RO string by checking if the string pointer comes from the Flash region of the MCU. This optimization works for both precompiled (.lc) files that exist in ROMFS and for internal Lua strings (C code). - functions in Flash: for precompiled (.lc) files that exist in ROMFS, the code of the functions and a part of the debug information will be read directly from Flash. - ROMFS was changed to support files that are larger than 2**16 bytes and it aligns all its files to an offset which is a multiple of 4 in order to prevent data alignment issues with precompiled Lua code. - the Lua bytecode dumper was changed to align all the instructions in a Lua function and a part of the debug information to an offset which is a multiple of 4. This might slightly increase the size of the precompiled Lua file. These changes were succesfully checked against the Lua 5.1 test suite. These changes were tested in eLua on LM3S and AVR32.