3 ms·
My reading of the disassembled code on page 7 is that the "end" opcode actually takes one byte, and isn't just a syntactic structure that the assembler removes.
by DonHopkins 8y ago
My reading of the disassembled code on page 7 is that the "end" opcode actually takes one byte, and isn't just a syntactic structure that the assembler removes. As if a Lisp VM had a close-paren instruction.
+003Eh: i32.eqz
+003Fh: if $3
+0041h: br $2 (---> break out of $2 (BLOCK))
+0043h: end
+0044h: get_local $12
What's the purpose of having an "end" opcode? Is there no overhead at runtime because it evaporates when the code is compiled? It it to avoid having forward referencing offsets in the code? Is it just in there for verification purposes?
It's kind of like a "comefrom" opcode, a target that other opcodes jump to (or after)!
- kazinator 8y agoI have an end opcode in the TXR Lisp virtual machine. It delimits blocks of code that have some sort of context attached. The opcode allows the virtual machine interpreter to recurse on itself; when it hits the end, the dispatch loop executes return to bail out to the higher level of recursion. Thus end is also useful for exiting the top-level invocation of the VM. It is required, in fact; if the end instruction is not present, the interpreter will keep marching through memory past the end of the routine. No wasteful check is needed whether the instruction pointer is past the code block. my end instruction also specifies a result value (because the machine is register based; there is no top-of-stack implicit value). This becomes the return value of a procedure when the final end is executed. The block instruction also uses it. When a (block ...) is compiled, the return value of the ordinary block termination is specified in the end instruction at the end of the block. Control returns to the block instruction which receives that value. end has something in common with the x86 ret instruction and its ilk. It's not so much an exotic "come from" as an ordinary "return".
- deleted 8y ago[deleted]