Skip to content

Commit e352743

Browse files
committed
Merge pull request #22 from besport/compiler
Huge number of compiler improvements contributed by Hugo
2 parents 7a4af62 + b6fdf6b commit e352743

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4226
-1804
lines changed

CHANGES

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,41 @@
22

33
* Features/Changes
44
** Add -linkall option to keep all provided primitives
5+
** Compiler: Add javascript file lookup using findlib
6+
(+mypkg/myfile.js will read myfile.js from mypkg findlib directory)
7+
(by Hugo Heuzard)
8+
** Compiler: Add compilation profiles -opt 1 (2 or 3)
9+
(1 -> as before ; 2 -> loop until fixpoint ; 3 -> enable experimental optim
10+
(by Hugo Heuzard)
11+
** Compiler: Improve missing primitives & reserved name detection
12+
(by Hugo Heuzard)
13+
** Compiler: Add variable renaming (Based on graph coloring)
14+
can be enable with -enable shortvar
15+
(by Hugo Heuzard)
16+
** Compiler: static evaluation of constant ("staticeval" optimisation)
17+
(by Hugo Heuzard)
18+
** Compiler: Share string constant (by Hugo Heuzard)
19+
** Compiler: Alias primitives (by Hugo Heuzard)
20+
** Compiler: Complete javacript ast (by Hugo Heuzard)
21+
** Compiler: 'caml_format_int %d x' compiles to ""+x (by Hugo Heuzard)
22+
** add javascript file in META (to be used with ocamlfind)
23+
(by Hugo Heuzard)
24+
** add Ocamlbuild plugin js_of_ocaml.ocamlbuild
25+
(by Jacques-Pascal Deplaix)
26+
** Add/Install unix.js, classlist.js, weak.js
27+
** Add Url.Current.protocol (by Vicent Balat)
28+
** Dependency: deriving instead of deriving-ocsigen
29+
** Log in case of wrong string encoding (by Hugo Heuzard)
30+
** Add compiler_libs (by Pierre Chambart)
31+
** Add Application Cache (by Marc Simon)
32+
** Compile native syntax extension (by Hugo Heuzard)
33+
** Add a javascript parser (extracted from facebook/pfff)
34+
(to be use later)
35+
36+
* BugFixes
37+
** Compiler: js file is not create in case of error (by Hugo Heuzard)
38+
** Fix compatibility when using type conv (by Hugo Heuzard)
39+
** Fix setTimeout overflow (by Hugo Heuzard)
540

641
===== 1.3 (2012-11-28) =====
742

TODO.txt

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
Priorities
22
==========
33

4-
- use short names for primitives
5-
- share string constants
6-
=====> generic mechanism for sharing constants?
7-
8-
- optimize pattern (new Mlstring("foo").toString())
9-
===> "foo" converted to UTF-8
10-
- new MlString(x) replaced by primitive
11-
124
- unhoist functions when possible
135

146
---------
@@ -80,8 +72,6 @@ Compiler optimizations
8072

8173
- fix control.ml
8274

83-
- detect caml_format_int("%d", x) and generate ""+x
84-
8575
- syntactic sugar for Javascript literal strings
8676
+ optimization to avoid going through Caml strings
8777

@@ -93,13 +83,9 @@ Compiler optimizations
9383
===> explicit conversion to boolean; specialized "if" that operates
9484
on booleans directly
9585

96-
- inlining (especially of functions that are used only once!)
9786
- constant hoisting (including functions, out of loops and functions)
9887
- inline also partially applied functions
9988

100-
- implement variable coalescing (in code generation, reuse the same
101-
name for several variables when they have a disting lifetime)
102-
10389
- we should check stack compatibility when parsing:
10490
when jumping somewhere, the stack should keep the same shape
10591

@@ -184,10 +170,7 @@ COMPACT MODE
184170
============
185171
- We need to insert newlines from time to time to avoid problems with
186172
some routers...
187-
- Code for variable renaming in Javascript code
188-
==> also eliminate redundant "var"?
189-
- Start with function parameters. Then, variables that are used most.
190-
- Use interference mechanism...
173+
- eliminate redundant "var"?
191174

192175
IMPROVEMENTS
193176
============
@@ -197,9 +180,6 @@ IMPROVEMENTS
197180
==> gdtoa
198181
http://caml.inria.fr/pub/ml-archives/caml-list/2002/12/2813f8e8be115b0bad1bc16b1e41b744.en.html
199182

200-
- We only have to make sure we do not use a
201-
reserved word nor a function used outside for naming variables
202-
203183
- explicit conversion from int to boolean
204184

205185
- simplify conditional definition

compiler/.depend

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,79 @@
1-
code.cmo : util.cmi code.cmi
2-
code.cmx : util.cmx code.cmi
1+
code.cmo : util.cmi reserved.cmo option.cmo code.cmi
2+
code.cmx : util.cmx reserved.cmx option.cmx code.cmi
33
control.cmo : subst.cmi code.cmi control.cmi
44
control.cmx : subst.cmx code.cmx control.cmi
5-
deadcode.cmo : util.cmi pure_fun.cmi code.cmi deadcode.cmi
6-
deadcode.cmx : util.cmx pure_fun.cmx code.cmx deadcode.cmi
5+
deadcode.cmo : util.cmi pure_fun.cmi option.cmo code.cmi deadcode.cmi
6+
deadcode.cmx : util.cmx pure_fun.cmx option.cmx code.cmx deadcode.cmi
77
dgraph.cmo : dgraph.cmi
88
dgraph.cmx : dgraph.cmi
9-
driver.cmo : util.cmi tailcall.cmi phisimpl.cmi parse_bytecode.cmi \
10-
js_output.cmi inline.cmi generate.cmi flow.cmi deadcode.cmi code.cmi \
11-
driver.cmi
12-
driver.cmx : util.cmx tailcall.cmx phisimpl.cmx parse_bytecode.cmx \
13-
js_output.cmx inline.cmx generate.cmx flow.cmx deadcode.cmx code.cmx \
14-
driver.cmi
15-
flow.cmo : util.cmi subst.cmi dgraph.cmi code.cmi flow.cmi
16-
flow.cmx : util.cmx subst.cmx dgraph.cmx code.cmx flow.cmi
17-
freevars.cmo : util.cmi code.cmi freevars.cmi
18-
freevars.cmx : util.cmx code.cmx freevars.cmi
19-
generate.cmo : util.cmi subst.cmi primitive.cmi pretty_print.cmi linker.cmi \
20-
js_simpl.cmi js_output.cmi javascript.cmi freevars.cmi code.cmi \
21-
generate.cmi
22-
generate.cmx : util.cmx subst.cmx primitive.cmx pretty_print.cmx linker.cmx \
23-
js_simpl.cmx js_output.cmx javascript.cmx freevars.cmx code.cmx \
24-
generate.cmi
25-
inline.cmo : util.cmi deadcode.cmi code.cmi inline.cmi
26-
inline.cmx : util.cmx deadcode.cmx code.cmx inline.cmi
9+
driver.cmo : tailcall.cmi specialize_js.cmo specialize.cmo primitive.cmi \
10+
pretty_print.cmi phisimpl.cmi parse_bytecode.cmi option.cmo linker.cmi \
11+
js_var.cmi js_output.cmi inline.cmi generate.cmi flow.cmi eval.cmo \
12+
deadcode.cmi code.cmi driver.cmi
13+
driver.cmx : tailcall.cmx specialize_js.cmx specialize.cmx primitive.cmx \
14+
pretty_print.cmx phisimpl.cmx parse_bytecode.cmx option.cmx linker.cmx \
15+
js_var.cmx js_output.cmx inline.cmx generate.cmx flow.cmx eval.cmx \
16+
deadcode.cmx code.cmx driver.cmi
17+
eval.cmo : primitive.cmi flow.cmi code.cmi
18+
eval.cmx : primitive.cmx flow.cmx code.cmx
19+
flow.cmo : util.cmi subst.cmi option.cmo dgraph.cmi code.cmi flow.cmi
20+
flow.cmx : util.cmx subst.cmx option.cmx dgraph.cmx code.cmx flow.cmi
21+
freevars.cmo : util.cmi option.cmo code.cmi freevars.cmi
22+
freevars.cmx : util.cmx option.cmx code.cmx freevars.cmi
23+
generate.cmo : util.cmi subst.cmi primitive.cmi option.cmo js_simpl.cmi \
24+
javascript.cmi freevars.cmi code.cmi generate.cmi
25+
generate.cmx : util.cmx subst.cmx primitive.cmx option.cmx js_simpl.cmx \
26+
javascript.cmx freevars.cmx code.cmx generate.cmi
27+
inline.cmo : subst.cmi code.cmi inline.cmi
28+
inline.cmx : subst.cmx code.cmx inline.cmi
2729
instr.cmo : instr.cmi
2830
instr.cmx : instr.cmi
29-
javascript.cmo : javascript.cmi
30-
javascript.cmx : javascript.cmi
31-
js_output.cmo : pretty_print.cmi javascript.cmi js_output.cmi
32-
js_output.cmx : pretty_print.cmx javascript.cmx js_output.cmi
31+
javascript.cmo : code.cmi javascript.cmi
32+
javascript.cmx : code.cmx javascript.cmi
33+
js_output.cmo : pretty_print.cmi parse_bytecode.cmi option.cmo \
34+
javascript.cmi code.cmi js_output.cmi
35+
js_output.cmx : pretty_print.cmx parse_bytecode.cmx option.cmx \
36+
javascript.cmx code.cmx js_output.cmi
3337
js_rename.cmo : util.cmi javascript.cmi
3438
js_rename.cmx : util.cmx javascript.cmx
35-
js_simpl.cmo : javascript.cmi js_simpl.cmi
36-
js_simpl.cmx : javascript.cmx js_simpl.cmi
37-
linker.cmo : util.cmi primitive.cmi pretty_print.cmi code.cmi linker.cmi
38-
linker.cmx : util.cmx primitive.cmx pretty_print.cmx code.cmx linker.cmi
39-
main.cmo : util.cmi pretty_print.cmi parse_bytecode.cmi linker.cmi \
40-
driver.cmi
41-
main.cmx : util.cmx pretty_print.cmx parse_bytecode.cmx linker.cmx \
42-
driver.cmx
43-
parse_bytecode.cmo : util.cmi primitive.cmi instr.cmi code.cmi \
39+
js_simpl.cmo : javascript.cmi code.cmi js_simpl.cmi
40+
js_simpl.cmx : javascript.cmx code.cmx js_simpl.cmi
41+
js_var.cmo : util.cmi reserved.cmo primitive.cmi option.cmo javascript.cmi \
42+
code.cmi js_var.cmi
43+
js_var.cmx : util.cmx reserved.cmx primitive.cmx option.cmx javascript.cmx \
44+
code.cmx js_var.cmi
45+
linker.cmo : util.cmi primitive.cmi pretty_print.cmi linker.cmi
46+
linker.cmx : util.cmx primitive.cmx pretty_print.cmx linker.cmi
47+
main.cmo : util.cmi pretty_print.cmi parse_bytecode.cmi option.cmo \
48+
linker.cmi driver.cmi
49+
main.cmx : util.cmx pretty_print.cmx parse_bytecode.cmx option.cmx \
50+
linker.cmx driver.cmx
51+
option.cmo :
52+
option.cmx :
53+
parse_bytecode.cmo : util.cmi primitive.cmi option.cmo instr.cmi code.cmi \
4454
parse_bytecode.cmi
45-
parse_bytecode.cmx : util.cmx primitive.cmx instr.cmx code.cmx \
55+
parse_bytecode.cmx : util.cmx primitive.cmx option.cmx instr.cmx code.cmx \
4656
parse_bytecode.cmi
47-
phisimpl.cmo : util.cmi subst.cmi dgraph.cmi code.cmi phisimpl.cmi
48-
phisimpl.cmx : util.cmx subst.cmx dgraph.cmx code.cmx phisimpl.cmi
57+
phisimpl.cmo : util.cmi subst.cmi option.cmo dgraph.cmi code.cmi \
58+
phisimpl.cmi
59+
phisimpl.cmx : util.cmx subst.cmx option.cmx dgraph.cmx code.cmx \
60+
phisimpl.cmi
4961
pretty_print.cmo : pretty_print.cmi
5062
pretty_print.cmx : pretty_print.cmi
51-
primitive.cmo : util.cmi primitive.cmi
52-
primitive.cmx : util.cmx primitive.cmi
63+
primitive.cmo : util.cmi reserved.cmo primitive.cmi
64+
primitive.cmx : util.cmx reserved.cmx primitive.cmi
5365
pure_fun.cmo : primitive.cmi code.cmi pure_fun.cmi
5466
pure_fun.cmx : primitive.cmx code.cmx pure_fun.cmi
67+
reserved.cmo :
68+
reserved.cmx :
69+
specialize.cmo : option.cmo flow.cmi code.cmi
70+
specialize.cmx : option.cmx flow.cmx code.cmx
71+
specialize_js.cmo : flow.cmi code.cmi
72+
specialize_js.cmx : flow.cmx code.cmx
5573
subst.cmo : util.cmi code.cmi subst.cmi
5674
subst.cmx : util.cmx code.cmx subst.cmi
57-
tailcall.cmo : util.cmi subst.cmi code.cmi tailcall.cmi
58-
tailcall.cmx : util.cmx subst.cmx code.cmx tailcall.cmi
75+
tailcall.cmo : util.cmi subst.cmi option.cmo code.cmi tailcall.cmi
76+
tailcall.cmx : util.cmx subst.cmx option.cmx code.cmx tailcall.cmi
5977
util.cmo : util.cmi
6078
util.cmx : util.cmi
6179
code.cmi : util.cmi
@@ -65,12 +83,13 @@ dgraph.cmi :
6583
driver.cmi : pretty_print.cmi parse_bytecode.cmi code.cmi
6684
flow.cmi : code.cmi
6785
freevars.cmi : util.cmi code.cmi
68-
generate.cmi : pretty_print.cmi parse_bytecode.cmi code.cmi
86+
generate.cmi : javascript.cmi code.cmi
6987
inline.cmi : code.cmi
7088
instr.cmi :
71-
javascript.cmi :
72-
js_output.cmi : pretty_print.cmi parse_bytecode.cmi javascript.cmi
73-
js_simpl.cmi : javascript.cmi
89+
javascript.cmi : code.cmi
90+
js_output.cmi : pretty_print.cmi parse_bytecode.cmi javascript.cmi code.cmi
91+
js_simpl.cmi : javascript.cmi code.cmi
92+
js_var.cmi : javascript.cmi code.cmi
7493
linker.cmi : pretty_print.cmi
7594
parse_bytecode.cmi : code.cmi
7695
phisimpl.cmi : code.cmi

compiler/Makefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ all: $(COMPILER)
55

66
lib: compiler.cma compiler.cmxa compiler.cmxs
77

8-
PACKAGES=findlib,str,unix
8+
PACKAGES=findlib,str,unix,ocamlgraph
99

10-
OBJS=pretty_print.cmx util.cmx dgraph.cmx \
11-
javascript.cmx js_output.cmx js_simpl.cmx \
12-
instr.cmx code.cmx primitive.cmx subst.cmx pure_fun.cmx deadcode.cmx \
13-
flow.cmx inline.cmx \
10+
OBJS=pretty_print.cmx reserved.cmx util.cmx option.cmx dgraph.cmx \
11+
code.cmx javascript.cmx js_output.cmx js_simpl.cmx \
12+
instr.cmx primitive.cmx subst.cmx pure_fun.cmx deadcode.cmx \
13+
flow.cmx specialize.cmx specialize_js.cmx eval.cmx inline.cmx \
1414
tailcall.cmx freevars.cmx phisimpl.cmx \
15+
js_var.cmx \
1516
linker.cmx generate.cmx parse_bytecode.cmx driver.cmx
1617

1718
COMPOBJS=$(OBJS) main.cmx
@@ -40,13 +41,13 @@ compiler.cmxs: $(OBJS)
4041
ocamlfind ocamlopt -shared -o $@ $^
4142

4243
%.cmx: %.ml
43-
ocamlfind ocamlopt -package findlib,str -for-pack Compiler -c $<
44+
ocamlfind ocamlopt -package findlib,str,ocamlgraph -for-pack Compiler -c $<
4445

4546
%.cmo: %.ml
46-
ocamlfind ocamlc -package findlib,str -c $<
47+
ocamlfind ocamlc -package findlib,str,ocamlgraph -c $<
4748

4849
%.cmi: %.mli
49-
ocamlfind ocamlc -package findlib,str -c $<
50+
ocamlfind ocamlc -package findlib,str,ocamlgraph -c $<
5051

5152
clean:
5253
rm -f *.cm[aiox] *.cmxa *.cmxs *.o *.a

0 commit comments

Comments
 (0)