munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"

Home Page:http://www.craftinginterpreters.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SegFault @ 24.5.3 in REPL

felix-alonso opened this issue · comments

Section 24.5.3 has to do with printing stack traces. It ends with entering in a broken program to demonstrate the stack trace.

fun a() { b(); }
fun b() { c(); }
fun c() {
  c("too", "many");
}

a();

If you run the program from the REPL by creating each definition in turn then at this point in the chapter you will produce a segfault after you enter in the second function. (Really it works with any pair of statements you enter.) This is fixed in the next section (24.5.4) because we add in return values so all's well that ends well.

However, I would recommend adding a note next to the example that warns the user that they will get a SegFault from the REPL, but not from a file. (It could even include a cheeky author comment asking the reader to consider why this might be the case.)

I burned an hour trying to figure out why the vm.frameCount underflowed (That's C, baby!) and where I deviated from the book as written. Turns out everything was working as expected. I just needed to keep following the book.


Thanks for writing this lovely book and putting it online! Really appreciate it!