Translating Julia to Javascript via LLVM and Emscripten

461 views
Skip to first unread message

Sven Mesecke

unread,
Sep 2, 2013, 12:14:26 PM9/2/13
to julia...@googlegroups.com
Hi,

given that Julia translates to LLVM, I was having some initial thoughts about translating Julia to Javascript. However, I was unable to find some information on how I could get the LLVM code. Any pointers so that I could give it a try? Is there a way for the user to translate Julia to LLVM?

Thanks,
best,
Sven

John Myles White

unread,
Sep 2, 2013, 1:54:30 PM9/2/13
to julia...@googlegroups.com
Check out the code_llvm() function: http://docs.julialang.org/en/latest/manual/metaprogramming/#reflection

-- John

Stefan Karpinski

unread,
Sep 2, 2013, 2:54:17 PM9/2/13
to Julia Users
This won't work at this point for the same reasons that we can't yet generate binaries – we use the LLVM JIT incrementally rather than compiling a large, complete chunk of LLVM code. If it is/were possible to use LLVM to compile itself as JavaScript, then maybe you could do it. Even then, you'd also have to get all of the other external libraries working in JavaScript. That seems like an awfully daunting task – especially getting all those numerical libraries working. OpenBLAS uses an extensive amount of assembly (and MKL is only available in binary form), so for linear algebra, the whole approach unravels.

Sven Mesecke

unread,
Sep 3, 2013, 12:33:18 PM9/3/13
to julia...@googlegroups.com
Thanks for your assessment, seems indeed to be a daunting task. I'll forgo it for now and see how Julia to LLVM develops.

Thanks,

Sven

Stefan Karpinski

unread,
Sep 3, 2013, 1:13:58 PM9/3/13
to Julia Users
What might, however, be very possible is getting Julia's parser running in some JavaScript scheme implementation (such as BiwaScheme). That would be a much more reasonable project and would allow parsing Julia code in the browser to determine when input expressions are complete.

mikeb2012

unread,
Apr 6, 2014, 8:07:31 PM4/6/14
to julia...@googlegroups.com
So where do things stand on this concept of Julia and Javascript interaction? 

Stefan in this thread hints at its potential if it were possible to use LLVM to compile itself.  That seems to have been done (LLVM.js) and the thread here refers to that. 

So I'm confused.  On the one hand, I have Javascript and the browser, _the_ most common GUI on the planet.  And JS does all the whiz bang graphics you could want, people seem to be making really decent IDE's with it, it's totally web compatible and complete with nodejs giving file access and server functionality.  But JS/Node sucks at number crunching.  On the other hand I have Julia, pretty much my go to replacement for Matlab (I've tried Octave, Scilab, etc. and Julia is _it_ ).  And yet, there is still really no great GUI or graphics.  I think:

a) why can't Julia be the number crunching engine that Javascript lacks, and JS the foundation for the graphics and GUI Julia lacks; or
b) could there be a Julia.js in the same way that Processing has ProcessingJS.

So why can't either or both of those things happen?  I see this and think Julia should be the engine driving that train.

Steven G. Johnson

unread,
Apr 6, 2014, 9:43:12 PM4/6/14
to julia...@googlegroups.com
On Sunday, April 6, 2014 8:07:31 PM UTC-4, mikeb2012 wrote: 
a) why can't Julia be the number crunching engine that Javascript lacks, and JS the foundation for the graphics and GUI Julia lacks; or

That's more-or-less how IJulia/IPython works.   The front-end is a lot of Javascript.  See also Gadfly.

Páll Haraldsson

unread,
Oct 8, 2015, 6:31:47 AM10/8/15
to julia-users
On Monday, September 2, 2013 at 6:54:17 PM UTC, Stefan Karpinski wrote:
This won't work at this point for the same reasons that we can't yet generate binaries – we use the LLVM JIT incrementally rather than compiling a large, complete chunk of LLVM code. If it is/were possible to use LLVM to compile itself as JavaScript, then maybe you could do it. Even then, you'd also have to get all of the other external libraries working in JavaScript.

Do you *have to* "get all of the other external libraries working"? See point B.

A,
I would like to see Julia work on Android, iOS, Chrome OS, maybe Firefox OS and Windows Phone. Supporting JavaScript/the web is one way. I see there is progress to get ARM to work, Android (and iOS) support (without MIPS..) might be not far away then, and JavaScript (JS) not needed as much.. Native support seems preferred, as then B. is not an issue..

What is the draw for people to get JavaScript support working? Firefox OS isn't really a priority for me, or would make or break Julia.. It however allows nothing else than JavaScript. Chrome OS, isn't as strict, I haven't looked into Chrome web apps much but think it kind of allows C (also assembly?) code (and latest Chromebook Pixel C is based on Android not Chrome OS, so maybe it is on the way out..).


I looked into the issues for getting other languages to work in a browser (is Scala the best supported language to learn from? Except for, maybe, the made to compile to JS languages, such as Dart), to learn from others.

I worried more about getting all JavaScript libraries (than possibly Julia's own..) supported from Julia, but since Scala-js has the interop (such as for Angualar) then maybe its not hard to do. There are however semantic differences for the Scala code (some I had overlooked, its not just the Integer issue.. would these be a problem?):

"Scala.js underspecifies the behavior of Floats by default. Any Float value can be stored as a Double instead, and any operation on Floats can be computed with double precision. The choice of whether or not to behave as such, when and where, is left to the implementation."

I was a little surprised by this, I thought 1.4 wasn't accurate for double either:
"1.4 matches Double only if strict-floats are enabled, otherwise Float and Double (unlike 1.5, the value 1.4 cannot be represented in a strict 32-bit Float)"

This seems what we could do for Julia (and probably best):
"JavaScript regular expressions are slightly different from Java regular expressions. The support for regular expressions in Scala.js is implemented on top of JavaScript regexes."

"scala.Symbol is supported, but is a potential source of memory leaks in applications that make heavy use of symbols."



I know about http://escher-jl.org/

I assume that doesn't mean it generates JavaScript code from arbitrary Julia code, just enough to make web pages/apps, but in what cases is more really needed? As I understand, Escher tries not to reuse, say Angular, or allow you to. The original announcement says "You don't need to learn or write HTML or CSS or JavaScript". Maybe I misremember, but at some point I read/interpreted Escher to say it generates JS for you, at least it allows for "rich UI".


B.
Of the external libraries (that are not optional - yet..), what is the minimum you need to support? My guess:

LLVM (3.3) — compiler infrastructure. (3.4 not supported; 3.5+ mostly supported, with caveats)
already not a problem.

FemtoLisp — packaged with Julia source, and used to implement the compiler front-end.
or some substitute (mentioned in the thread).

libuv — portable, high-performance event-based I/O library
Is this only for green-threading? Can you skip if you want just basic (single-threaded non-parallel) Julia support.. 

OpenLibm — portable libm library containing elementary math functions.
Skip or just easy to support? I guess this would be the bare minimum to get floats?

DSFMT — fast Mersenne Twister pseudorandom number generator library.
Skip - or just substitute with what JavaScript has?

OpenBLAS — fast, open, and maintained basic linear algebra subprograms (BLAS) library, based on Kazushige Goto's famous GotoBLAS.
Since this is a problem, could even a naive pure Julia matrix multiply (etc. I do not really know this are care too much about [multi] linear algebra) substitute do? Not for everything.. Just so that not everything falls apart..

FFTW (>= 3.3) — library for computing fast Fourier transforms very quickly and efficiently.PCRE (>= 8.31) — Perl-compatible regular expressions library.
Skip. Still wander if supporting would be possible?

GMP (>= 5.0) — GNU multiple precision arithmetic library, needed for BigInt support.
Skip - just reduced functionality, OR as integers are not really supported in JS, support this as the default Int..

MPFR (>= 3.0) — GNU multiple precision floating point library, needed for arbitrary precision floating point (BigFloat) support.
Skip

libgit2 (>= 0.21) — Git linkable library, used by Julia's package manager
How critical is this? Only for developers or just to get any Julia code running?

utf8proc (>= 1.2) — a library for processing UTF-8 encoded Unicode strings
I guess needed, not something JS has as a substitute..

libosxunwind — clone of libunwind, a library that determines the call-chain of a program
Is this only needed for when you get errors? Seems difficult to support, at least for some BSD..

-- 
Palli.
Reply all
Reply to author
Forward
0 new messages