A tiny (1000 lines), fastish, embeddable scripting language can be AOT compiled
12 days ago
- #embedded-scripting
- #performance-optimization
- #programming-languages
- Filli is a Lua/Python-like embeddable language written in C23/C99 with GNUisms, also compilable as C++.
- It features functions, closures, generators, dictionaries, and arrays, and is sandboxable like Lua.
- Performance: The interpreter is 2x slower than Lua, but the AOT version is 6x faster than the interpreter, outperforming Lua and LuaJIT interpreters in some cases.
- AOT version works by emitting C code that includes a modified interpreter, compiling it, and running bytecode instruction by instruction.
- Syntax resembles Python/Lua, demonstrated with a pi calculation benchmark.
- Originated from the need for a small embeddable scripting language, improving upon Flinch, a previous stack language attempt.
- Parsing challenges were addressed without an AST, using Pratt parsing and emitting bytecode directly.
- VM design focused on simplicity and performance, using dynamic typing and stack-based operations.
- Performance optimizations included switching compilers (GCC to Clang) and adjusting compiler flags for better execution speed.
- Added features like dictionaries, lambdas with closures, and generator-coroutines, keeping the implementation under 1000 lines.
- AOT compilation approach was unique, converting opcodes to C code, avoiding dynamic computed goto labels for better performance.
- Memory management uses the Boehm GC for simplicity.
- Limitations include a hard limit of 32k identifiers per source file and restrictions on continue/break patch-up points.
- The project is open-source, with the interpreter under 1k lines of C code and the AOT compiler in a separate branch.