You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OCamlScript is a Javascript backend for [the OCaml language](https://ocaml.org/)
5
-
which aims to provide a better language for the Javascript platform.
4
+
OCamlScript is a JavaScript backend for [the OCaml compiler](https://ocaml.org/). Users of OCamlScript can write type-safe, high performance OCaml code, and deploy the generated JavaScript in any platform with a JavaScript execution engine.
6
5
7
-
One OCaml module is mapped to one JS module, and no name mangling happens
8
-
so that:
6
+
Each OCaml module is mapped to a corresponding JavaScript module, and names are preserved so that:
9
7
10
8
1. The stacktrace is preserved, the generated code is debuggable with or without sourcemap.
11
-
2. You can call `List.length` (List is a module in OCaml standard library)
12
-
in a plain Javascript file.
13
-
9
+
2. Modules generated by OCamlScript can be used directly from other JavaScript code. For example, you can call the `List.length` function from the OCaml standard library `List` module from JavaScript.
14
10
15
11
### A simple example
16
12
@@ -23,7 +19,7 @@ let sum n =
23
19
!v
24
20
```
25
21
26
-
Generated code is as below:
22
+
OCamlScript generates code similar to this:
27
23
28
24
```js
29
25
functionsum(n) {
@@ -35,45 +31,41 @@ function sum(n) {
35
31
}
36
32
```
37
33
38
-
As you can see, there is no name mangling in the generated code, so suppose the
39
-
module is called `M`, you can call `M.sub` in vanilla Javascript
40
-
41
-
You can learn more by playing the online [in-browser compiler](http://zhanghongbo.me/js-demo).
34
+
As you can see, there is no name mangling in the generated code, so if this module is called `M`,
35
+
`M.sum()` is directly callable from other JavaScript code.
42
36
37
+
You can learn more by exploring the online [in-browser compiler](http://zhanghongbo.me/js-demo).
43
38
44
39
45
40
## Disclaimer
46
41
47
-
This project is currently released to exchange ideas outside
48
-
Bloomberg and collect some early feedback from OCaml and Javascript community,
49
-
it is in an *very early* stage and not production ready
50
-
for your own projects *yet*.
42
+
This project has been released to exchange ideas and collect feedback from the OCaml and JavaScript communities.
43
+
It is in an *very early* stage and not production ready for your own projects *yet*.
51
44
52
45
53
46
## Build
54
47
55
-
Note that you have to clone this project with `--recursive` option, we can only distribute
56
-
the patch of OCaml due to License restrictions.
57
-
48
+
Note that you have to clone this project with `--recursive` option, as the core OCaml compiler is brought into your clone as a Git `submodule`.
58
49
59
-
### Linux and Mac OS
50
+
### Linux and Mac OSX
60
51
61
52
62
53
1. Apply the patch to OCaml compiler and build
63
54
64
55
Please ignore the warnings generated by git apply
65
56
66
-
```
57
+
```sh
67
58
cd ocaml
68
59
git apply ../js.diff
69
60
./configure -prefix `pwd`
70
61
make world.opt
71
62
make install
72
63
```
64
+
73
65
2. Build OCamlScript Compiler
74
66
75
-
Assume that you have ocamlopt.opt in the PATH
76
-
```
67
+
Assume that you have `ocamlopt.opt` in the `PATH`
68
+
```sh
77
69
cd ../jscomp
78
70
ocamlopt.opt -I +compiler-libs -I bin -c bin/compiler.mli bin/compiler.ml
It should generate a file called `hello.js`, then we runt the `js` file
105
+
It should generate a file called `hello.js`, which can be executed with any JavaScript engine. In this example, we use Node.js
112
106
113
107
```sh
114
108
node hello.js
115
109
```
110
+
116
111
If everything goes well, you will see `hello world` on your screen.
117
112
118
113
## Windows support
119
114
120
-
We plan to provide a Windows Installer in the near future.
115
+
We plan to provide a Windows nstaller in the near future.
121
116
122
117
# Licensing
123
118
124
-
The [OCaml](./ocaml) directory is a submodule from OCaml's official repo(4.02.3), all its rights
125
-
are reserved by [INRIA](http://www.inria.fr/) (see its QPL LICENSE for more details).
119
+
The [OCaml](./ocaml) directory is the official OCaml compiler (version 4.02.3). Refer to its copyright and license notices for information about its licensing.
126
120
127
-
Our compiler relies on a patch[(js.diff)](./js.diff) to the OCaml compiler.
121
+
The `ocamlscript` backend relies on a patch [(js.diff)](./js.diff) to the OCaml compiler.
128
122
129
-
This project reused and adapted part of [js_of_ocaml](https://github.com/ocsigen/js_of_ocaml)'s:
123
+
This project reused and adapted parts of [js_of_ocaml](https://github.com/ocsigen/js_of_ocaml):
130
124
* Some small printing utilties in [pretty printer](./jscomp/js_dump.ml).
131
125
* Part of the [Javascript runtime](./jscomp/runtime) support
132
126
@@ -145,66 +139,34 @@ JS backend.
145
139
[stdlib](jscomp/stdlib) is copied from ocaml's [stdlib](ocaml/stdlib) to have it compiled with
146
140
the new JS compiler.
147
141
148
-
Since our work is derivative work, we choose the GPL V2 license to
149
-
make it compatible with
150
-
[js_of_ocaml](http://ocsigen.org/js_of_ocaml/).
142
+
Since our work is derivative work of [js_of_ocaml](http://ocsigen.org/js_of_ocaml/), the license of the OCamlScript components is GPLv2, the same as js_of_ocaml.
151
143
152
-
Note that QPL license is not compatible with GPL V2, so we distribute
153
-
our changes to the compiler as a patch instead.
154
-
155
-
## Design goal
144
+
## Design goals
156
145
157
146
1. Readability
158
-
1. No name mangling
159
-
2. Support Javascript modules systems
160
-
3. Integrate with existing javascript ecosystem, for example,
147
+
1. No name mangling.
148
+
2. Support JavaScript module system.
149
+
3. Integrate with existing JavaScript ecosystem, for example,
0 commit comments