Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Mozilla's Narcissus meta-circular JavaScript interpreter (github.com/mozilla)
28 points by ldayley on Jan 11, 2012 | hide | past | favorite | 10 comments


I'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


Parent interpreter is not host, it is JavaScript. No one said that parent and child interpreters cannot have the same language :)


You 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.


It's currently 4AM here, so I cannot reason right :) If I misunderstood your point, my deepest apologies.


In this interpreter, user objects are represented as identical host objects, not implemented by hand.


Mozilla 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/


A 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/ [2]: 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.


This 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.


Funny 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.


It took a moment to register the significance of the name "Narcissus". I guess JsJs (like PyPy) just doesn't roll off the tongue.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: