The question title speaks for itself. I'm specifically thinking in terms of a Node.js server. Additionally, this question is assuming that you don't need eval()
.
Also, if this is not possible, why not?
The question title speaks for itself. I'm specifically thinking in terms of a Node.js server. Additionally, this question is assuming that you don't need Also, if this is not possible, why not? |
|||||
|
It's easy to compile any language, no matter how dynamic, to machine code. It just won't be efficient machine code, since it will usually do a lot of dispatching based on run time type tags and looking up values in hash tables, much like a (bytecode) interpreter. In the simplest case, just compile C code like
For JavaScript without
|
|||||||||||||
|
Node.js uses the V8 engine, which is a pure compiler. It never interprets. There isn't even an interpreter in V8, just two compilers. |
|||||
|
In fact, Javascript is (inside several major browsers) often "compiled" using Just-in-Time compilation techniques (read about the V8 Javascript engine). But as delnan explained, there are case where it is not worthwhile. AFAIK some implementations use Tracing JIT compilation techniques. And And asmjs.org defines a specification of a subset of Javascript which is designed to be easy to compile. |
|||||
|