Make the VM Lua-version-agnostic and modularize

  • From: "Soni L." <fakedme+lj@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 23 Sep 2015 15:27:42 -0300

Currently LuaJIT works like this:

The VM is made for Lua 5.1.
The parser can only do Lua 5.1, with some extensions from Lua 5.2.
Can't support anything else because that's how it is.

My proposal is to basically make the VM Lua-version-agnostic. Instead of making it specific for Lua 5.1, we make it for Lua 5.1, Lua 5.2 AND Lua 5.3. Then, instead of backporting features, we do something different:

1. Command line switches, like -51, -52, -53.
2. require("5.1"), require("5.2"), require("5.3"), which return the global environment for Lua 5.1, Lua 5.2 and Lua 5.3, respectively.
3. The Lua 5.1 global environment's loadstring() would run a Lua 5.1 parser and emit "LuaJIT MultiLua Bytecode" (or w/e you wanna name it). The Lua 5.2 global environment's load() would run a Lua 5.2 parser and emit "LuaJIT MultiLua Bytecode". The Lua 5.3 global environment's load() would run a Lua 5.3 parser and emit "LuaJIT MultiLua Bytecode".
4. The different standard libraries would provide different features for each language version. Lua 5.2+'s require would pass 2 arguments (modname, path) to the loaded module, while Lua 5.1's would pass just 1.

This allows for Lua 5.1 compliance, but also Lua 5.2 and Lua 5.3 compliance. All in a single VM. Just requires some extra modularization.

It /might/ also be possible to make an unified C API/ABI. A C API/ABI that has support for all of Lua 5.1's API, Lua 5.2's API and Lua 5.3's API.

We already have bytecodes for bit operations (I think? not sure) (aka we have Lua 5.3 bitops just waiting to be implemented), we already have lots of things from Lua 5.2's stdlib (table.pack, table.unpack, etc), we just need to add some things from Lua 5.3 and a parser for it.

We could also reuse code between versions.

Other related posts: