Emscripten: compiling LLVM to JavaScript

Hi all! I haven't tried the tool myself, but it seems interesting to the Haskell efforts to compile to JavaScript: http://syntensity.blogspot.com/2011/04/emscripten-10.html Cheers, Sönke

On 11 April 2011 14:54, Sönke Hahn
I haven't tried the tool myself, but it seems interesting to the Haskell efforts to compile to JavaScript:
Good grief, that sounds incredibly awesome. GHC → LLVM → JS. Get all GHC's goodies *and* not have to write JS for targeting browsers. Very interested. I will mess with it tonight. Cheers!

Can JS in a browser call out to heavy computational routines in Haskell?
I suppose JS run as a scripting language outside the browser can call
out to Haskell.
Can Haskell open and interact with a browser window without going
through a server like component?
On Mon, Apr 11, 2011 at 9:02 AM, Christopher Done
On 11 April 2011 14:54, Sönke Hahn
wrote: I haven't tried the tool myself, but it seems interesting to the Haskell efforts to compile to JavaScript:
Good grief, that sounds incredibly awesome. GHC → LLVM → JS. Get all GHC's goodies *and* not have to write JS for targeting browsers. Very interested. I will mess with it tonight. Cheers! _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- -- Regards, KC

Time ago YHC compiler (not longer active) got additional backend that
generated JS from Yhc.Core.
It was working quite ok. You can still find demos online.
Generating JS (high level code) from Ghc.Core feels better than from low
level code of LLVM.
Is GHC.core very different from YHC.core?
Sz.
On Mon, Apr 11, 2011 at 6:02 PM, Christopher Done
On 11 April 2011 14:54, Sönke Hahn
wrote: I haven't tried the tool myself, but it seems interesting to the Haskell efforts to compile to JavaScript:
Good grief, that sounds incredibly awesome. GHC → LLVM → JS. Get all GHC's goodies *and* not have to write JS for targeting browsers.
Very interested. I will mess with it tonight.
Cheers!
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Mon, Apr 11, 2011 at 3:54 PM, Sönke Hahn
Hi all!
I haven't tried the tool myself, but it seems interesting to the Haskell efforts to compile to JavaScript:
I saw this same article this morning. I personally am not so interested in compiling Haskell to run as Javascript, though it definitely sounds like a nice idea. I was wondering if we can somehow build Haskell/LLVM bytecode bundles, similar to how Java code gets distributed as JARs. Imagine being able to do any/all of these: * Build a bundle from any package on Hackage. * Have a utility that can convert this to Javascript via emscripten * Create a Haskell runtime for different OSes that can run these bundles, and comes complete with GTK/Qt and a few other basic libraries. * Convert a bundle into something that can run natively on the JVM or CLR. * Create a "Haskell Web Start" where Haskell bundles can be run with a single click from the browser. This is far from my area of expertise, but I know that I could put such a system to good use. A lot of this stuff (running on JVM/CLR for instance) already has a good head start from efforts in the LLVM world. Michael

I do wonder how Emscripten handles the GHC calling convention that is
part of LLVM. In particular, global register declarations in the RTS
scare me from a side line view, and LLVM's calling convention support
is what makes the combination work at all in a registered environment.
It's currently not even possible to compile code using global register
variables to LLVM bitcode - it requires support everywhere from the
frontend all the way to code generation. This is why LLVM uses a
custom calling convention for GHC. The custom CC is also needed to
make sure things like GC etc can work accurately - GC roots for
example are always in predictable physical registers or somesuch.
The RTS will probably need to be heavily modified or flat-out
re-implemented in JS for this to work, I'd think (similar to ghcjs.)
It's possible to get GHC to generate code that does not use global
register variables (normally used when compiling via C, use ack and
search for 'NO_REGS' in the source. It's primarily for unregisterized
builds.) The result is fairly POSIX-compliant code that could be
compiled with, say, clang to produce bitcode.
However, forcing NO_REGS across GHC will mean that certain STG
'registers' are instead mapped to stack locations, not real physical
registers. So it changes the calling convention. The LLVM calling
convention is currently only built to handle a registerized GHC from
what I've seen, and upon entry to STG-land, it's going to expect that
certain STG registers are pinned to physical machine registers.
Result: disasterous CC mismatch.
Of course, perhaps re-implementing the RTS in JS isn't a terrible,
terrible idea. You could for example, swap out GHC's lightweight
threading to use webworkers or somesuch. This would probably be a hell
of a lot more difficult if you were compiling the real C RTS code into
JS indirectly via LLVM.
I don't know if Emscripten is the way to go for compiling Haskell to
JS, but it does open up more possibilities. It's going to be a lot of
work no matter how you approach it though - perhaps we need some
interested team of people willing to do the research.
(NB: I could be wrong on the LLVM note; David T. or one of the Simons
would probably know more and be more qualified to answer.)
On Mon, Apr 11, 2011 at 7:54 AM, Sönke Hahn
Hi all!
I haven't tried the tool myself, but it seems interesting to the Haskell efforts to compile to JavaScript:
http://syntensity.blogspot.com/2011/04/emscripten-10.html
Cheers, Sönke
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Regards, Austin
participants (6)
-
austin seipp
-
Christopher Done
-
KC
-
Michael Snoyman
-
Szymon Jachim
-
Sönke Hahn