Caterpillar

Daily Thought - 2024-08-25

< back to list

Tail call elimination leaves gaps in the call stack that will confuse the developer, when they're looking at an error in the debugger. For Caterpillar, with its focus on interactivity, immediacy, and intuitiveness, this is an unacceptable trade-off. Fortunately, there seems to be a solution: call stack reconstruction.

Let's start with the simple case (which is already implemented): main is the entry point to every Caterpillar program, so if the call stack doesn't start there, you know something's missing. (In the future that will probably depend on the host, but for now it's true. Either way, the debugger only runs when a host is present, so it can rely on host-specific knowledge.)

The fix is easy: Just add main to the start of the call stack. The debugger also shows which expression within an active function called the next one, but that's easy too: The stack frame was optimized away by tail call elimination, so it must have been a tail call. We can mark the last expression in main as the active one, and we're done.

<< previous thoughtnext thought >>