Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 99 lines (79 sloc) 3.323 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 OpaTop Bypass Management, binding with libbsl.
21 @author Mathieu Barbin
22 *)
23
24 (**
25 Unlike compilers which uses plugins containing only essentially
26 string like informations about primitives (like the function name,
27 it's type, etc...), the interpreter needs to access a dynamic pointer
28 on the implementation of the function.
29
30 This is possible with libbsl, that is what {b loaders} are for.
31 Loaders contain the same informations then the Plugins, but with
32 an extra [Obj.t] : the implementation of the primitive.
33
34 In the opatop main, we first store all linked loaders in the
35 common [BslPluginTable], using explicitelly their function
36 [self_store], so that we are sure that they are linked with
37 the executable.
38
39 After that we execute the main loop of the interpreter,
40 which begins with an initial building of the starting environment.
41 At this point, this module is requested to build the bymap,
42 which correspond to registering and exporting all primitives from
43 the loaders stored into the [BslPluginTable].
44 *)
45
46 (**
47 The manipulation of bypasses has been simplified, and opatop
48 use the standard bsl, [BslLib.BSL].
49 *)
50
51 type bypass_map = BslLib.BSL.ByPassMap.t
52 type bypass = BslLib.BSL.ByPass.t
53
54 (**
55 Building the bymap from the contents of the [BslPluginTable].
56 Do not call this function <<too soon>>, or the map will be empty.
57 - [too soon] means before the linked loaders may have time to
58 store them self in the [BslPluginTable].
59
60 In practice, whenever we need to build a new toplevel, we generate
61 a main which look like :
62 {[
63 let _ =
64 Loader1.self_store () ;
65 Loader2.self_store () ;
66 start_main_of_opatop ()
67 ]}
68
69 There is a cache for the built bypass_map, so that you can call this
70 function whenever you need to access the bypass_map.
71 *)
72 val bypass_map : unit -> bypass_map
73
74 (**
75 Once the map has been build, we can ask for a bypass key to be resolved.
76 If the bypass is unknown, the function returns [None], the evaluation
77 can fail with a context error.
78 *)
79 val find_opt : BslKey.t -> bypass_map -> bypass option
80
81 (**
82 For the typer, get the type of the bypass.
83 *)
84 val bypass_typer : bypass_map -> QmlTypes.bypass_typer
85
86 (**
87 For the evaluator, this module is able to create directly
88 a value of type [Value.t].
89
90 The option is used because some bypass are defined,
91 but do not have an implementation in ml available
92 in the interpreter.
93
94 In case this function returns [None], the eval loop
95 can fail with a context error, telling that there is
96 no available implementation of the bypass for opatop.
97 *)
98 val eval : bypass -> OpaTopValue.t option
Something went wrong with that request. Please try again.