This project is an interpreter of the Lua 5.4 programming language written in OCaml with the Dune build system.
- Build standard command:
dune build @all
- Execute Cram test:
dune test
ordune runtest
- Run:
dune exec ola -- file_name.lua
- Run in debug mode:
dune exec ola -- file_name.lua --debug
local function hello(msg)
print("Hello, "..msg.."!")
end
hello("world")
$ dune exec ola -- examples/hello.lua
interprete ...
Hello, world!
$ BISECT_FILE=$(pwd)/bisect opam exec -- dune runtest --force --instrument-with bisect_ppx
$ bisect-ppx-report summary
Coverage: 225/1379 (16.32%)
- Install in current opam OCaml switch:
dune install
- Run:
ola file_name.lua
-ola file_name.lua --debug
Debug mode displays the Lua input file twice in the console: original version - after scope analysis version (variables renamed with a unique name). Nb. Display formatting needs to be improved (Issue).
To enhance the test suite, I imported one from the experimental lua-wasm project. Thanks to the author. By the way, this is a very interesting exploratory work on compiling Lua to WebAssembly!
This experimental project has the following goals:
- Write an interpreter allows a deep understanding of a programming language. (Read a language specification in detail, understand the semantic, the execution model, etc.)
- Learn how to deal with a dynamique language, such as typing at runtime.
- Last but not least, Have fun!
Lua seems to be a good dynamic language for this context.
Designed by a university research team (PUC Rio Brazil),
its syntax is minimalist and its semantics well defined.
Implementing a whole Lua interpreter is a very big deal (a good experience to understand that), I'm so far from it. For now, there are the basics, including the fundamental concepts of tables and closures and the very beginnings of StdLib. This already allows to do a lot of fun stuffs :-) #WIP
More fun in a group than alone!
Feel free: Contact me, suggest issues and pull requests.
Thanks @zapashcanon, an active member of the OCaml community, for first feedbacks and reviews.