Monday, December 29, 2014

Nursery sizes.

Intel i5-3210M cpu, 3072 KB L3 cache. Not sure why the CPU stalls with the tiny nurseries.

Friday, December 12, 2014

Test suite for Haskell2010

To keep track of progress and to ward off regressions, the test suite now have a section for Haskell2010 compatibility checks:

# runhaskell Main.hs -t Haskell2010 --plain | tail -n 4
         Test Cases  Total
 Passed  0           0
 Failed  6           6
 Total   6           6

The tests only cover a small part of the Haskell2010 specification and none of them pass yet.

Thursday, December 4, 2014

Compiling to JavaScript.

Lots of very interesting things are possible when everything (including the runtime system) is translated to LLVM IR. For example, compiling to JavaScript becomes trivial. Consider this ugly version of Hello World:


{-# LANGUAGE MagicHash #-}
module Main (main) where

import LHC.Prim

putStrLn :: List Char -> IO Unit
putStrLn msg = putStr msg `thenIO` putStr (unpackString# "\n"#)

main :: IO Unit
main = putStrLn (unpackString# "Hello World!"#)

entrypoint :: Unit
entrypoint = unsafePerformIO main

Notice the 'List' and 'Unit' types, and the 'thenIO' and  'unpackString#' functions. There's no syntactic sugar in LHC yet. You can get everything sugar-free these days, even Haskell compilers.

Running the code through the LLVM dynamic compiler gives us the expected output:

# lli Hello.ll
Hello World!

Neato, we have a complete Haskell application as a single LLVM file. Now we can compile it to JavaScript without having to worry about the garbage collector or the RTS; Everything has been packed away in this self-contained file.

$ emcc -O2 Hello.ll -o Hello.js # Compile to JavaScript using
                                # emscripten.
$ node Hello.js                 # Run our code with NodeJS.
Hello World!

$ ls -lh Hello.js               # JavaScript isn't known to be
                                # terse but we're still smaller
                                # than HelloWorld compiled with GHC.
-rw-r--r--  1 lemmih  staff   177K Dec  4 23:33 Hello.js