[Question] A different lowering for while-statement perhaps
jigargandhi opened this issue · comments
Hey @terrajobst,
I am really enjoying your compiler series.
In episode 8 lowering, you have mentioned while statement as sequence of steps
- goto check
- continue
- body
- gotoTrue condition continue
- end
Perhaps, what if we had a version with one less label as follows
- begin
- gotoFalse condition end
- body
- goto begin
- end
Would it impact anytime later?
Thanks!!
I think you're right that we could have gotten away with fewer labels in that episode.
But eventually we'll need to have at least two labels per loop: one for jumping out of the loop and one for continuing the loop. Those two labels are the jump targets for the break
and continue
statements. You can see this in episode 13.
Yeah, when we have break
and continue
in loops additional labels might be necessary. Thanks for your explanation. Keep rocking with the series :)
Thanks for watching and asking questions