Hello,
Is there a native machine code compiler for Javascript?
I'm not talking about a VM.
If it doesn't exist can it be done?
I am wondering if it can be compiled to binary due to the dynamic nature of the language.
Thanks in advance,
Omer
Hello,
Is there a native machine code compiler for Javascript?
I'm not talking about a VM.
If it doesn't exist can it be done?
I am wondering if it can be compiled to binary due to the dynamic nature of the language.
Thanks in advance,
Omer
It is theoretically possible, but there will be a lot of runtime support baggage involved (and even a full Javascript compiler or interpreter to support eval
).
Are you looking for an actual native code compiler, or are you looking for something that can bundle Javascript code along with a runtime into a single executable binary?
Java uses byte code which is interpreted by the VM, you can get wrappers which make what looks like a native exe - Launch4J for example.
It's definitely doable, although the only way I know how to do it at the moment is a two step process...
Why would you want to, though? What advantage do you expect to find?
TraceMonkey in FF3.5 do this to some parts of the javascript code. You may be able to get some directions from there!
As far as I know there are no static compilers for javascript. It is certainly theoretically possible, however a static compilation of javascript would need a very heavyweight runtime to support all of its features(such as dynamic typing and eval). As a small aside, when presented with the need to statically compile Python(Another dynamic language), the PyPy developers ended up creating a language which was a very restricted subset of Python (called RPython), void of some of Python's more dynamic features, that was capable of being statically compiled.
If you're asking this for the purpose of creating a standalone executable from Javascript code, I'm sure there must be wrappers which essentially would create an executable comtaining your script and an embedded Javascript VM(Sadly, I don't know any offhand)