3 ms·
Run Functions in Another Stack with Zig
- Teiolass 2y agoEvery program compiled with a reasonable compiler runs putting some of its data in the so called stack. It’s fairly easy: when you call a function, the function puts its data on top of the stack; when the function returns the data is removed so that the stacks now exposes the data of the caller function. In this post we mess with this mechanism, but substituting the default area of memory for the stack with a freshly allocated one.
- deleted 2y ago[deleted]
- 8474_s 2y agoWhy not bypass this nasty stack juggling and just use a async/await?
- Teiolass 2y agoMostly because I just wanted to understand a bit more how these things work. Using abstraction in the form of magic keywords gets the job done (sometimes, but not always) but is almost useless for your understanding. And I think that the understanding can be very useful even when you use the magic words.
- AndyKelley 2y agoFun fact: zig used to have a `@newStackCall` builtin [1], removed from the language in 0.6.0 [2]. [1]: https://ziglang.org/documentation/0.5.0/#newStackCall https://ziglang.org/documentation/0.5.0/#newStackCall [2]: https://ziglang.org/download/0.6.0/release-notes.html#newStackCall-Removed https://ziglang.org/download/0.6.0/release-notes.html#newSta...