Post

Having a blast with more compiler visualizations. This one is helping me understand backpatching:

0 reposts3 likes

If your compiler only has one pass at the nodes in your abstract syntax tree, and you have an if/else statement, how can it know ahead of time where you want it to jump to in the else case?

It doesn't! So you have to emit some bytecode as a placeholder first, and remember where you set your placeholders. When you're done compiling the relevant blocks of your if/else, you take note of your current position, and fill in those placeholders to say "hey the jump should end up over here"