janvhs / ideas

A dump of things I want to learn and project ideas
1 stars 0 forks source link

AOT compiled Lua and functional dialect #17

Open janvhs opened 6 months ago

janvhs commented 6 months ago

Lua has no notion of a class hierarchy. Therefore, it might be a good fit for having a functional dialect. The dialect should have a relation similar to the relation between ReScript / Elm and JavaScript. It would be great to keep distinct parts of Lua's syntax and maintain its simplicity. That would be a fun project.

Furthermore, compiling Lua in an ahead of time manner would be very interesting. It has a dynamic type system, which makes it even cooler. Similar things have been done with the Trüffel set of languages and I've heard of an AOT ruby implementation, too. I just have to find the conference talk again

janvhs commented 6 months ago

Maintain compatibility with required C libraries like Löve, so the Lua ecosystem and package manager can still be used

janvhs commented 6 months ago

Maybe add a static, structural type system based on set theory. Similar to Typescript and Elixir's plan. Moonscript and Neolua already do that and Lua has some type checking tools

janvhs commented 6 months ago

Do optional static linking and compile to WASM if feasible

janvhs commented 6 months ago

Embedding assets similar to Go's magic compiler comments or C's embedding macro would be fun, too

janvhs commented 6 months ago

This should be possible without rewriting the whole Lua interpreter, as Lua already has two great implementations, which are supposed to be embedded. These are the official Lua and LuaJIT.

Although, I doubt it due to the nature of JIT compilers, the Bytecode of LuaJIT could be used as a starting point to generate native AOT code.

janvhs commented 6 months ago

Shopify did something interesting with compiling JavaScript to WASM in the past, using the JIT bytecode of QuickJS. It's called Javi or something similar

janvhs commented 6 months ago

Found the talk

https://youtu.be/NfMX-dFMSr0?si=jh_DSDIiNMELUMkI

janvhs commented 6 months ago

https://github.com/AlexDenisov/mlir-tutorial

janvhs commented 6 months ago

Python efforts

unladen-swallow from Google

https://github.com/bytedance/matxscript

https://github.com/exaloop/codon

janvhs commented 6 months ago

Maybe compile Lua to C and use clang from there. Multiple languages are using this approach

For lua there is https://github.com/davidm/lua2c and luac2c

janvhs commented 6 months ago

For Python

https://micropython.org

https://gitlab.com/hartsantler/tpythonpp

Might be interesting too

janvhs commented 6 months ago

Embedd stylua, luacheck and the type checker from lua lsp as well as the lsp into a single toolchain

janvhs commented 6 months ago

Existing Lua implementations in Go

https://github.com/yuin/gopher-lua

https://github.com/Shopify/go-lua