<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span></span></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br></div><div><br>On Jun 29, 2013, at 9:53 PM, Eli Friedman <<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Jun 29, 2013 at 7:51 PM, David Farler <span dir="ltr"><<a href="mailto:accumulator@icloud.com" target="_blank">accumulator@icloud.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br>
<br>
In getting to know the LLVM infrastructure, I'm having a hard time finding implementation details for closures and continuations.<br>
<br>
For closures, I've read comments such as "using a struct" as an environment to hold references to free variables, linked lists to dictionaries for various scope levels, and even things like "it's just like virtual methods". I have a couple of questions regarding codegen, especially in the context of a Lispy/Haskell-like language with automatic reference counting of immutable objects allocated on the heap.<br>

<br>
What needs to be added to Functions during code generation? Is it a really just a struct only holding offsets to free variables? Or do symbols need to be looked up a kind of scope chain at runtime?<br>
<br>
Does adding a JIT complicate codegen of closures in terms of symbol lookup in the bundled environment?<br>
<br>
Any recommendations for treating functions with no free variables vs closures?<br>
<br>
Does implementing continuations greatly affect implementations of closures? I assume the stack would need to be heap-allocated explicitly, which might affect how pointers would be saved in a bundled environment.<br></blockquote>
<div><br></div><div>Please read <a href="http://llvm.org/docs/tutorial/index.html">http://llvm.org/docs/tutorial/index.html</a> .  I'm having trouble coming up with answers to most of your questions.<br><br></div><div>
If you need completely general continuations, yes, you'll want to explicitly allocate your stack.<br></div><div><br></div><div>-Eli<br></div></div></div></div>
</div></blockquote><br><div>Thanks, this is the tutorial I've been reading and it's a great resource. I think I just need to start looking at some languages that already implement this. I can see now that free variable addresses are known at compile time and can be used in the future provided they are allocated on or moved to the heap.</div><div><br></div><div>Still wondering about how to pack the structs and how eval/JIT affects this; I'll keep looking. </div><div><br></div><div>Thanks!</div><div>David</div></div></body></html>