Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 191 lines (151 sloc) 4.726 kB
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
4 This file is part of Opa.
fccc685 Initial open-source release
MLstate authored
5
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
6 Opa is free software: you can redistribute it and/or modify it under the
fccc685 Initial open-source release
MLstate authored
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
10 Opa is distributed in the hope that it will be useful, but WITHOUT ANY
fccc685 Initial open-source release
MLstate authored
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
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
16 along with Opa. If not, see <http://www.gnu.org/licenses/>.
fccc685 Initial open-source release
MLstate authored
17 *)
18
19 (**
20 OpaTop runtime values : algebra and utils.
21 @author Mathieu Barbin
22 *)
23
24 (** {6 Refactoring WIP} *)
25
26 (**
27 TODO : Ident and IdentMap are 2 toplevel module
28 in compilerlib.
29 *)
30
31 (** {6 Type alias} *)
32
33 type pos = FilePos.pos
34 type 'a pprinter = 'a LangPrint.pprinter
35
36 (** {6 Runtime Value Algebra} *)
37
38 (**
39 Value algebra.
40
41 We use Lazy.t all the time for conciseness, it will always be
42 already evaluated for non-lazy records. The [t option] is only
43 used for lazy DB records.
44
45 Note about the value albebra:
46 opatop is not targetting performance. We have already some back-end
47 for that. The goal is to have as much tracability as possible,
48 for debbuging the all framework.
49
50 StringMap and IdentMap are used for having a typer off mode.
51 Positions are used to test errors reporting features.
52 *)
53 type t =
54 | V_const of pos * QmlAst.const_expr
55 | V_record of pos * (t Lazy.t) StringMap.t * t option ref
56 | V_closure of pos * (t IdentMap.t) ref * QmlAst.expr
57 | V_extern of pos * string * BslTypes.t list * Obj.t
58 | V_bypass of pos * BslTypes.t list * BslTypes.t * Obj.t
59
60
61 (** {6 GUIDELINES for matching a [t]} *)
62 (**
63 Verbose :
64 {[
65 | V_const (pos, const)
66 | V_record (pos, fields, info)
67 | V_closure (pos, env_val, env_type, expr)
68 | V_extern (pos, name, params, obj)
69 | V_bypass (pos, ByFun (arg, ret, obj))
70 ]}
71
72 Shorter :
73 {[
74 | V_const (p, c)
75 | V_record (p, fds, i)
76 | V_closure (p, ev, et, e)
77 | V_extern (p, n, pms, o)
78 | V_bypass (p, ByFun (arg, ret, o))
79 ]}
80 *)
81
82 (** {6 Positions} *)
83 (**
84 This module follows the guidelines for error reporting :
85 + It uses [OManager] for printing localized error messages.
86 *)
87 (** *)
88 val pos : t -> pos
89 val reset_pos : t -> pos -> t
90 val merge_pos : t -> pos -> t
91
92 (**
93 A default pos for [Value.t]
94 *)
95 val nopos : pos
96
97 (** {6 Printing} *)
98
99 (**
100 Printer for values.
101 You can add a type for hidding some structural informations.
102 Since fields are lazy, you can force or not the evaluation before
103 printing.
104 Default :
105 - [ty=None] No type, the printer is purelly structural.
106 - [force=false] Does not force, will print just ["<lazy>"] in that case.
107 *)
108 val pp_value :
109 ?ty:QmlAst.ty ->
110 ?force:bool ->
111 t pprinter
112
113 (**
114 The default printer [pp_value] with default options
115 - [ty] is [None]
116 - [force] is [false]
117
118 Exposed in the interface so that we have a pp following the interface
119 of pp printers, as requested by the guidelines.
120 *)
121 val pp : t pprinter
122
123 (**
124 Print the type of a value. This is semi structural.
125 *)
126 val pp_type : t pprinter
127
128 (** {6 Comparaison} *)
129
130 (**
131 Runtime structural comparaison on values.
132 TODO: option strong ==> clarify this, maybe remove or rename.
133 *)
134 val compare : ?strong:bool -> t -> t -> int
135
136 (**
137 A dummy value, use it e.g. when eval is off.
138 This is a extern value, equal to an Ocaml int [0].
139 *)
140 val t_null : ?pos:pos -> unit -> t
141
142 (** {6 Value Environment} *)
143
144 type env = t IdentMap.t
145
146 (** {6 Projections} *)
147
148 (**
149 This implements the projection to Ocaml standard runtime values,
150 for using external primitives from BSL libs. (bypass plugins)
151 *)
152 module Proj :
153 sig
154 (** {6 BSL Types} *)
155
156 val shared_void : t
157
158 val t_int : ?pos:pos -> int -> t
159 val t_float : ?pos:pos -> float -> t
160 val t_string : ?pos:pos -> string -> t
161 val t_int64 : ?pos:pos -> Int64.t -> t
162
163 val t_void : ?pos:pos -> unit -> t
164
165 val t_true : ?pos:pos -> unit -> t
166 val t_false : ?pos:pos -> unit -> t
167 val t_bool : ?pos:pos -> bool -> t
168
169 val t_none : ?pos:pos -> unit -> t
170 val t_some : ?pos:pos -> t -> t
171 val t_option : ?pos:pos -> t option -> t
172
173 val t_extern : ?pos:pos -> string -> BslTypes.t list -> 'a -> t
174
175 (** {6 Projection} *)
176 (**
177 Building an Ocaml ['a] from a [Value.t].
178 The [eval] function is passed for projecting closure into ml-functions.
179 *)
180 val ocaml_of_t :
181 eval:(env -> QmlAst.expr -> t) ->
182 BslTypes.t ->
183 t -> 'ocaml_value
184
185 (**
186 The projection in the other way.
187 *)
188 val t_of_ocaml :
189 BslTypes.t -> 'ocaml_value -> t
190 end
Something went wrong with that request. Please try again.