Difference between revisions of "SAPL"

From Clean
Jump to navigationJump to search
Line 5: Line 5:
  
 
SAPL is a purely functional, intermediate language and related infrastructure for supporting cross-compilation of lazy functional languages to different target platforms. It currently supports [[Clean]] and [http://www.haskell.org/ghc/‎ Haskell/GHC] as source languages and provides JavaScript as target platform, however a [http://www.dartlang.org‎ DART] target is under development. SAPL is extensively used in the [[ITasks]] project, furthermore various GHC based projects are experimenting with SAPL.
 
SAPL is a purely functional, intermediate language and related infrastructure for supporting cross-compilation of lazy functional languages to different target platforms. It currently supports [[Clean]] and [http://www.haskell.org/ghc/‎ Haskell/GHC] as source languages and provides JavaScript as target platform, however a [http://www.dartlang.org‎ DART] target is under development. SAPL is extensively used in the [[ITasks]] project, furthermore various GHC based projects are experimenting with SAPL.
 
== Getting started ==
 
 
So far, no official version of the SAPL compiler infrastructure is released. The current development version can be
 
checked out from https://svn.cs.ru.nl/repos/clean-sapl. Build instructions can be found at [[SAPL/Build]]
 
  
 
== Overview ==
 
== Overview ==
Line 84: Line 79:
 
and at [https://svn.cs.ru.nl/repos/clean-sapl/trunk/platforms/Clean/run-time Clean run-time]. You also need to borrow the common
 
and at [https://svn.cs.ru.nl/repos/clean-sapl/trunk/platforms/Clean/run-time Clean run-time]. You also need to borrow the common
 
part of the RTS from [https://svn.cs.ru.nl/repos/clean-sapl/trunk/platforms/Common/run-time Common RTS].
 
part of the RTS from [https://svn.cs.ru.nl/repos/clean-sapl/trunk/platforms/Common/run-time Common RTS].
 +
 +
== Getting started ==
 +
 +
So far, no official version of the SAPL compiler infrastructure is released. The current development version can be
 +
checked out from https://svn.cs.ru.nl/repos/clean-sapl. Build instructions can be found at [[SAPL/Build]]
  
 
== Tutorial (GHC) ==
 
== Tutorial (GHC) ==

Revision as of 20:40, 4 January 2014

SAPL

SAPL is a purely functional, intermediate language and related infrastructure for supporting cross-compilation of lazy functional languages to different target platforms. It currently supports Clean and Haskell/GHC as source languages and provides JavaScript as target platform, however a DART target is under development. SAPL is extensively used in the ITasks project, furthermore various GHC based projects are experimenting with SAPL.

Overview

Compiling Clean or Haskell to JavaScript consists of three easy steps. First, you need to compile the necessary source code modules to the SAPL language. The execution of this step depends on the source language you would like to use. Instructions for Clean and Haskell/GHC can be found at SAPL/Clean and SAPL/GHC, respectively.

Linking

The second step is to collect and combine, starting with some root expressions, the necessary functions recursively into one SAPL file. Engaging on this linking step helps with reducing the final code size as much as possible. The linking is done using the sl command. A simple example for its usage is as follows:

sl --include-dir=build --expr=Main.main out.sapl

It links for the main function in the module called Main and collects all the necessary functions into the out.sapl file. The module search path is the build directory in the current directory. Multiple root expressions and include directories can be provided. For the other command line arguments please type

sl --help

Final compilation

The result of the sl command can be compiled to JavaScript using the sapl2js command. The following example compiles out.sapl to JavaScript and places the result in the file out.js.

sapl2js -f clean -o out.js out.sapl

Please note the usage of the -f command line argument. The target code depends on the source language as different languages use different primitive/built-in functions. Thus, during the final compilation step, the compiler must be aware of the primitive functions contained by the SAPL source code.

This information is provided by the so called flavor file to the final compiler. The file has an extension of ".f" and it describes how to compile the primitive functions of a given source language to a given target language. As currently we have two source languages and one target platform, two flavor files are provided: one for the compilation of Clean to JavaScript (clean.f) and one for compilation of Haskell/GHC to JavaScript (ghc.f). The compiler looks up the flavor file in the following directories in the given order:

  1. in the current directory
  2. in the directory which contains the executable of the compiler (bindir)
  3. bindir/../lib/sapl/
  4. bindir/../lib/

For further command line arguments please type

sapl2js --help

Micro optimizations

As an optional step, we recommend to use Closure Compiler for micro optimizations of the generated JavaScript code. It can speed up the generated JavaScript code by up to 10-20 percents. You can use a following command:

java -jar closure-compiler.jar --js_output_file out.js in.js

Execution

For the execution of the final script you need to cope with the SAPL run-time engine. It consists of the actual run-time functions and the implementation of the primitive functions. This latter depends on the source language, thus, you need (partly) different run-time for different source languages.

Template HTML as well as the necessary JavaScript files for GHC and Clean can be found at GHC run-time and at Clean run-time. You also need to borrow the common part of the RTS from Common RTS.

Getting started

So far, no official version of the SAPL compiler infrastructure is released. The current development version can be checked out from https://svn.cs.ru.nl/repos/clean-sapl. Build instructions can be found at SAPL/Build

Tutorial (GHC)

Before you engage in following this tutorial, please make sure you successfully installed the SAPL system as it is written at SAPL/Build.

TODO

News

  • January 2 2014: The first draft version of the SAPL wiki is added