Skip to content
This repository
tag: v1020
Fetching contributors…

Cannot retrieve contributors at this time

file 213 lines (165 sloc) 5.797 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(**
Register Generator for the BSL.

@author Mathieu Barbin
@author Mehdi Bouaziz
*)

(**
This module implement the lib for building and generating all plugins,
laoder, runtime, etc... from bsl-sources files

See also:
+ {b bslregister} The command line tool version of this lib
+ {b opa-plugin-builder} The installed wrapper
*)

(** {6 Alias for clarty} *)

type filename = string

(** {6 User Interruption} *)

(**
Define a public exception for interrupting the lib.
The command line tool should raise this exception to
kill properly the lib.
*)
exception SigInt

(**
Set the sigint signal to this exception.
Usefull if you want to use this lib from a command line tool.
*)
val set_signal_sigint : unit -> unit

(**
Get back to the signal handler before setting SigInt
Add if needed (not implemented)
*)
val unset_signal_sigint : unit -> unit

(** {6 Warnings} *)
val warning_set : WarningClass.Set.t

(** {6 Registering Sessions} *)

(**
The type of a work in progress register session.
The type is not functionnal because it contains
a marshal plugin session which is not functionnal,
and a private mutable table.

<!> Beware, the table used is [BslLib.BSL].
If needed, it is possible to instanciate an other one,
this is currently not a probleme because the compilers
uses BSL too, but do not call BslRegisterLib at compile time.
[bslregister] is done when we compile the plugins, not
during the compilation of servers.
*)
type session

(** Building a new [session] for registering files *)
val create : options:BslInterface.options -> session

(**
Preprocessing on all languages, the extension tells what to do.
Supported extensions are:
-ml
-js
-jsconf
-opa (deprecated)
*)
val preprocess_file : session -> filename -> session

(** {6 Finalization} *)

(**
The finalized type, ready to be used for generated file production.
*)
type finalized_t

(**
Finalize the session.

build his own bsl, and checks :
- all registers
- js checks
- opa checks
*)
val finalize : session -> finalized_t

(** check *)
val js_validator : finalized_t -> unit

(** {6 Files Production} *)

(**
TODO: rewrite using ASTs (not so easy, lot of static code...)
maybe a mix would be better.
*)

type 'a output = out_channel -> 'a -> unit

type iterator = {
  output : 'a. filename -> (out_channel -> 'a -> unit) -> 'a -> unit
}

type 'a output_iterator = iterator -> 'a -> unit

(**
JS runtime.
This is the concatenation of all the js code.

It is principally used for debugging, and having a trace
of the resulting code.

The code is spliten, and is in the plugin file by file.
Opa compiler use plugins to get back the js code.
*)
val out_js_code : finalized_t output_iterator

(**
ML loader and plugin.

This is almost the same file, but the loader contains more than the plugin,
it contains also dynamic function pointer for passing it to the interpreter,
so that its key resolution give him back a function which it can apply.

We use 2 separated files, because since the loader contains functions pointer,
it depends on the runtime, whereas the compiler does not.
If the plugin depends also on the runtime, it wont be possible to dynlink
a plugin from the compiler.

So, functions are [Obj.t option]
+ in the loader : [Some (Obj.repr myfunction)]
+ in the plugin : [None]

cf [BslPluginInterface]

ML Runtime and Runtime header

This is the concatenation of all the implementation code.
The mli is generated from the [##register] directives, so
that in this way we can check that the implementation has
really the type that the implementer pretend in its register.

JS keys

This is a file containing all the key resolution in JS, so that
we can use the checker for knowing statically if a resolution leads
to an unbound value.
*)
(** *)
val out_js_keys : finalized_t output
val out_ml_loader : finalized_t output
val out_ml_plugin : finalized_t output
val out_ml_runtime : finalized_t output
val out_ml_runtime_mli : finalized_t output

(**
Marshal plugin.
To avoid recompilation and dynamic loading, the infos from a plugin
can also be marshalled.
Our applications are supporting both mode, dynlink plugin and marshalled.
*)
val out_ml_marshal_plugin : finalized_t output

(**
Opa code after pre-processing.
Directives [##include] and [##include-type] have been solved.
The code is also in the loader, and plugin.
*)
val out_opa_code : finalized_t output_iterator

(**
Opa inferred types.

Once preprocessed, opa files are regrouped and typed.
For each opa file, an typed interface can be produced
somewhere.
*)
val out_opa_interface : finalized_t output_iterator


(*
(** {6 More export for sharing / debuging} *)

(**
Used by browser for debuging
*)
val string_of_bypass_directive :
lang:BslLanguage.t ->
type_path_map:BslLib.typesmap ->
current_path:(string list) ->
directive_tags * bypasslang_directive -> (string * string)
*)
Something went wrong with that request. Please try again.