I am proud to announce the first public release of Glulxtoc, a Glulx to C decompiler!
Glulxtoc is a Rust project (how to install Rust), and you can install it easily using cargo: cargo install glulxtoc
Glulxtoc will output a folder of C code and a CMake script for compiling it against a Linux Glk library. In theory the code should be cross-platform, and I’d welcome help adding support for other build systems.
I’m happy with how stable it is currently, but there will be bugs. Don’t hesitate to report any issues you have.
FAQ:
- Why?
- Fun!
- I had been intending to use the decompiler core as the foundation for a new version of ZVM (and to write my GVM interpreter.) Glulxtoc combines the if-decompiler with a C code generator, and it wouldn’t be hard to switch the code generator for a JS or WASM code generator. However I’m not sure how feasible it will be - compiling big Glulx files is both slow and takes a lot of memory.
- When decompiled to C and then compiled with an optimising C compiler, large Glulx games should run considerably more efficiently. This could help with publishing large games for mobile or other restricted platforms. (However note that the final binary will not be compact file-size-wise.)
- What makes Glulxtoc efficient?
There are two major optimisations:- Firstly, by tracking which functions call which others, we are able to turn many Glulx VM function calls into direct C function calls. In effect it expands the idea of accelerated functions from the dozen or so in the Glulx spec to any safe function in your code, potentially 10s of thousands.
- Glulxtoc implements a ‘relooper’ algorithm, like those in Emscripten and Cheerp. A relooper algorithm takes a list of unstructured jumps and branches, and turns them into loops. So rather than being a knotty messy of
goto
statements, the output will be well structured code, and then able to receive all the optimisations of any other well-written C code.
- Why Rust?
This is my first Rust project, and I’ve really enjoyed learning the language. The big advantages I found in Rust are its algebraic data types, its ability to compile to WASM, and the Petgraph graph library. There are graph libraries for other languages of course, and Petgraph isn’t without some rough edges, but I found it fairly easy to use, and when I ran into trouble I found answers quickly on Stack Overflow. Thank you Rust community!