forked from HaxeFoundation/haxe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.ml
executable file
·80 lines (68 loc) · 1.92 KB
/
plugin.ml
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
(*
* Haxe Compiler
* Copyright (c)2005 Nicolas Cannasse
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)
let verbose = ref false
let class_path = ref ([] : string list)
let defines = ref (PMap.add "true" () PMap.empty)
let defined v = PMap.mem v (!defines)
let define v = defines := PMap.add v () (!defines)
let get_full_path = ref (fun (s:string) -> s)
let find_file f =
let rec loop = function
| [] -> raise Not_found
| p :: l ->
let file = p ^ f in
if Sys.file_exists file then
file
else
loop l
in
loop !class_path
type timer_infos = {
name : string;
mutable start : float;
mutable total : float;
}
let times = ref true
let get_time = Unix.gettimeofday
let htimers = Hashtbl.create 0
let new_timer name =
try
let t = Hashtbl.find htimers name in
t.start <- get_time();
t
with Not_found ->
let t = { name = name; start = get_time(); total = 0.; } in
Hashtbl.add htimers name t;
t
let curtime = ref None
let timer name =
if not !times then
(function() -> ())
else
let t = new_timer name in
let old = !curtime in
curtime := Some t;
(function() ->
let dt = get_time() -. t.start in
t.total <- t.total +. dt;
curtime := old;
match !curtime with
| None -> ()
| Some ct -> ct.start <- ct.start +. dt
)