forked from melsman/mlkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME_SMLTOJS
More file actions
152 lines (107 loc) · 4.82 KB
/
README_SMLTOJS
File metadata and controls
152 lines (107 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
This is file README_SMLTOJS mael 2013-06-04
INTRODUCTION
------------
SMLtoJs (pronounced "SML toys") is a compiler from Standard ML to
JavaScript, which allows programmers to enjoy the power of Standard ML
static typing, higher-order functions, pattern matching, and modules
for programming client-side web applications.
SMLtoJs compiles all of Standard ML, including most of the Standard ML
Basis Library. It also has good support for integrating with
JavaScript.
FEATURES
--------
* 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
* JavaScript integration. SMLtoJs has support for calling JavaScript
functions and for executing JavaScript statements.
* Simple DOM access support and support for installing Standard ML
functions as DOM event handlers and timer call back functions.
* Optimization. All Modules language constructs, including functors,
functor applications, and signature constraints, are eliminated by
SMLtoJs at compile time. Moreover, SMLtoJs performs a series of
compile time optimizations, including function inlining and
specialization of higher-order recursive functions, such as map
and foldl. Optimizations can be controlled using compile-time
flags. As a result, SMLtoJs generates fairly efficient JavaScript
code, although there are rooms for improvements; see below.
* Compiling in the Browser. A version of SMLtoJs can be compiled by
SMLtoJs itself, which leads to a proper browser hosted Standard ML
compiler.
ONLINE DEMONSTRATION
--------------------
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:
http://www.smlserver.org/smltojs
GETTING THE SOURCES
-------------------
SMLtoJs compiles on Debian 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.
BUILDING 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
JavaScript files and a file prims.js, which contains a set of
primitive JavaScript functions used by the generated code.
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 js/test directory
and run "make clean all":
$ cd js/test
$ make clean all
You can now start Firefox on the generated html-files; the file
all.html includes links to all the test files:
$ firefox all.html
The examples temp.html, counter.html, and 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
necessary JavaScript sources. Executing
$ firefox run.html
will start up a simple IDE for the compiler.
ISSUES
------
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_opt flag to smltojs (-aopt).
COPYRIGHT AND LICENSE
---------------------
See the files in doc/license for copyright notices and license
information.