On 2013-06-06 11:46, Kristian Lein-Mathisen wrote: > [...] > From what I understand, this is exactly what foreign-primitive does: > wraps C_return in a CPS, keeping the stack-allocation alive. > [...]
Hello, well, kind of. Since compiled CHICKEN code is fully CPS transformed you don't wrap something in a CPS context, you wrap anything that isn't natively in CPS with a function that calls it and passes the result to the values continuation. foreign-lambda and friends create such wrappers, foreign-primitive doesn't create a wrapper, it just expects the code to be in CPS style, which means that the code may never return at all. C_return is, in that case, just syntactic sugar for invoking the values continuation. Since the code in a foreign-primitive never returns, things allocated in the nursery (ie. on the stack) live on "forever", or rather until the next minor garbage collection comes around, transfers anything that's still referenced into the second generation heap and throws away the nursery (ie. almost the entire stack). Therefore foreign-primitive can do allocation in the nursery, but foreign-lambda can't. However, foreign-lambda could still allocate directly in the second generation heap or transfer nursery-allocated values directly into the heap upon return before the stack context is destroyed. The question is whether such magic is present for foreign-safe-lambda, as the documentation may indicate, or whether that is not the case, as Felix has indicated with his earlier message :-) Ciao, Thomas -- When C++ is your hammer, every problem looks like your thumb. _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users