Skip to content

Russoul/Idris2-Lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lua backend for Idris 2


Tested against Idris 2, version 0.5.1-96c44abb6

Requirements & Installation

All libraries can be installed via luarocks:

luarocks install luautf8 --lua-version=V --local
luarocks install bigint --lua-version=V --local LD='clang -lstdc++'
luarocks install luafilesystem --lua-version=V --local
luarocks install vstruct --lua-version=V --local
luarocks install inspect --lua-version=V --local

Lua 5.1 only:

luarocks install bit32 --lua-version=5.1 --local

where V is your lua version (5.1, 5.2, 5.3).


Before you proceed, fill in the LuaVersion and LuaExe environment variables with a desired Lua version and a name of the executable file for that version.

Build, test and install:

make all && make install

Idris 2 REPL preconfigured with lua codegen will be available under the name idris2-lua located in the same folder as your idris2 executable.

Status

  • The project aims to keep performance reasonable, Lua has many limitations, concerning local variables and nested structures like if-then-else statements, leading to design choices that may decrease performance and limit what the Lua runtime can do to optimize execution. Suggestions are welcome !

  • Major chez tests taken from the official repository under tests/chez run successfully, those which don't are primary FFI or BitXX tests.

Structure and How-Tos

  • Backend needs to know what version of Lua you target as there are incompatibilities:

    Define a global varible LuaVersion with a value: 5.1, 5.2, 5.3

  • If you want to run generated code within the REPL, define LuaExe with the name of the Lua executable (which should be in PATH) of the target version. If the variable is undefined, the backend will default to lua.

Good to know

  • Lua 5.1 and Lua 5.2 do not support 64 bit integers ! Best precision you can get is 52 bits. Also, if you use Buffers maximum precision is 48 bits, disregarding the Lua version ! This is planned to be fixed moving to native buffers.
  • Bits8, Bits16, Bits32, Bits64 are not yet implemented