Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a native machine code compiler for JavaScript? [closed]

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.

like image 370
the_drow Avatar asked Jul 13 '09 07:07

the_drow


People also ask

Can JavaScript be compiled to machine code?

JavaScript is an interpreted language, not a compiled language. A program such as C++ or Java needs to be compiled before it is run. The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute.

What compiler should I use for JavaScript?

Komodo Edit Komodo Edit is also one of the popular options for JavaScript IDE's. It can be considered as a lower version of Komodo's latest IDE as it simplifies development than ever before. It is a powerful as well as simple edit which supports multiple languages.

Can JavaScript compile to a binary?

So JS can be interpreted or compiled to machine code (using a JIT compiler), similar to how JVMs work, yes.


1 Answers

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 containing your script and an embedded JavaScript VM (sadly, I don't know any offhand).

like image 122
Falaina Avatar answered Sep 29 '22 12:09

Falaina