Skip to content

AOT or JIT

Dibyendu Majumdar edited this page Nov 28, 2020 · 3 revisions

AOT or JIT

Assuming we are able to compile Lua source then how do we hook everything up with Lua?

Lua Load

The Lua load function compiles Lua code and leaves a closure on the stack representing the main chunk. This closure has a proto attached to it, which also references all the child protos.

Lua function calls

The OP_CLOSURE opcode creates a closure from given proto and sets this to a variable.

JIT mode

In JIT mode we need to behave like load, e.g. we could have a special JIT load api. For each proc we need to create Proto structure and associate the code with it. For the top level chunk we need to create a closure and associate the top level proto with it. The load must push the closure to the Lua stack.

AOT mode

The generated C code for the Lua chunk, should also include, as an epilogue, code to construct the protos, and the closure object, and this code should be invoked by the open call to construct and push the Lua closure on to the stack. This can be done in the same way that lua undump works, except we will not have any bytecodes to load.

TODO we need to ensure that the generated code can be loaded similarly to Lua code.

Interfacing with Lua without a hard link

Latest version generates all the C code upfront so no reverse calls to Ravi necessary during compilation.