logoalt Hacker News

lelanthrantoday at 11:44 AM1 replyview on HN

> Hmm. I'm fairly certain that most of that assembly code for saving/restoring registers can be replaced with setjmp/longjmp, and only control transfer itself would require actual assembly.

Actually you don't even need setjmp/longjmp. I've used a library (embedded environment) called protothreads (plain C) that abused the preprocessor to implement stackful coroutines.

(Defined a macro that used the __LINE__ macro coupled with another macro that used a switch statement to ensure that calling the function again made it resume from where the last YIELD macro was encountered)


Replies

Cloudeftoday at 12:47 PM

Wouldnt that be stackless (shared stack)

show 1 reply