4 ms·
Personally, I like the VM technique over compilation to JS source. With a VM, you can track the continuation by simple stack operations rather than furiously al
by ericbb 14y ago
Personally, I like the VM technique over compilation to JS source. With a VM, you can track the continuation by simple stack operations rather than furiously allocating JS closures. Think about the effect in memory: when you do a return in a VM, you just pop some stuff off the stack(s) and there is no closure left hanging around for the GC to collect.
The Dybvig "Three implementations of scheme" paper presents a really nice VM and Norvig's PAIP book presents a nice simple compiler for Scheme. Those are the two main sources that I've used for my simple compiler.
Edit: Also...
> I lose all the benefits of JIT-ed Javascript if I run it in a VM.
But if you are using CPS, then your JS functions are going to be really small and the JIT won't have much to work with, right? It's not clear to me that the JIT will be more effective working on CPS JS given that you want to have fine-grained continuations for debugging.
- jlongster 14y agoThe VM makes it easy to make continuation operations trivial, yes, but at the cost of normal code running slower and having to re-implement lots of things. I think both ideas have potential, and I need to implement both and see which one wins out. I'm not sure how well the JIT works with CPS-ed code. There's a Firefox addon to inspect the JIT which we could use to find out (https://addons.mozilla.org/en-US/firefox/addon/jit-inspector/ https://addons.mozilla.org/en-US/firefox/addon/jit-inspector...). It's possible we could optimize loops in a way that is more JIT-friendly. More research is needed!
- ericbb 14y ago> More research is needed! Agreed. And I'm looking forward to more posts on Outlet! I have a project that's similar in that it's a Lisp dialect designed to match my own tastes and to eventually run on a variety of platforms. So far, I've had variants of it running on JavaScript and Go. It's in a rough state at the moment but you can see it here: https://github.com/ebb/lumgua https://github.com/ebb/lumgua and another, rather different incarnation here: http://norstrulde.org/ilge10/ http://norstrulde.org/ilge10/ (with some more description here: http://norstrulde.org/ilge10/about.html http://norstrulde.org/ilge10/about.html)