chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Chicken C interface


From: Kristian Lein-Mathisen
Subject: Re: [Chicken-users] Chicken C interface
Date: Thu, 6 Jun 2013 12:13:31 +0200

I did not read your question properly, sorry! Thanks for the clarification, I didn't know foreign-lambda were the one that had to do the CPS-conversion. Does that mean there is a small performance overhead when using foreign-lambda as opposed to just foreign-primitive?

K.


On Thu, Jun 6, 2013 at 11:59 AM, Thomas Chust <address@hidden> wrote:
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.



reply via email to

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