Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 132 lines (104 sloc) 3.616 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 Module for macro generating bsl types coercions and definitions.
21
22 @author Mathieu Barbin
23 *)
24
25 (**
26 This module implements the traduction of bsl-types into the back-end languages.
27 It has also a module dedicated to Opa syntax for bsl-preprocessing (cf [iformats]).
28
29 TODO:
30 Currently, we output code only as concrete syntax (Ocaml, Js).
31 It is really usefull to have dedicated printers for BslTypes,
32 because we can make some specific control for external primitives
33 printing and error messages,
34 but for code generation, it would be better to pass through an
35 AST generation.
36 Some (sunny) day we will add an implemention for AST production.
37
38 + when OcamlAst will be more stable.
39 + when JsAst will be more stable.
40 + when we will decide what we do with LLVM, and have a AST for extern C bindings.
41
42 *)
43
44 (** *)
45 type 'a pprinter = 'a LangPrint.pprinter
46 type ('env, 'a, 'ast) generator = 'env -> 'a -> 'env * 'ast
47
48 module Opa :
49 sig
50 (**
51 Printer for [t] with the opa syntax
52 *)
53 val pp : BslTypes.t pprinter
54
55 (**
56 Used for declarating a new external type
57 {[
58 type toto('a, 'b) = external
59 ]}
60 Assert: This function is called with an [External] type, with [TypeVar] for all parameters
61 @error if [t] is not a candidate for definition (outside of this case)
62 *)
63 val pp_definition : BslTypes.t pprinter
64 end
65
66 module Ocaml :
67 sig
68 (** TODO: add link for ocaml path manager *)
69
70 (**
71 Printer for [t] with the ocaml syntax.
72
73 This function is the kernel of the type checking done
74 on the [MLRuntime], because it produces types coercions
75 from the types read in the register directives.
76
77 cf: BslServerLib.S
78
79 The scope of type variables is fresh for every call to pp.
80 *)
81 val pp : BslTypes.t pprinter
82
83 (**
84 For External types, the implementation is hidden, it is a ocaml row code.
85 {[
86 ##extern-type ('a, 'b) toto = Ka of 'a | Kb of 'b
87 ]}
88 will produce
89 + in the ml:
90 {[
91 type ('a, 'b) toto = Ka of 'a | Kb of 'b
92 ]}
93 + in the mli:
94 {[
95 type ('a, 'b) toto
96 ]}
97 + in opa:
98 {[
99 type toto('a, 'b) = external
100 ]}
101
102 Assert: This function is called with an exteranl types, with only [TypeVars] for parameters
103
104 @error if [t] is not a candidate for definition (outside of this case)
105 *)
106 val pp_definition : BslTypes.t pprinter
107 end
108
109 module C :
110 sig
111 (**
112 At some we did some tests for targetting llvm.
113 This is currently unused, and unmaintain, and this is
114 probably no more corresponding to anything we will keep.
115
116 This is partially not implemented and not supported by
117 any back-end.
118
119 @deprecated Wait for LLVM backend.
120 *)
121
122 (**
123 Printer for [t] with the C syntax.
124
125 <!> It outputs type name and macro which are define in
126 the pervasives of the C (["opabsl/cbsl"]). You cannot use
127 it without the C init library.
128 *)
129 val pp : BslTypes.t pprinter
130
131 end
Something went wrong with that request. Please try again.