Glulx to Webassembly

Webassembly is basically a virtual CPU architecture that serves as a sort of common denominator for CPUs. It’s designed to get compiled down to target-specific instructions, while maintaining the sandboxing present in the browser. E.g. LLVM IR allows the code to just access memory randomly, Webassembly operates on it’s own block of memory and can’t access outside it (if the compiler to the target code has done a good job securing it). The goal is to get native performance while running untrusted code.

I’ll have to agree with @inventor200’s (deleted for some reason?) comment: You can absolutely go overboard with your world model, calculations and other stuff, such that performance does become a problem. But you’re right, most games probably don’t really need it.

Believe it or not, there are Webassembly runtimes targeting embedded machines, and of course a wasm2c converter. So unless the retro hardware doesn’t support C, it’d be just as portable as Z code.

So does the code just jump to addresses and and executes until it hits a return or something? You could analyze the jump instructions to get the functions, as long as the destination isn’t computed at runtime. Otherwise, yeah, you’d need debug info or something to properly do it. A build tool could probably take the work of compiling Inform code with the debug file and turn that into a wasm file without the user having to configure something, right?

A quick google search revealed there is a Glulx backend for LLVM made by someone, which can probably be compiled and plugged into Clang to compile C++.

I had a brief look at the Glk interface, and I’d be surprised if there wasn’t a C library for it you can use. Seems like pretty straightforward definitions for me.

Maybe this’d be worth splitting into a separate thread?

1 Like