Post

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"

I really struggle to visualize this so putting in a shit ton of trace calls and piping it out to my little website helped a lot.

0 reposts0 likes

No replies yet.