Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 80 lines (68 sloc) 2.772 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 module SA = SurfaceAst
19 module C = SurfaceAstCons.ExprIdentCons
20 module O = OpaEnv
21
22 let infos_ident =
23 [
24
25 "cps_client_mode", (fun options -> C.E.bool options.O.cps_client);
26
27 "release", (fun options -> C.E.bool options.O.compile_release);
28 "opa_filenames", (fun options -> C.E.list
29 (List.map C.E.string options.O.filenames));
30
f3fef85 [cleanup] fixme: remove some of them
Mathieu Barbin authored
31 (* transformed into a [Date.date] using [int2time] *)
fccc685 Initial open-source release
MLstate authored
32 "compilation_date", (fun _ -> C.E.int (Time.in_milliseconds (
33 #<If:DIFFING>
34 Time.zero
35 #<Else>
36 Time.now ()
37 #<End>
38 ))
39 );
40
41 "opa_git_version", (fun _ -> C.E.int BuildInfos.opalang_git_version);
42 "opa_git_version_hash", (fun _ -> C.E.string BuildInfos.opalang_git_sha);
43 "opa_date", (fun _ -> C.E.string BuildInfos.date);
44 "opa_is_release", (fun _ -> C.E.bool BuildInfos.is_release);
45 ]
46
47 let infos_ident_names =
48 List.map fst infos_ident
49
50 let process_code ~options code =
51 let idents = Hashtbl.create 1 in
52 let lookup annot key =
53 try Hashtbl.find idents key
54 with Not_found -> (
55 let ident = SurfaceAstCons.ExprIdent.ns_fresh ~label:annot key in
56 if List.mem key infos_ident_names then
57 Hashtbl.add idents key ident
58 else (
59 let context = OpaError.Context.annot annot in
60 OpaError.serror context
61 "The compile time key %s doesn't exists.@\n%a"
62 key
63 (HintUtils.pp_suggestion infos_ident_names) key
64 );
65 ident
66 ) in
67 let def key ident =
68 let value = (List.assoc key infos_ident) options in
69 C.C.newval ident value in
70 let code =
71 OpaWalk.Code.map_up
72 (function
73 | (SA.Directive (`compiletime s, [], []),annot) -> (SA.Ident (lookup annot s), annot)
74 | (SA.Directive (`compiletime _, _, _),_) -> assert false
75 | e -> e) code in
76 SurfaceAstCons.with_builtin_position
77 (fun () ->
78 Hashtbl.fold (fun key ident code -> def key ident :: code) idents code
79 )
Something went wrong with that request. Please try again.