<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">2014-05-06 23:32 GMT+02:00 Marc Feeley <span dir="ltr"><<a href="mailto:feeley@iro.umontreal.ca" target="_blank">feeley@iro.umontreal.ca</a>></span>:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
On May 6, 2014, at 4:22 PM, Mikael <<a href="mailto:mikael.rcv@gmail.com">mikael.rcv@gmail.com</a>> wrote:<br>
<br>
> Dear Marc,<br>
><br>
> Just curious, Gambit's JS backend, it uses the JS VM:s GC right -<br>
><br>
> How do you make the SCM to JS object mapping deliver that?<br>
><br>
> I mean, say, a cons cell, a vector, a closure, a firstclass continuation and a stack frame, about how are those mapped to JS objects as for the JS VM to be able to GC them just as it does with ordinary values?<br>
><br>
>  - Gambit uses numbers for object references ordinarily, so I guess the object mapping has been done deeper than that, so that actual JS object references are used as SCM object references by the JS backend.<br>
<br>
</div></div>Scheme objects are mapped to JS objects.  So a pair is an instance of the “class” Gambit_Pair, and a vector is an instance of the class Gambit_Vector.  Scheme closures are JS closures.  A Scheme continuation is a chain of frames (each frame is a JS array).  So everything is garbage collectible by the JS GC.<br>


<br>
There is a bit of fanciness in how the continuations are created.  The Scheme stack is an extensible array and stack frames are allocated in this array contiguously.  When a continuation is captured the stack is emptied and each frame becomes an independent JS array.<br>

</blockquote><div><br></div><div>Aha. And then, when one stack frame (JS  array) refers to another stack frame (JS array), then this is done by the means of an actual object reference?</div><div><br></div><div>E.g.</div>
<div>
<br></div><div>var frame1 = [value, value ...... ];</div><div><br></div><div>var frame2 [value, ........ frame1, ...];</div><div><br></div><div>?</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<span class="HOEnZb"><font color="#888888"><br>
Marc<br>
<br>
</font></span></blockquote></div><br></div></div>