-
Notifications
You must be signed in to change notification settings - Fork 5
AOT or JIT
Assuming we are able to compile Lua source then how do we hook everything up with Lua?
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.
The OP_CLOSURE opcode creates a closure from given proto and sets this to a variable.
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.
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.
Latest version generates all the C code upfront so no reverse calls to Ravi necessary during compilation.