4 ms·
Mozilla's Narcissus meta-circular JavaScript interpreter
- ldayley 15y agoIt took a moment to register the significance of the name "Narcissus". I guess JsJs (like PyPy) just doesn't roll off the tongue.
- lubutu 15y agoI'm confused. This is a self-interpreter, but in what sense is it metacircular? It's an implementation of JavaScript in JavaScript; it does not appear to rely on the host's evaluation semantics, which is necessary to qualify as a metacircular evaluator: http://en.wikipedia.org/wiki/Meta-circular_evaluator http://en.wikipedia.org/wiki/Meta-circular_evaluator
- stralep 15y agoParent interpreter is not host, it is JavaScript. No one said that parent and child interpreters cannot have the same language :)
- lubutu 15y agoYou misunderstand: the parent interpreter is JavaScript, yes, but the child interpreter does not rely on the parent's evaluation semantics, which means it is not a metacircular evaluator, it's just a self-interpreter. See the Wikipedia article for more information.
- stralep 15y agoIt's currently 4AM here, so I cannot reason right :) If I misunderstood your point, my deepest apologies.
- comex 15y agoIn this interpreter, user objects are represented as identical host objects, not implemented by hand.
- thristian 15y agoMozilla also has a Firefox addon called Zaphod which will allow you to force scripts in web-pages to be executed with your (customized) Narcissus interpreter, instead of executing scripts with SpiderMonkey directly: https://mozillalabs.com/zaphod/ https://mozillalabs.com/zaphod/
- lalc 15y agoFunny enough, I just started using this the other day to write a little async callback JS pre-processor. I wanted to just tokenize but then I found out that JS's regexp literals make JS ambiguous to parse. This project turned out to be a huge boon--really easy to patch to find particular token boundaries.
- tikhonj 15y agoA cool project that uses this is DoctorJS[1][2]. It's a ctags tool optimized for JavaScript and a JavaScript static analyzer. [1]: http://doctorjs.org/ http://doctorjs.org/ [2]: https://github.com/mozilla/doctorjs https://github.com/mozilla/doctorjs Unfortunately, it does not seem to create Emacs-style tags at the moment. I had meant to add that to it--I even have some half-baked code lying around somewhere--but never got around to finishing it :( Still, it's a cool project anybody working with JavaScript should check out.
- mcmire 15y agoThis is interesting, but doesn't appear to be self-hosting. That is, you can't use Narcissus to compile Narcissus, you have to use SpiderMonkey to run the Narcissus code (that is the impression I get from reading the wiki, anyway, someone correct me if I'm wrong). Still, it is cool that the objects that Narcissus parses in the "user" code are stored exactly the same way in the "host" code.