Tail-call optimization in C is relatively recent
Tail-call optimization in C is relatively recent
Posted Aug 23, 2025 19:43 UTC (Sat) by lafp (subscriber, #89554)In reply to: Tail-call optimization in C is relatively recent by anton
Parent article: Python, tail calls, and performance
For what it's worth, I recently implemented a (toy) interpreter for a variant of Forth that uses tail calls for dispatching instructions. The main gain I had was making all the built-in functions behave like instructions themselves, rather than having a "call a built-in function" instruction; it also has support for a few handfuls of super-instructions, which helped quite a bit as they're not that different than anything else. The performance is pretty decent, but it'll need a bit more work in the optimizer to reach what I need it to reach (ultimately I want this to run on a small computer, expose the interpreter through a browser, and let people write code that's then used to control a LED matrix; think of this project, but in a smaller scale: https://www.noisebridge.net/wiki/Flaschen_Taschen).
The code is here (https://github.com/lpereira/lwan/blob/master/src/samples/...) and it's a variant of the Forth Haiku language, that lets you create art with small bits and pieces of Forth code, not unlike ShaderToy is for GLSL.
