I'm aware of Emscripten and LLVM, but neither are written in JavaScript intended for a browser.
As far as I can tell, the tools exist, but they haven't been put together, but I could very well be missing some key factor that makes it very difficult to compile C++ to JavaScript in a browser.
So I'll mention my naive implementation:
Compile Emscripten to C, then use Clang to compile it to LLVM, then use Emscripten to compile it to JavaScript.
Compile Clang to LLVM, then compile that to JavaScript through Emscripten.
Write some C++ and run it through JavaScript Clang, then run that LLVM through Emscripten to get JavaSscript
Run the resulting JavaScript!
I'm sure I'm missing something from my steps. Please let me know, and let me know if there are any efforts by the community to resolve those missing pieces.
EDIT: JSCPP is the closest I've found, but it lacks a lot of features and frankly the author took on an absurd undertaking, by trying to rewrite the parser etc. on his own, rather than using existing tools. Still, close and pretty neat.
It is possible to compile C++ to JavaScript using a self-hosting version of Emscripten that runs in a browser, such as emception.
Alternatively, it is possible to run a C++ compiler (or even an entire operating system) using an x86 emulator in JavaScript.
Related
Is JavaScript running on top of web browser?
Like Java running on top of JVM?
Or Does it actually compiled to binary code and run on machine?
V8 (in Google Chrome) contains a JS interpreter and a JIT (Just-in-time) compiler. JS code is converted to V8-specific bytecode. The bytecode is initially interpreted by the interpreter, called "Ignition". When a function becomes "hot" (it is run a lot), the TurboFan JIT compiler produces optimized machine code from the bytecode.
Other modern JS engines use similar strategies. So JS can be interpreted or compiled to machine code (using a JIT compiler), similar to how JVMs work, yes.
Javascript isn't truly compiled - it's interpreted on the browser, so yes it effectively "runs on top of the browser" on the client side.
EDIT: I should've started by saying at it's base level. As is mentioned on a comment to this, there are more complex engines now.
It has to -- nothing can run on a computer without being the appropriate machine code for the processor.
V8 converts the JavaScript to its own byte code, then is heavily optimized and converted into machine code.
Even the JVM does something similar. The JVM converts the Java byte code into machine code.
What compiler options are best to ensure that dartdevc generates minifier friendly javascript code which can be compressed by google closure compiler in ADVANCED mode.
Please show a tested example that specifies options for 1. dartdevc, and 2. java -jar goolge-closure-compiler.jar as a simple bash script, without pub.
Module type should be 'common' if possible, dart_sdk.js should be included, the final result should be es3 or es5 for compatibility with all browsers, and all output goes into one compressed .js file.
The dartdevc compiler is not meant for production usage at this time, and does not support any sort of "advanced" optimizations (such as those done by the Google Closure Compiler). Our only supported optimization path is using dart2js, our optimizing compiler which in many cases is as good as or better the Google Closure Compiler.
See "When should I use dartdevc" on our FAQ page:
Use dartdevc whenever you’re actively working on your code.
Keep using dart2js to build your deployed, production application. With dart2js you get advanced optimizations such as tree shaking to minimize downloaded code size.
I'm excited you'd like to see dartdevc work for more use cases, but we are concentrating on a great developer experience and keeping optimization usage in dart2js at this time.
This question already has answers here:
How can I integrate Python and JavaScript?
(13 answers)
Closed 13 days ago.
I was wondering if it is possible to run native python code in chrome instead of javascript.
I have seen projects like pyjs or brython, but what they do is compile python to javascript. While those are great projects a problem with this approach is always that you cannot easily debug the original python code.
Amongst other things I stumbled upon this thread, describing how to develop custom code for chromes-sandbox. But this would probably lead to implementing a python interpreter in the sandbox, which would be an overkill.
Any help is appreciated! (I don't want to start any python vs. javascript discussions, but only find out if this would be possible and if so, how to do it)
Kind Regards,
Marco
Python is a programming language, you can't run native code of a programming language. You can however, run programs written in python in the browser.
So can I run python code in the browser or not?
Update June 2013: The Brython project is now available letting you run Python 3 code in your browser. You can check it out at http://www.brython.info/ .
You can use run LLVM in JavaScript using ECMAScripten. This means you can compile c-python from C to JavaScript and just run JS in the browser. The link to the ECMAScripten wiki provides more details on how to do that.
(Here is a live demo of a python REPL running in the browser)
There also exist python 2 implementations that work in the browser.
But should I?
Probably not, JavaScript and python are similar in many things, both are dynamic, both are compact and both are clever. If you know python you can learn JavaScript very quickly.
If you like python's syntax, you might want to consider CoffeeScript which has similar syntax to Python (and somewhat to Ruby) and compiles to JavaScript transparently.
Solutions that run python in the browser will also tend to be much slower, at least until more browsers will support asm.js (currently only firefox nightly).
I believe you can create a compiler in Javascript, to run simple python code. There are probably some available programs as well that will allow this to be carried out. Although, it is not possible to run python directly through a web browser.
Now , it's possible . you can run python in browser
Is it possible to run JavaScript code in parallel in the browser? I'm willing to sacrifice some browser support (IE, Opera, anything else) to gain some edge here.
If you don't have to manipulate the dom, you could use webworkers ... there's a few other restrictions but check it out # http://ejohn.org/blog/web-workers/
Parallel.js of parallel.js.org (see also github source) is a single file JS library that has a nice API for multithreaded processing in JavaScript. It runs both in web browsers and in Node.js.
Perhaps it would be better to recode your JavaScript in something that generally runs faster, rather than trying to speed up the Javascript by going parallel. (I expect you'll find the cost of forking parallel JavaScript activities is pretty high, too, and that may well wipe out any possible parallel gain; this is common problem with parallel programming).
Javascript is interpreted in most browsers IIRC, and it is dynamic on top of it which means it, well, runs slowly.
I'm under the impression you can write Java code and run it under browser plugins. Java is type safe and JIT compiles to machine code. I'd expect that any big computation done in Javascript would run a lot faster in Java. I'm not specifically suggesting Java; any compiled language for which you can get a plug in would do.
As an alternative, Google provides Closure, a JavaScript compiler. It is claimed to be a compiler, but looks like an optimizer to me and I don't know much it "optimizes". But, perhaps you can use that. I'd expect the Closure compiler to be built into Chrome (but I don't know for a fact) and maybe just running Chrome would get your JavaScript compiler "for free".
EDIT: After reading about what about Closure does, as compiler guy I'm not much impressed. It looks like much of the emphasis is on reducing code size which minimizes download time but not necessarily performance. The one good thing they do in function inlining. I doubt that will help as much as switching to a truly compiled langauge.
EDIT2: Apparantly the "Closure" compiler is different than the engine than runs JavaScript in Chrome. I'm told, but don't know this for a fact, that the Chrome engine has a real compiler.
Intel is coming up with an open-source project codenamed River Trail check out http://www.theregister.co.uk/2011/09/17/intel_parallel_javascript/
In terms of quick dynamically typed languages, I'm really starting to like Javascript, as I use it a lot for web projects, especially because it uses the same syntax as Actionscript (flash).
It would be an ideal language for shell scripting, making it easier to move code from the front and back end of a site, and less of the strange syntax of python.
Is there a good, javascript interpreter that is easy to install (I know there's one based on java, but that would mean installing all the java stuff to use),
I personally use SpiderMonkey, but here's an extensive list of ECMAScript shells
Example spidermonkey install and use on Ubuntu:
$ sudo apt-get install spidermonkey
$ js myfile.js
output
$ js
js> var f = function(){};
js> f();
Of course, in Windows, the JavaScript interpreter is shipped with the OS.
Just run cscript or wscript against any .js file.
There are four big javascript interpreters currently. V8, Squirrelfish, Spidermonkey and Rhino. I think more important than performance is how well it integrates into existing infrastructure, and I guess Rhino with its bridge to Java wins here.
Try jslibs, a scripting-focused standalone JS runtime and set of libraries that uses SpiderMonkey (the Gecko JS engine).
On the 'easy to translate' theme, there's also Lua.
It's somewhat similar to Javascript, but more 'orthogonal' (closer to functional roots).
The heavy orientation to 'pure' programming theory has made it really small and fast. It's the fastest scripting language around, and the JIT runs circles around the new JavaScript JITs that are starting to appear.
Also, since it was originally thought as an extension language, it has a very nice and clean interface to C, making it very easy to create bindings to any C library you might want to access.
Google's V8 can be used as a standalone interpreter. Configuring with scons sample=shell will build an executable named shell, that can be called like so: ./shell file.js.
You'll need some server-side JavaScript interpreter. Check out the following blog post. Something such as Rhino might be useful for you.
You might try toying around with SquirrelFish or v8, both should be runnable on the command line.
FYI, there is a built-in one already on modern windows platforms. You need to use JScript, but it's close enough. Same environment also allows for VBScript. To run a program you can execute something like:
cscript foo.js
The windows system API is a bit weird and frustrating if you expect the same flexibility as with basic JS objects, but they do have thorough documentation if you can handle digging through the MSDN pages and seeing all the examples in VBScript.
Not sure what's available for Linux/Mac in terms of js shell.
Well, for safety reasons, javascript had not been provided with file access right by design. So as a scripting language, it's a bit limited.
But still, if you really want to, spider monkey is your best option. Here is a tuto :
http://developer.mozilla.org/en/Introduction_to_the_JavaScript_shell
Node.JS. It's great. Has many modules. you can do all your file scripting with Node.
In my years I've found most Javascript developers find it quite easy to transfer over to PHP and vice versa - it isn't a direct answer to your question, although if you're working in ActionScript and JavaScript then you're best to stick with something like PHP (if you're not willing to move to Java, and stick with the ECMA base)