Writing a compiler: Exceptions Part 2, layered jmp_bufs for exception bubbling

preview_player
Показать описание
I'm writing a programming language that resembles Ruby, called Natalie.

In this video, we continue our work on Exceptions, trying to get everything figured out when there are multiple levels of begin/rescue blocks. Unfortunately, I didn't quite get to the finish line on this one, so there's another video coming with Part 3, the conclusion.
Рекомендации по теме
Комментарии
Автор

By the way, the reason the `setjmp` is incorrect is not because it captures the stack (I'm pretty sure `setjmp` doesn't save the stack to begin with) it's because you call `setjmp` inside a function and then immediately return from that function. By the time you `longjmp`, the stack frame of the function you set to return to no longer exists, so you get undefined behaviour and jump to random unrelated code. It just happened to work the first time because your function got inlined.

yyny