Reputation: 1583
Another post questioned how practical it is to compile languages into Javascript. Practicality aside, what interpreters translate from some language X to Javascript and were implemented in Javascript? I'm especially interested in the cases where X wasn't designed with the intention of targeting Javascript. Even if the interpreter isn't totally finished I'd like to hear about it.
You may be curious about the motivation for this question. Javascript certainly can't leverage as much power as assembler, but the flexibility for code distribution and execution may sometimes outweigh that cost.
One use case for these interpreters is a model for teaching and learning programming languages. Consider how useful it is to have a Javascript interpreter in the interactive book Eloquent Javascript. Sure, there may be a performance hit over compiling it natively, but in some situations the cost is certainly worth it. And yes, I realize it's always an option to rely on the server to compile or interpret code, but I'm specifically interested in client-side approaches.
UPDATE: A lot of responses include references to compilers that weren't implemented in Javascript. I just want to stress that the interpreter itself should be implemented in Javascript so that both it and the source language code could run on the browser on your grandparent's computer.
Upvotes: 10
Views: 1446
Reputation: 369420
See also this question: Are there other languages than Objective-J that get “compiled” to JavaScript in the browser?
Upvotes: 4
Reputation: 59994
j2js compiles Java bytecode to Javascript (e.g., Java, Scala, etc.).
Upvotes: 1
Reputation: 53940
some more or less toy interpreters in pure javascript
and of course the obligatory
Upvotes: 2
Reputation:
Community Wiki, let's mash this out :-)
jsc - re-compiles from CIL (CIL compiled from VB.NET, C#, etc.)
Script# - compiles from C# (source-code).
GWT: Google Web Toolkit - compiles from Java.
Emscripten - compiles from LLVM. Should be able to work (Language X)->LLVM->JavaScript, minus issues, where Language X has an LLVM compiler.
Upvotes: 4
Reputation: 3914
CoffeeScript is a programming language that compiles to JavaScript.
Upvotes: 6
Reputation: 90712
Pyjamas can compile Python to JavaScript. That's a server-type translation; Pyjamas has not yet been used to compile itself so there is no JavaScript Python interpreter.
Upvotes: 0