All of Standard ML. SMLtoJs has support for all of Standard ML, including modules, pattern matching, higher-order functions, generative exceptions, etc.
Standard ML Basis Library support. SMLtoJs has support for most of the Standard ML basis library, including the following structures:
Array2 ArraySlice Array Bool Byte Char CharArray CharArraySlice CharVector CharVectorSlice Date General Int Int31 Int32 IntInf LargeWord ListPair List Math Option OS.Path Pack32Big Pack32Little Random Real StringCvt String Substring Text Time Timer Vector VectorSlice Word Word31 Word32 Word8 Word8Array Word8ArraySlice Word8Vector Word8VectorSlice
Simple DOM access support and support for installing Standard ML functions as DOM event handlers and timer call back functions.
Compiling in the Browser. A version of SMLtoJs can be compiled by SMLtoJs itself, which leads to a proper browser hosted Standard ML compiler.
To see SMLtoJs in action, see the SMLtoJs homepage for links to online examples of compiled Standard ML and the Web browser hosted Standard ML compiler.
Getting the Sources
SMLtoJs compiles on Linux and Mac OS systems with MLton or MLKit. The SMLtoJs sources are hosted at Github. To get the latest sources, issue the following git command:
$ git clone https://github.com/melsman/mlkit.git smltojs
This command copies the sources to the directory smltojs.
To compile SMLtoJs from the sources (see above), simply type
$ cd smltojs $ ./autobuild $ ./configure $ make smltojs $ make smltojs_basislibs
If compilation succeeds, an executable file bin/smltojs should now be available.
How it Works
The SMLtoJs executable
bin/smltojs takes as argument an sml-file
(or an mlb-file referencing the sml-files and other mlb-files of the
project) and produces an html file called
run.html provided there are
no type errors! The resulting html-file mentions the generated
prims.js, which contains a set of
Hint: Adding the flag
-o name as command-line argument to smltojs
results in the file name.html being generated instead of run.html.
Testing that it Works
To compile and test the test programs, cd to the
make clean all:
$ cd js/test $ make clean all
You can now start Firefox or Chrome on the generated html-files; the file all.html includes links to all the test files:
$ firefox all.html
life.html are the most
interesting examples at the moment (more will come).
Compilation in the Browser
To build the browser-hosted compiler, proceed as follows:
$ cd ../../src/Compiler $ SML_LIB=$(HOME)/smltojs/js ../../bin/smltojs -aopt smltojs0.mlb
The last command should generate a file
run.html which links to all
$ firefox run.html
will start up a simple IDE for the compiler.
There is a known issue with a bug in the following test (in some cases, the implementation pretty prints reals slightly different than suggested by the spec):
real ---- test13c: WRONG
There are plenty of possibilities for further improvements, including:
Functor in-lining, which may lead to improved execution speed.
Improved constant folding. Some features are implemented with the
--aggressive_optflag to smltojs (
License and Copyright
The MLKit compiler is distributed under the GNU Public License,
version 2. See the file MLKit-LICENSE
for details. The runtime system (
/src/Runtime/) and libraries
basis/) is distributed under the more liberal MIT License.