[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Chicken C interface

From: Thomas Chust
Subject: Re: [Chicken-users] Chicken C interface
Date: Thu, 06 Jun 2013 11:59:52 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6

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.
> [...]


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

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 :-)


When C++ is your hammer, every problem looks like your thumb.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]