tag:blogger.com,1999:blog-2744072865491516720.post8588717654291980761..comments2023-05-03T06:35:33.259-04:00Comments on Higher Logics: Coroutines in C ReduxSandro Magihttp://www.blogger.com/profile/05446177882449578817noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-2744072865491516720.post-53160728080862488572012-10-26T14:34:14.989-04:002012-10-26T14:34:14.989-04:00w.r.t. lazy stack copying - even if you could dete...w.r.t. lazy stack copying - even if you could detect that you need to lazily copy a bit more stack, you'll still have the problem that pointers to the stack might be invalid. For example:<br /><br />char buf[256];<br />fill_my_buffer(buf,sizeof buf,stdin);<br /><br />As a common idiom for I/O in C, this probably has to be supported intelligently.<br /><br />Another way to reduce copying might be to somehow detect an area of the stack which were not changed since the last time a particular coroutine was invoked and not copy that part.<br /><br />To do this, you'd have to compare the stack as it is copied away to see what parts of the stack a coroutine actually modified. Then some kind of versioning system might be needed for chunks of stack so that when you are going to copy chunks of stack back in you can check if the version number is the same and skip copying in that case. It's not clear that all this comparing would save any time compared to copying, though.<br />Dobeshttps://www.blogger.com/profile/09392777569321223496noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-48504501818976100652008-07-19T12:28:00.000-04:002008-07-19T12:28:00.000-04:00You are correct. It would be ideal for the compile...You are correct. It would be ideal for the compiler to emit stack frame information, which can then be used to update all stack frame references. There are some compilers for garbage collected languages that do this in fact. I don't know of any C compilers that do this however.<BR/><BR/>Still, as long as a language emits PIC code, and uses only relative offsets from the current stack position to reference its locals, stack relocation is trivial.<BR/><BR/>The tricky parts comes with absolute addressing, like taking the address of a local and passing it to another function. Here you either need to update that address within the stack frame (complicated), use a relative offset from the stack base, or otherwise ensure that the newest address is always used (like adding a level of indirection).Sandro Magihttps://www.blogger.com/profile/05446177882449578817noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-1152119691241595342008-07-19T11:56:00.000-04:002008-07-19T11:56:00.000-04:00The problem almost seems like it would be better s...The problem almost seems like it would be better solved in the compiler or even in a preprocessor generating a stack struct with structs and unions for subroutines that can freaze.<BR/><BR/>Is there a solution like this?Leehttps://www.blogger.com/profile/03257229256000743102noreply@blogger.com