5 ms·
Why not use WASM to bootstrap your compiler?
by DrNosferatu 2y ago
Why not use WASM to bootstrap your compiler?
- anyfoo 2y agoElaborate, why use WASM?
- DrNosferatu 2y agoLike Zig did - then you could bootstrap in whatever environment that can interpret WASM. PS: Why all the downvotes? Just another perspective.
- mananaysiempre 2y agoUnlike any real machine (and most virtual ones), WASM is impossible to target with a simple single-pass C compiler. The reducible control flow requirement means you have to build a full control-flow graph and do graph algorithms to it before you can start emitting code. So IMO it makes for a bad starting point.
- anyfoo 2y agoIf you want to have "fun", generate code in a WASM-representation of Hoare's WHILE language, i.e. a program that only consists of a single outer while loop (in WASM a "loop" block), and conditionally decide for every single instruction in the loop whether it should be executed during a given pass. I think that could be done with a single-pass C compiler. In a very trivial (and terrible) case, you could keep a running "line_counter" variable that every statement in the loop is predicated with, which either gets incremented at the end of the loop, or set to an arbitrary value for representing branches. It would of course be a horrible (but very amusing) mess, and rather enforces your actual point.
- ksk23 2y agoReminds me of what I understand from the „Usagi Electric“ Bendix rotating drum -memory-computer execution :)