Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 193 lines (149 sloc) 7.385 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 Explicit instantiation adds type abstractions and type applications
20 throughout the code to resolve the \@typeof directive
21
22 Only the necessary part of the code is instrumented in this way
23 (when you don't use (transitively) \@typeof, your code is not
24 rewritten)
25
26 Preconditions: the code is typed
27
28 Directives removed: \@typeof
29 *)
30
31
32 (* Hack: 2 global refs instead of function arguments; TODO: unhack *)
33
34 (** A map of top-level expressions published between client and server *)
35 type published_map = (Annot.label * Ident.t * [`one_lambda | `two_lambdas]) option IdentMap.t
36 val published_ref : published_map ref
37
38 (** The link between current identifiers and the ones before slicing *)
39 val renaming_map : QmlRenamingMap.t ref
40
41
42 (** Building representation of types in OPA *)
43
44 (**
45 The type of type representations
46 See stdlib/package/stdlib/core/opatype.opa
47 *)
48 val opatype_type : QmlAst.ty
49 val oparow_type : QmlAst.ty
50 val opacol_type : QmlAst.ty
51
52 (** [ty_to_opaty ~side annotmap gamma ty] represents a type [ty] in OPA,
53 as an OPA expression. The type of these OPA expressions is defined
54 in the OPA standard library.
55
56 @param side on which side we are, meaningless when memoization is off
57 @param annotmap the annotmap for, e.g., creating new OPA expressions
58 @param gamma the environment with type definitions
59 @param ty type to be represented in OPA.
60
61 @return Updated annotmap, and an OPA representation of [ty].
62 *)
63 val ty_to_opaty :
64 side:[ `server | `client ] -> ?memoize:bool -> ?normalize:bool
65 -> QmlAst.annotmap -> QmlTypes.gamma -> QmlAst.ty -> val_:(?side:[`client|`server] -> string -> Ident.t)
66 -> QmlAst.annotmap * QmlAst.expr
67
68 (** [get_memoized_definitions gamma side] adds to gamma type schemes
69 of the new top level definitions visible at [side], generated
70 as a side effect by [ty_to_opaty]. *)
71 val get_memoized_definitions :
72 QmlTypes.gamma -> [ `server | `client ]
73 -> QmlTypes.gamma * QmlAst.code
74
75 (** A dummy representation of type that can be inserted when [process_code]
76 will not be called on a given expression, e.g., because
77 Explicit Instantiation is disabled by a compilation option. *)
78 val dummy_opaty :
79 QmlAst.annotmap -> QmlAstCons.TypedExpr.gamma
80 -> QmlAst.annotmap * QmlAst.expr
81
82 (**
83 A specialized version of [ty_to_opaty] for opadoc.
84 Scopes of variables are passed for normalization
85 keeping names, and the function is returned for
86 limiting object creation.
87 *)
88 val ty_to_opaty_for_opadoc :
89 val_:(?side:[`client|`server] -> string -> Ident.t) ->
90 gamma:QmlTypes.gamma ->
91 annotmap:QmlAst.annotmap ->
92 (
93 QmlTypeVars.TypeVarPrint.scope ->
94 QmlTypeVars.RowVarPrint.scope ->
95 QmlTypeVars.ColVarPrint.scope ->
96 QmlAst.ty -> QmlAst.expr
97 )
98
99 (** Building representation of type schemes in OPA *)
100
101 (** The type of representation of type schemes. *)
102 val opatsc_type : QmlAst.ty
103
104 (** [tsc_to_opatsc ~side (annotmap, gamma) tsc] represents a type scheme [tsc]
105 in OPA, as OPA expression (of type [QmlAst.expr]). The OPA type of this
106 OPA expression is defined in file "specialisation.opa" as [OpaTsc.t].
107
108 @param side on which side we are
109 @param annotmap the annotmap for, e.g., creating new OPA expressions
110 @param gamma the environment with type definitions
111 @param tsc type scheme to be represented in OPA
112
113 @return Updated annotmap, and an OPA expression that represents
114 [tsc] in OPA.
115 *)
116 val tsc_to_opatsc :
117 side:[ `server | `client ] -> val_:(?side:[`client|`server] -> string -> Ident.t) -> ?memoize:bool ->
118 QmlAst.annotmap * QmlTypes.gamma -> QmlTypes.typescheme
119 -> QmlAst.annotmap * QmlAst.expr
120
121
122 (** Transforming code to enable run-time explicit instantiation *)
123
124 (** [have_typeof ?set gamma annotmap qmlAst] extends [set] with with type
125 variables that are used to compute the results of sll [\@typeof] directives
126 within [qmlAst].
127
128 @param set initial set of variables, empty if not given
129 @param gamma the environment with type definitions
130 @param annotmap the annotmap for, e.g., looking up types of expressions
131 @param qmlAst the syntax tree to scan
132
133 @return Extended set, with all variables meaningful for [\@typeof].
134 *)
135 val have_typeof :
136 QmlTypes.gamma -> QmlAst.annotmap -> QmlAst.code
137 -> QmlTypeVars.FreeVars.t
138
139 (** [process_code have_typeof gamma annotmap _published qmlAst] inserts
140 directives for Explicit Instantiation into the code of [qmlAst].
141
142 @param have_typeof set of type variables to be considered meaningful for [\@typeof]
143 @param gamma the environment with type definitions
144 @param annotmap the annotmap for, e.g., looking up types of expressions
145 @param _published unused; currently [published_ref] is used instead
146 @param qmlAst the syntax tree to transform
147
148 @return Transformed syntax tree, with extra type arguments represented by directives. Also, updated annotmap and environment with changed types for top level definitions.
149 *)
150 val process_code :
151 QmlTypeVars.FreeVars.t
152 -> QmlTypes.gamma -> QmlAst.annotmap -> IdentSet.t -> QmlAst.code
153 -> QmlAst.annotmap * QmlTypes.gamma * QmlAst.code
154
155
156 (**
157 Takes the gamma of the current compilation unit after being modified by process_code
158 and returns the gamma of the standard library after modification by process_code
159 *)
160 val get_stdlib_gamma : QmlTypes.gamma -> QmlTypes.gamma
161
162
163 (** [unprocess_code gamma annotmap qmlAst] eliminates Explicit Instantiation
164 directives in code [qmlAst], replacing them with standard OPA code.
165
166 @param gamma the environment with type and value definitions
167 @param annotmap the annotmap for, e.g., looking up types of expressions
168 @param qmlAst the syntax tree to transform
169
170 @return Updated annotmap and updated code with extra type arguments
171 abstracted and applied using standard OPA code and with [\@typeof]
172 directives implemented using the extra type arguments.
173 *)
174 val unprocess_code :
175 val_:(?side:[`client|`server] -> string -> Ident.t) -> side:[ `server | `client ] ->
176 QmlTypes.gamma -> QmlAst.annotmap -> QmlAst.code
177 -> QmlAst.annotmap * QmlAst.code
178
179
180 (** Inserts code generating type definition environment accessible
181 from within OPA code (for runtime explicit instantiation).
182
183 @param gamma the environment with type definitions
184 @param annotmap the annotmap for creating new OPA expressions
185
186 @return Updated annotmap and code building the OPA representation
187 of the type environment.
188 *)
189 val generate_tsc_map_updates :
190 val_:(?side:[`client|`server] -> string -> Ident.t) -> side:[ `server | `client ] ->
191 ?memoize:bool -> local_typedefs:QmlAst.TypeIdentSet.t -> QmlTypes.gamma -> QmlAst.annotmap
192 -> QmlAst.annotmap * QmlAst.code_elt
Something went wrong with that request. Please try again.