3 ms·
For one thing, JS has no unstructured control-flow. So your compilation process involves breaking down ifs, loops and so on into branches, then… trying to messi
by TazeTSchnitzel 9y ago
For one thing, JS has no unstructured control-flow. So your compilation process involves breaking down ifs, loops and so on into branches, then… trying to messily reconstruct them.
- dualogy 9y agoWell, ouch, a transpiler writer has to code up a bit of boilerplate, most of it just once early on in the project's life-time.. "too bad"! IMHO reconstructing stuff may be a somewhat tricky challenge, but there's no intrinsic need for it to be "messy" regardless of the target language? I must be missing something here still.. =) I'm doing transpilation to Go right now, so often I think "much of this would have been much simpler to get done if I transpiled instead to an anything-goes scripting language". (Reason of course being I want to emit idiomatic human-written-like code, and working with mostly-incomplete type information coming in, still reconstruct types rather than pass-and-return-typeless-boxed-values-around messily.) A lot of this is pretty "messy" right now, but I place all of the blame for that on me (guess I prefer rodeo-ing into it rather than "sitting down and writing a formal paper on it first"), neither the target or source language.
- TazeTSchnitzel 9y ago> there's no intrinsic need for it to be "messy" regardless of the target language The generated code with “re”constructed control flow is going to be a mess and you can't really help it. Worst-case it'll be a `while(1) { switch(i) {` type of thing.
- deleted 9y ago[deleted]
- DiThi 9y agoUnstructured control flow is easily emulated with switch statements. In fact it's what emscripten did long before asm.js was made, IIRC.
- TazeTSchnitzel 9y agoEmscripten has a specially-designed algorithm called relooper for reconstructing control flow (there’s a paper on it!). Switch statements are its last resort.
- comex 9y ago> For one thing, JS has no unstructured control-flow. So your compilation process involves breaking down ifs, loops and so on into branches, then… trying to messily reconstruct them. An omission which, incidentally, is also intentionally present in WebAssembly. There are supposedly good reasons for it, but I still find it really disappointing. see also: https://github.com/WebAssembly/design/issues/796 https://github.com/WebAssembly/design/issues/796
- sjrd 9y agoOr ... you don't break down ifs, loops and so on into branches to begin with. Scala.js has an optimizing compiler that doesn't do that (and I've heard a bunch of compiler people who were really impressed at the level of optimizations we can do without breaking down control flow into branches).