3 ms·
If your source language has some construct that you want to express as state machines (e.g. async, CPS, pattern match compilation), and you want to compile the
by aweinstock 6y ago
If your source language has some construct that you want to express as state machines (e.g. async, CPS, pattern match compilation), and you want to compile the state machine as direct threaded code[0] (which involves fewer branches than a while-switch), then if you're compiling to C, you need computed gotos[1], which are non-standard.
[0]: https://en.wikipedia.org/wiki/Threaded_code#Direct_threading https://en.wikipedia.org/wiki/Threaded_code#Direct_threading
[1]: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html
- mratsim 6y agoGCC, Clang, ICC do support computed gotos and you can fallback to ``while true`` loop + switch dispatch for others. This is what Nim does: https://nim-lang.org/docs/manual.html#pragmas-computedgoto-pragma https://nim-lang.org/docs/manual.html#pragmas-computedgoto-p...