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

I am trying to automatically compile / convert code written using Python semantics into native and fast Javascript code.

What tools can do this, with good debugging support, like Java, etc.

Has anyone done this?

Why?

I am trying to write visualization code with a complex main loop, a timeline, some physical simulation, and some complex interaction. IE: this is a real CPU binding issue.

Writing with Javascript and testing in its browser environment is more difficult to debug than say Java, .NET or Python, working in a decent IDE. But in order to do real large-scale web development with complex client code, you must at least compile Javascript, if not write directly.

Background: Recent Achievements

Emscripten allows you to compile C / C ++ into Javascript, which can work with improved browser performance due to support for ArrayBuffer array arrays and new JS browsers, as ASM.js and LLJS, use the improved Mozilla enhancements recently (which is most likely other vendors will follow).

Altjs.org has a list of Javascript alternaltives underwear, but it does not focus on the latest speed improvements or good semantics yet but for people it is becoming more common for coding browsers with better tools. Emscripten in particular downloads amazing demos .

Possible options:

  • Shedskin - I have currently tried working with Shedskin, but I have limited C ++ / C skills (Emscripten provides only the C API for the garbage collector created by Boehm that it uses, and Shedskin needs a C ++ garbage collection class for it that doesn’t exist yet).
  • Unladen Swallow / RPython, LLVM - unable to configure Ubuntu correctly
  • Boo to Java, then LLVM (not yet installed on my Ubuntu system)

Additional restrictions:

  • I need to use this on my Ubuntu system.
  • Compiled Javascript must be less than 1 MB
  • Debugging in the native language, which is also compiled, is still possible, allowing you to use existing debugging tools.

"This process of constructing instruction tables should be very exciting. There should be no real danger that it will ever become a hard work, since any processes that are completely mechanical can be transferred to the machine itself." - Alan M. Turing, 1946

+6
source share
2 answers

Do you need a high-level dynamic language that compiles to efficient low-level JavaScript? There is no such. If dynamic languages ​​were fast, we would not need asm.js in the first place.

If you want to write code that compiles into efficient JavaScript, you will need to learn a lower level language. The reason Emscripten is fast is because it compiles from a low level language (C / C ++), which allows for better compiler optimization than regular JavaScript. This is also the reason that asm.js and LLVM can be faster. They get their speed from non-dynamic types, garbage collection (this is exactly what ArrayBuffer allows for memory) and other high-level functions.

Bottom line. There are no tools for compiling a language with Python 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 for creating fast JavaScript is Emscripten. You can also consider LLJS or write fast JavaScript manually (Chrome has debugging tools).

Also, given the title of your question, you are very worried about the syntax. You shouldn't be. When choosing the right language for the job, the syntax is one of the least important factors.

+2
source

Since you mentioned shedskin yourself, I would understand that you can share your experience (and explain what exactly, in your opinion, shedskin is missing, except that its input is limited to python grammar). I can also assume that Cython / Pyrex is unacceptable (due to too grammar restrictions).

If shedskin is too much for the alpha scene for you, then you can look for something like a Numba project, which includes a dynamic python compiler in LLVM, as well as llvm-py, which allows you to associate LLVM with open byte code similar to that ctypes allows you to link shared libraries and create LLVM IR compilers.

Here is a cutout from a blog showing how you can use Numba as a JIT for numpy (including comparing performance with equivalent Cython code):

import numpy as np from numba import double from numba.decorators import jit @jit(arg_types=[double[:,:], double[:,:]]) def pairwise_numba(X, D): M = X.shape[0] N = X.shape[1] for i in range(M): for j in range(M): d = 0.0 for k in range(N): tmp = X[i, k] - X[j, k] d += tmp * tmp D[i, j] = np.sqrt(d) 

Emscripten should allow you to expose and invoke your python -> llvm -> JS code, as described here: https://github.com/kripken/emscripten/wiki/Interacting-with-code

+1
source

All Articles