4 ms·
What? Compilers handle tail calls all the time even in languages like C and higher level functional languages. Its just a jmp? Does the wasm VM not have a jmp
by anfilt 4y ago
What? Compilers handle tail calls all the time even in languages like C and higher level functional languages.
Its just a jmp? Does the wasm VM not have a jmp instruction?!?
- Jtsummers 4y agohttps://www.w3.org/TR/wasm-core-1/#control-instructions%E2%91%A0 https://www.w3.org/TR/wasm-core-1/#control-instructions%E2%9... Those are the list of control instructions. WASM seems to be a bit of a misnomer as it is not an assembly language in the more conventional sense. It is a structured language and provides a limited goto in the form of branches (in the section I linked to) which are constrained to a particular scope. If you compile your whole program so it fits within a single function, then yes you can use this to do universal tail call elimination. Otherwise you are restricted to doing TCE only on auto-recursive functions and maybe mutually recursive functions if you have a single entry point (of the set of functions) and decide to optimize by moving all of them into one function. Otherwise, function calls are performed using one of the two call instructions which (presently) implement a behavior more like conventional call stack/stack frames. This proposal would add a second pair of call instructions that a compiler can emit which the WASM runtime would then optimize (by not generating new stack frames).
- anfilt 4y agoSo no self modifying code either, since it seems like I can't just get the address of a function and modify the byte code?
- shadowofneptune 4y agoThat would be used most often for malware, unfortunately.