3 ms·
> Interestingly, this restriction does not apply to goto labels, which you can use first and define later: The compiler can just emit the label as written into
by klyrs 6y ago
> Interestingly, this restriction does not apply to goto labels, which you can use first and define later: The compiler can just emit the label as written into the assembly code and let the assembler worry about patching up the jump target.
A one-pass compiler can manage this by maintaining a mapping of undefined labels to a list of goto statements that refer to them. Once the definition is located, unwind the list and fill in the jump values. Types are trickier because the size is unknown.
- tom_mellior 6y agoThere is no way to "fill in the jump values" if you have already emitted the goto to a place you can't modify later. Like the featured article does, emitting its code with printf. I agree that you could emit code to an intermediate buffer, fix it up later, and still call this (a slightly more relaxed version of) one-pass compilation.
- klyrs 6y agoFair point... kinda feels like passing the buck, but not having that memory overhead is nice