4 ms·
So, you can't answer "in general" because things are handled differently depending on the language. I believe Scheme basically only uses the heap (which is nec
by Verdex 5y ago
So, you can't answer "in general" because things are handled differently depending on the language.
I believe Scheme basically only uses the heap (which is necessary because of call/cc iirc).
Haskell uses a variation of a G machine (looks like a spineless tagless g machine to be specific). The way that works is that they convert your program into a giant lambda term and then they work on reducing it. This of course looks nothing like a traditional call stack, so you can replace that whole thing with the G machine. Recursion (at least of the non-tail recursive variety) will look like a lambda term slowly getting bigger in heap space.
And then I also heard of someone (I forget which language) talking about setting up some logic to look for stack overflows and then throw all the current stack onto a heap and then start over.
- dfox 5y agoThe part about detecting stack overflows probably refers to implementation strategy in some scheme implementations (IIRC chicken scheme does this) which involve using the platform/machine stack as effectively hardware-assisted nursery generation for generational copying GC, when it gets full (usually well before true overflow) the minor GC cycle gets done and the stack gets completely emptied. In these designs the "stack" is usually used for all allocations, not only for activation records.