top | item 3449836

Mozilla's Narcissus meta-circular JavaScript interpreter

28 points| ldayley | 14 years ago |github.com | reply

10 comments

order
[+] lubutu|14 years ago|reply
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
[+] stralep|14 years ago|reply
Parent interpreter is not host, it is JavaScript. No one said that parent and child interpreters cannot have the same language :)
[+] comex|14 years ago|reply
In this interpreter, user objects are represented as identical host objects, not implemented by hand.
[+] thristian|14 years ago|reply
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/

[+] tikhonj|14 years ago|reply
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.

[+] mcmire|14 years ago|reply
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.
[+] lalc|14 years ago|reply
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.
[+] ldayley|14 years ago|reply
It took a moment to register the significance of the name "Narcissus". I guess JsJs (like PyPy) just doesn't roll off the tongue.