bytecode cross-compiled on dev machine #481
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this PR is a pretty big refactor of how we run lua code on crow. previously we would save all the baked-in lua files in their regular string representation & load (compile) them at runtime on crow.
this PR includes an additional luacc (cross-compilation) stage which compiles the lua files into lua bytecode and saves that into the flash image. the benefit is much reduced runtime RAM when loading libraries as they can be loaded directly into the VM without needing to be parsed at runtime.
the RAM used by the lua machine is not decreased, nor is FLASH space decreased (bytecode is similar in size to the strings), but it's just the compilation process that doesn't need to allocate anything.
while this has improved the situation where crow would freeze when running scripts that utilize multiple different
iidevices, it still hasn't solved the problem. previously we would fail on the 2ndiidevice being loaded, and now we fail on the 3rd. it's also not a matter of the garbage collector needing to be tuned, as a full GC cycle is run after any file is loaded into the VM.still, this feels like an improvement of the system, and i would like to push it into
main. that said, there's no point rushing it out now as we still haven't solved the fundamental problem which led me to work on this.//
note the cross-compiler is built from this branch https://github.com/trentgill/lua/tree/luacc-5.3.4
invoke it from the root directory with:
and the binary
luaccis created atsrc/luacc.it is just copied into this repo for convenience (and bc i can't have 2 submodules referencing the same repo afaik).
it should be easily converted for other lua versions should we need. just need to make sure to pass
-DLUA_32BITSto the compiler. the only file changed issrc/ldump.cinDumpHeaderwhere we override the sizeofsize_tandintto be 32 bits (uint32_t).//
unfortunately the github action is broken because apparently
luaccneeds to be compiled for whatever system they are running on which i have no real sense of. it should be as easy as changingmake linuxtomake <platform>, but we'd need to run that compilation in the action which i have no clue how to do.