Difference between revisions of "SAPL"

From Clean
Jump to navigationJump to search
 
(59 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{|style="width:100%; border:none"
 
{|style="width:100%; border:none"
|style="width:70%; vertical-align: top; padding-right: 20px;"|
+
|style="width:70%; vertical-align: top; padding-right: 40px;"|
  
 
[[File:sapl-logo.png|left|text-top|300px|SAPL]]
 
[[File:sapl-logo.png|left|text-top|300px|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.
+
<span style="font-size:130%">'''Note:''' ''The SAPL compiler infrastructure project is no longer in development. The content on these pages is provided as a historical reference only. The SAPL language and the SAPL to JavaScript compiler is integrated with the Clean compiler and still in development / maintaned, but the GHC to SAPL compiler is not maintained any more, because of the lack of resources to keep up with the changes of the SAPL language and the GHC compiler.''</span>
 +
 
 +
 
 +
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] and Java target is under development. SAPL is extensively used in the [[ITasks]] project, furthermore various GHC based projects are experimenting with SAPL.
  
 
== Overview ==
 
== Overview ==
Line 13: Line 16:
  
 
Source filters convert the source language to the SAPL language. Currently we have source filters for Clean and Haskell/GHC. For Clean, the filter is integrated into the compiler. As for Haskell/GHC, a separate compiler is provided based on the original one.
 
Source filters convert the source language to the SAPL language. Currently we have source filters for Clean and Haskell/GHC. For Clean, the filter is integrated into the compiler. As for Haskell/GHC, a separate compiler is provided based on the original one.
 +
Detailed instructions for their usages can be found at [[SAPL/Clean]] and [[SAPL/GHC]], respectively.
 +
 +
==== SAPL linker ====
  
# '''SAPL linker'''. It collects and combine, starting with some root expressions, the necessary functions recursively into one SAPL file. This helps with minimizing the size of the output code.
+
SAPL has hierarchical module support based on directory layout. Prior to the target compilation a linking
# '''Flavours'''. A flavour is a kind of configuration file used by the target compilers. It provides information about how to compile the built-in functions of a given source language to a given target language.
+
step is required to collect and combine, based on arbitrary root expressions, the necessary functions recursively from the separate modules into one SAPL file which will be the input of the target compilers.
# '''Target compilers'''. A target compiler transforms SAPL code into a given target language. The compilation must be aided by a flavour for the correct compilation of the built-in functions.
 
# '''Target run-time'''. Run-time functions are necessary to execute the target code. Some of these are independent of the source language and cope with e.g. lazy evaluation, while some are dependent of the source language and must be in sync with the source filter and the supporting flavour.
 
  
== Getting started ==
+
As the SAPL language is designed for easy parsing, linking is very fast and straightforward compared to the linking
 +
of the target languages (e.g. JavaScript) and helps with minimizing the size of the output code.
  
So far, no official version of the SAPL compiler infrastructure is released. The current development version can be
+
==== Flavours ====
checked out from https://svn.cs.ru.nl/repos/clean-sapl. Build instructions can be found at [[SAPL/Build]]
 
  
=== GHC ===
+
A flavour is a kind of configuration file used by the target compilers. It provides information about how to compile the built-in functions of a given source language to a given target language. It must be in sync with the source filter and source language dependent part of the run-time system. Flavours are provided for all the combinations of source and target languages.
  
=== Clean ===
+
==== Target compilers ====
 +
 
 +
A target compiler transforms SAPL code into a given target language. The compilation must be aided by a flavour for the correct compilation of the built-in functions. The SAPL library supports the development of target languages by providing a lexer and parser for the SAPL language along with language transformation functions (e.g. Topological ordering of let definitions), and other support functions (e.g. strictness propagation, type inference etc). Currently JavaScript is the only target language supported, however DART and Java targets are under development.
 +
 
 +
==== Target run-time ====
 +
 
 +
Run-time functions are necessary to execute the target code. Some of these are independent of the source language and cope with e.g. lazy evaluation, while some are dependent of the source language and must be in sync with the source filter and the supporting flavour. Some language features must be supported by the run-time system, for the current state of/features supported by the run-times please consult with the appropriate page:
 +
 
 +
* [[Clean/JavaScript]]
 +
* [[Haskell/GHC/JavaScript]]
 +
 
 +
== Tutorial (Clean) ==
 +
 
 +
The SAPL compiler and linker is fully integrated into the upcoming version of the Clean compiler.
 +
Until that becomes available, please contact me for instructions by dlacko@gmail.com.
  
 
== Tutorial (GHC) ==
 
== Tutorial (GHC) ==
  
Before you engage in following this tutorial, please make sure you successfully
+
As for GHC a carefully adjusted environment must be used for the SAPL compilation (e.g. 32bit compiler must be used,
installed the SAPL system as it is written at [[SAPL/Build]].
+
for more explanation please consult to [[Sapl/GHC]]). We use [http://www.vagrantup.com Vagrant] to provide this environment by virtualisation.
 +
However, you don't need any knowledge on Vagrant, all you have to do is to install [http://www.vagrantup.com/downloads.html Vagrant] in one simple step (you also need to install a low level virtualizer e.g. [https://www.virtualbox.org/ VirtualBox] and some SSH client if you do not have one installed), check out the following SVN URL
 +
 
 +
https://svn.cs.ru.nl/repos/clean-sapl/trunk/platforms/GHC/vagrant
 +
 
 +
and in directory where you checked out type
 +
 
 +
  $ vagrant up
 +
followed by
 +
 
 +
  $ vagrant ssh
 +
and you find yourself using a shell where all the SAPL components are available precompiled. The current directory outside the virtual machine can be accessed at the directory <tt>/vagrant</tt>.
 +
Now, create a <tt>hello.hs</tt> with the well knows "Hello, World!" example:
 +
 
 +
  $ mkdir hello
 +
  $ cd hello
 +
  $ cat > hello.hs
 +
    main = putStrLn "Hello, World!"^D
 +
First step, compile it to SAPL:
 +
  $ ghcsapl hello.hs
 +
It creates a <tt>Main.sapl</tt>, as SAPL file names are the names of the modules rather than the original file names.
 +
 
 +
If you are brave enough, have a look at the generated SAPL source code. It consists of three simple lines only,
 +
with references to functions located in other modules, e.g. <tt>System.IO</tt>. For proper compilation you need to collect the
 +
necessary functions from these modules. Precompiled SAPL files can be found in <tt>~/sapl/packages</tt>,
 +
the base system modules are in <tt>core/base</tt> and <tt>core/ghc-prim</tt> within that. Use the <tt>sl</tt> command for linking:
 +
 
 +
  $ sl -I ~/sapl/packages/core/base -I ~/sapl/packages/core/ghc-prim -i Main.sapl -e Main.main hello.sapl
 +
This command produces a <tt>hello.sapl</tt> file which is already self-contained.
 +
Finally the
 +
  $ sapl2js -f ghc hello.sapl
 +
produces JavaScript output of approximately 1300 bytes as <tt>hello.js</tt>. Please note the usage of the "ghc" flavour.
 +
I recommend one optimal step, the utilization of [https://developers.google.com/closure/compiler/ closure compiler] to reduce code size and execution time:
 +
  $ java -jar ~/sapl/tools/closure-compiler.jar --js_output_file hello_opt.js hello.js
 +
For the execution check out the necessary run-time from the following URLs:
 +
 
 +
* https://svn.cs.ru.nl/repos/clean-sapl/trunk/platforms/GHC/run-time
 +
* https://svn.cs.ru.nl/repos/clean-sapl/trunk/platforms/Common/run-time
 +
 
 +
It contains a template HTML file named <tt>client.html</tt> for the execution of a function placed in a file <tt>main.js</tt>.
 +
So all you need is to copy all the files of the run-time and either <tt>hello.js</tt> or <tt>hello_opt.js</tt> (renamed to <tt>main.js</tt>)
 +
into one common directory.
 +
 
 +
For more elaborated projects I also recommend to create a <tt>Makefile</tt>. For this simplistic case it could be like this:
 +
 
 +
<pre>
 +
SL=sl --include-dir=~/sapl/packages/core/base \
 +
      --include-dir=~/sapl/packages/core/ghc-prim
 +
S2JS=sapl2js -f ghc
 +
GHCSAPL=ghcsapl -O2
 +
CC=java -jar ~/sapl/tools/closure-compiler.jar 
 +
 
 +
all: create hello_opt.js
 +
 +
hello_opt.js:
 +
    $(GHCSAPL) --make hello.hs
 +
    $(SL) -i Main.sapl -e Main.main hello.sapl
 +
    $(SAPL2JS) hello.sapl
 +
    $(CC) --js_output_file hello_opt.js hello.js
 +
</pre>
 +
 
 +
== Publications ==
 +
 
 +
There are two publications that are closely related to the current form of SAPL, however, both of them are slightly outdated. The SAPL language described in the first paper is already modified several times for various reasons, but the compilation scheme is still basically the same. As for the second paper, most of the shortcomings listed there are solved after the publication (some of them by adjusting the SAPL language itself) and currently the transformation scheme support all of the Haskell/GHC language features. The third paper describes the original SAPL language the first time.
 +
 
 +
# László Domoszlai and E. Bruel and J.M. Jansen. Implementing a non-strict purely functional language in JavaScript. ''Acta Univ. Sapientiae. Informatica'', 3(1):76-98, 2011
 +
# László Domoszlai and Rinus Plasmeijer. Compiling Haskell to JavaScript through Clean's core. ''Annales Univ. Sci.'', 36:117--142, 2012. Selected papers of 9th Joint Conference on Mathematics and Computer Science, MaCS 2012, February 9-12, 2012, Siófok, Hungary
 +
# J.M. Jansen and P. Koopman, and R. Plasmeijer. Efficient interpretation by transforming data types and patterns to functions. ''Selected Papers of the 7th Symposium on Trends in Functional Programming, TFP'06'', volume 7, pages 73-90, Nottingham, UK, 2006.
 +
 
 +
== Contact ==
  
TODO
+
If you have any question related to any part of the SAPL infrastructure, please do not hesitate to contact to László Domoszlai by dlacko@gmail.com.
  
 
|style="width:30%; vertical-align: top; padding-right: 20px;"|
 
|style="width:30%; vertical-align: top; padding-right: 20px;"|

Latest revision as of 14:01, 18 September 2017

SAPL

Note: The SAPL compiler infrastructure project is no longer in development. The content on these pages is provided as a historical reference only. The SAPL language and the SAPL to JavaScript compiler is integrated with the Clean compiler and still in development / maintaned, but the GHC to SAPL compiler is not maintained any more, because of the lack of resources to keep up with the changes of the SAPL language and the GHC compiler.


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 and Java target is under development. SAPL is extensively used in the ITasks project, furthermore various GHC based projects are experimenting with SAPL.

Overview

SAPL infrastructure consists of a few main parts built around the SAPL Language.

Source filters

Source filters convert the source language to the SAPL language. Currently we have source filters for Clean and Haskell/GHC. For Clean, the filter is integrated into the compiler. As for Haskell/GHC, a separate compiler is provided based on the original one. Detailed instructions for their usages can be found at SAPL/Clean and SAPL/GHC, respectively.

SAPL linker

SAPL has hierarchical module support based on directory layout. Prior to the target compilation a linking step is required to collect and combine, based on arbitrary root expressions, the necessary functions recursively from the separate modules into one SAPL file which will be the input of the target compilers.

As the SAPL language is designed for easy parsing, linking is very fast and straightforward compared to the linking of the target languages (e.g. JavaScript) and helps with minimizing the size of the output code.

Flavours

A flavour is a kind of configuration file used by the target compilers. It provides information about how to compile the built-in functions of a given source language to a given target language. It must be in sync with the source filter and source language dependent part of the run-time system. Flavours are provided for all the combinations of source and target languages.

Target compilers

A target compiler transforms SAPL code into a given target language. The compilation must be aided by a flavour for the correct compilation of the built-in functions. The SAPL library supports the development of target languages by providing a lexer and parser for the SAPL language along with language transformation functions (e.g. Topological ordering of let definitions), and other support functions (e.g. strictness propagation, type inference etc). Currently JavaScript is the only target language supported, however DART and Java targets are under development.

Target run-time

Run-time functions are necessary to execute the target code. Some of these are independent of the source language and cope with e.g. lazy evaluation, while some are dependent of the source language and must be in sync with the source filter and the supporting flavour. Some language features must be supported by the run-time system, for the current state of/features supported by the run-times please consult with the appropriate page:

Tutorial (Clean)

The SAPL compiler and linker is fully integrated into the upcoming version of the Clean compiler. Until that becomes available, please contact me for instructions by dlacko@gmail.com.

Tutorial (GHC)

As for GHC a carefully adjusted environment must be used for the SAPL compilation (e.g. 32bit compiler must be used, for more explanation please consult to Sapl/GHC). We use Vagrant to provide this environment by virtualisation. However, you don't need any knowledge on Vagrant, all you have to do is to install Vagrant in one simple step (you also need to install a low level virtualizer e.g. VirtualBox and some SSH client if you do not have one installed), check out the following SVN URL

https://svn.cs.ru.nl/repos/clean-sapl/trunk/platforms/GHC/vagrant

and in directory where you checked out type

 $ vagrant up 

followed by

 $ vagrant ssh

and you find yourself using a shell where all the SAPL components are available precompiled. The current directory outside the virtual machine can be accessed at the directory /vagrant. Now, create a hello.hs with the well knows "Hello, World!" example:

 $ mkdir hello
 $ cd hello
 $ cat > hello.hs
   main = putStrLn "Hello, World!"^D

First step, compile it to SAPL:

 $ ghcsapl hello.hs

It creates a Main.sapl, as SAPL file names are the names of the modules rather than the original file names.

If you are brave enough, have a look at the generated SAPL source code. It consists of three simple lines only, with references to functions located in other modules, e.g. System.IO. For proper compilation you need to collect the necessary functions from these modules. Precompiled SAPL files can be found in ~/sapl/packages, the base system modules are in core/base and core/ghc-prim within that. Use the sl command for linking:

 $ sl -I ~/sapl/packages/core/base -I ~/sapl/packages/core/ghc-prim -i Main.sapl -e Main.main hello.sapl

This command produces a hello.sapl file which is already self-contained. Finally the

 $ sapl2js -f ghc hello.sapl

produces JavaScript output of approximately 1300 bytes as hello.js. Please note the usage of the "ghc" flavour. I recommend one optimal step, the utilization of closure compiler to reduce code size and execution time:

 $ java -jar ~/sapl/tools/closure-compiler.jar --js_output_file hello_opt.js hello.js

For the execution check out the necessary run-time from the following URLs:

It contains a template HTML file named client.html for the execution of a function placed in a file main.js. So all you need is to copy all the files of the run-time and either hello.js or hello_opt.js (renamed to main.js) into one common directory.

For more elaborated projects I also recommend to create a Makefile. For this simplistic case it could be like this:

SL=sl --include-dir=~/sapl/packages/core/base \
      --include-dir=~/sapl/packages/core/ghc-prim
S2JS=sapl2js -f ghc
GHCSAPL=ghcsapl -O2
CC=java -jar ~/sapl/tools/closure-compiler.jar   

all: create hello_opt.js
	
hello_opt.js:
    $(GHCSAPL) --make hello.hs
    $(SL) -i Main.sapl -e Main.main hello.sapl
    $(SAPL2JS) hello.sapl
    $(CC) --js_output_file hello_opt.js hello.js

Publications

There are two publications that are closely related to the current form of SAPL, however, both of them are slightly outdated. The SAPL language described in the first paper is already modified several times for various reasons, but the compilation scheme is still basically the same. As for the second paper, most of the shortcomings listed there are solved after the publication (some of them by adjusting the SAPL language itself) and currently the transformation scheme support all of the Haskell/GHC language features. The third paper describes the original SAPL language the first time.

  1. László Domoszlai and E. Bruel and J.M. Jansen. Implementing a non-strict purely functional language in JavaScript. Acta Univ. Sapientiae. Informatica, 3(1):76-98, 2011
  2. László Domoszlai and Rinus Plasmeijer. Compiling Haskell to JavaScript through Clean's core. Annales Univ. Sci., 36:117--142, 2012. Selected papers of 9th Joint Conference on Mathematics and Computer Science, MaCS 2012, February 9-12, 2012, Siófok, Hungary
  3. J.M. Jansen and P. Koopman, and R. Plasmeijer. Efficient interpretation by transforming data types and patterns to functions. Selected Papers of the 7th Symposium on Trends in Functional Programming, TFP'06, volume 7, pages 73-90, Nottingham, UK, 2006.

Contact

If you have any question related to any part of the SAPL infrastructure, please do not hesitate to contact to László Domoszlai by dlacko@gmail.com.

News

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