Using C as a back end
Stephen Weeks
MLton@sourcelight.com
Tue, 14 Aug 2001 11:10:24 -0700
> In article <00-10-195@comp.compilers> you write:
> >I disagree with the first two points above. Since SML has garbage
> >collection, we had to face the problem of implementing it... I wrote a simple
> >two-space copying gc... We went
> >through several iterations of the interface between the generated C
> >and the runtime (all basically different ways of telling the GC the
> >root set) and eventually found one we liked.
>
> Have you published the details? I hope you will.
It's doubtful we will at this point, since we've moved on to the native backend,
which gives much better performance.
> >As to exceptions, SML has them, and I don't think our implementation
> >is slow. Raising an exception to an unknown handler involves a store,
> >an add, a dereference, a switch and possibly a trampoline, if the
> >destination is in another C procedure.
>
> Aha, I had forgotten about trampolines. But it might be nice to know
> the details here.
Again, we've moved to the native backend, but in this case that didn't change
much, other than to replace the switch and the trampoline with a jump. The
method is to store in a global (actually per thread) variable the offset of the
current exception handler (a code pointer) relative to the bottom of the stack.
Then, raising an exception involves
store into a global of the value to raise
add of the stack bottom to the global
dereference of the code pointer
jump to the code