Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 160 lines (133 sloc) 3.555 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 Some utils for users of Ocaml lang.
21
22 @author Mathieu Barbin
23 @author Esther Baruk
24 *)
25
26 (**
27 Nary support for applications
28 *)
29 module App :
30 sig
31 (**
32 Gather the arguments of an apply. Returns f * args
33 *)
34 val nary_app : Ocaml.expr -> Ocaml.expr -> Ocaml.expr * Ocaml.expr list
35
36 (**
37 Reconstruct an apply node from f * args
38 *)
39 val app : Ocaml.expr -> Ocaml.expr list -> Ocaml.expr
40 end
41
42 (**
43 Operations on arrays
44 *)
45 module Array : sig
46 (** Avoid an array construction by calling Array.make and filling the array *)
47 val relax_make : Ocaml.expr -> Ocaml.expr
48 end
49
50 (** {6 Type alias} *)
51 (** *)
52 type filename = string
53
54 (** {6 Paths in modules} *)
55
56 (**
57 A ocaml module name.
58 This name is capitalized, like [String, List]
59 *)
60 type module_name = string
61
62 module Module :
63 sig
64
65 (**
66 The path to a module
67 *)
68 type path = module_name list
69
70
71 val of_filename : filename -> module_name
72
73 (**
74 For generating code containing field from records,
75 when you do not want to have conflicting open,
76 it is better to prefix the field by their global
77 module path.
78
79 {[
80 module_path ~full:["A" ; "B" ; "C"] ~pwd:["A"]
81 ]}
82
83 returns
84 {[
85 ["B" ; "C"]
86 ]}
87
88 *)
89 val module_path : full:path -> pwd:path -> path
90 end
91
92 (** {6 Ident} *)
93
94 module Ident :
95 sig
96 (**
97 like {[asr, or, mod, lsr, +, etc...]}
98 *)
99 val is_operator : string -> bool
100 end
101
102 (** {6 Optimizing Ocaml code} *)
103
104 (**
105 * Tries to optimize the code (without affecting its semantics).
106 * For now it only does a couple of simplifications of match
107 * expressions such as:
108 *
109 * [1]
110 * match [EXPR] with
111 * | [V1] -> [V1] -> [EXPR]
112 * | ...
113 * | [Vn] -> [Vn]
114 *
115 * [2]
116 * match [EXPR] with match e with
117 * | [V] -> [V] -> | [V] as E -> E
118 * | ... | ...
119 *
120 * [3]
121 * match match [EXPR] with match [EXPR] with
122 * | A(a1, ..., an) -> B(e_b1, ..., e_bn) | A(a1, ..., an) -> let (b1, ..., bn) = (e_b1, ..., e_bn) in X
123 * | C(c1, ..., cn) -> D(e_d1, ..., e_dn) -> | C(c1, ..., cn) -> let (c1, ..., cn) = (e_c1, ..., e_cn) in Y
124 * with
125 * | B(b1, ..., bn) -> X
126 * | D(d1, ..., dn) -> Y
127 *
128 * All are needed for TRX code generation.
129 * But in the future more optimizations may be added so it's good
130 * to apply this functions to your generated code so that it can
131 * benefit from them as they come.
132 *)
133 val optimize : Ocaml.code -> Ocaml.code
134
135 (**
136 Misc
137 *)
138 module Misc :
139 sig
140 (**
141 Utils for passtracker.
142 Returns the number of node of an expression.
143 FIXME:
144 currently, the pattern are not counted.
145 *)
146 val size : Ocaml.expr -> int
147 end
148
149 (**
150 Simple dependencies computation.
151 *)
152 module Deps :
153 sig
154 (**
155 Fold on every ident.
156 Used for computing the dependency of an expression.
157 *)
158 val deps : (Ocaml.param_effectif -> 'acc -> 'acc) -> 'acc -> Ocaml.expr -> 'acc
159 end
Something went wrong with that request. Please try again.