Skip to content
Newer
Older
100644 70 lines (54 sloc) 2.05 KB
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18
19 (**
20 Pass to share constants, simple records and records with only constant fields.
21
22 @author Esther Baruk
23 @author Mathieu Barbin
24 *)
25
26 (**
27 This pass defines for each constant (string, float and records) used in the QML code a toplevel
28 definition.
29 We define a subset of QML ast to work only on the part of the ast which we are interested in.
30
978b7c4 @akoprow [fix] typo: occurence->occurrence, occured->occurred
akoprow authored
31 Then it replaces every occurrence of the constant by the corresponding
fccc685 Initial open-source release
MLstate authored
32 toplevel identifier just defined.
33
34 Example :
35
36 {[
37 _ = %%bslpervasives.print_endline%% "hello"
38 _ = %%bslpervasives.print_endline%% (%%bslpervasives.string_of_float%% 2.)
39 c = 2.
40 _ = %%bslpervasives.print_endline%% "hello"
41
42 is rewritten in
43
44 {[
45 v0_const = "hello"
46 v1_const = 2.
47
48 _ = %%bslpervasives.print_endline%% v0_const
49 _ = %%bslpervasives.print_endline%% (string_of_int v1_const)
50 c = v1_const
51 _ = %%bslpervasives.print_endline%% v0_const
52 ]}
53 The constants ["hello"] and [2.] are now shared thanks to the
54 declaration of two variables at the beginnning of the code.
55
56 For debuging, and choosing what kind of constant to share,
57 cf constant_sharing_* debug variables.
58 *)
59
60 (**
61 Beware, part of the env is mutable, which does not allow
62 to use this module as purelly functionnal with diverge.
63 *)
64 val process_code :
65 side:[`client | `server] ->
66 typed:bool ->
67 QmlTypes.gamma ->
68 QmlAst.annotmap ->
69 QmlAst.code -> (QmlTypes.gamma * QmlAst.annotmap) * QmlAst.code
Something went wrong with that request. Please try again.