Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tools for compiling Python / Boo / Ruby like syntax to C / C++ / LLVM / Javascript (using JS ArrayBuffer for speed)

I'm trying to automatically compile / convert code written with Pythonic semantics into native and fast Javascript code.

What tools can do this, with nice debugging support possible like with Java etc?

Has anyone done this?

Why?

I'm trying to write some visualisation code with a complex main loop, a timeline, some physics simulation, and some complex interaction. I.E: it IS an actual CPU bound problem.

Writing with Javascript and testing in it's browser environment is harder to debug than say, Java, .NET or Python running in a decent IDE. But for doing actual large scale web development with complex client side code, it's necessary to at least compile to Javascript, if not directly write in it.

Background: Recent advances

Emscripten allows compiling C/C++ to Javascript, that can run with increasing efficiency in the browser due to ArrayBuffer's typed array support and new browser JS engines, as ASM.js and LLJS take advantage of Mozilla's recent speed improvements (that other venders will likely soon follow).

Altjs.org has a laundry list of Javascript alternaltives, but doesn't yet focus on the recent speed improvements or nice semantics specifically but it is becoming common place for people to code for browsers with better tools. Emscripten in particular has loads of amazing demos.

Possible options already considered:

  • Shedskin - Currently I have tried getting Shedskin working but I have limited C++/C skills (Emscripten only exposes a C API for the Boehm inspired garbage collector it uses, and Shedskin needs a C++ garbage collection class for it's objects, which doesn't exist yet).
  • Unladen Swallow / RPython, to LLVM - have not been able to setup correctly on Ubuntu yet
  • Boo to Java then to LLVM (not been able to setup on my Ubuntu system yet)

Additional constraints:

  • I need to use this on my Ubuntu system.
  • The compiled Javascript should probably be less than 1 MB
  • Debugging in the native language which is also cross compiled, should still be possible, allowing taking advantage of existing debug tools.

"This process of constructing instruction tables should be very fascinating. There need be no real danger of it ever becoming a drudge, for any processes that are quite mechanical may be turned over to the machine itself." -- Alan M. Turing, 1946

like image 582
Luke Stanley Avatar asked Mar 23 '13 13:03

Luke Stanley


1 Answers

You want a high level dynamic language that compiles down to efficient low level JavaScript? There is no such thing. If dynamic languages were fast we would not need asm.js in the first place.

If you want to write code that compiles to efficient JavaScript your will have to learn a lower level language. The reason why Emscripten is fast is because it compiles from a low level language (C/C++) that allows for greater compiler optimization than regular JavaScript. That is also the reason why asm.js and LLVM can be faster. They get their speed from not have dynamic types, garbage collection (this specifically is what makes it possible to use ArrayBuffer for memory) and other high-level features.

Bottom line is. There exists no tools for compiling a language with Pythonic semantics into native and fast Javascript code. And depending on what you mean by semantics it is unlikely that such a thing will appear since Python is a slow language in itself.

The best option right now for generating fast JavaScript is Emscripten. You could also consider LLJS or writing fast JavaScript by hand (Chrome has debugging tools for this).

Also, considering the title of your question you are very concerned about syntax. You should not be. When choosing the right language for the job the syntax is one of the least important factors.

like image 163
paldepind Avatar answered Sep 23 '22 03:09

paldepind