11 {html_symbols: (string * int) list, |
11 {html_symbols: (string * int) list, |
12 session_positions: (string * Properties.T) list, |
12 session_positions: (string * Properties.T) list, |
13 session_directories: (string * string) list, |
13 session_directories: (string * string) list, |
14 session_chapters: (string * string) list, |
14 session_chapters: (string * string) list, |
15 bibtex_entries: (string * string list) list, |
15 bibtex_entries: (string * string list) list, |
|
16 command_timings: Properties.T list, |
16 docs: string list, |
17 docs: string list, |
17 global_theories: (string * string) list, |
18 global_theories: (string * string) list, |
18 loaded_theories: string list} -> unit |
19 loaded_theories: string list} -> unit |
19 val init_session_yxml: string -> unit |
20 val init_session_yxml: string -> unit |
20 val init_session_file: Path.T -> unit |
21 val init_session_file: Path.T -> unit |
48 end; |
50 end; |
49 |
51 |
50 structure Resources: RESOURCES = |
52 structure Resources: RESOURCES = |
51 struct |
53 struct |
52 |
54 |
|
55 (* command timings *) |
|
56 |
|
57 type timings = ((string * Time.time) Inttab.table) Symtab.table; (*file -> offset -> name, time*) |
|
58 |
|
59 val empty_timings: timings = Symtab.empty; |
|
60 |
|
61 fun update_timings props = |
|
62 (case Markup.parse_command_timing_properties props of |
|
63 SOME ({file, offset, name}, time) => |
|
64 Symtab.map_default (file, Inttab.empty) |
|
65 (Inttab.map_default (offset, (name, time)) (fn (_, t) => (name, t + time))) |
|
66 | NONE => I); |
|
67 |
|
68 fun make_timings command_timings = |
|
69 fold update_timings command_timings empty_timings; |
|
70 |
|
71 fun approximative_id name pos = |
|
72 (case (Position.file_of pos, Position.offset_of pos) of |
|
73 (SOME file, SOME offset) => |
|
74 if name = "" then NONE else SOME {file = file, offset = offset, name = name} |
|
75 | _ => NONE); |
|
76 |
|
77 fun get_timings timings tr = |
|
78 (case approximative_id (Toplevel.name_of tr) (Toplevel.pos_of tr) of |
|
79 SOME {file, offset, name} => |
|
80 (case Symtab.lookup timings file of |
|
81 SOME offsets => |
|
82 (case Inttab.lookup offsets offset of |
|
83 SOME (name', time) => if name = name' then SOME time else NONE |
|
84 | NONE => NONE) |
|
85 | NONE => NONE) |
|
86 | NONE => NONE) |
|
87 |> the_default Time.zeroTime; |
|
88 |
|
89 |
53 (* session base *) |
90 (* session base *) |
54 |
91 |
55 val default_qualifier = "Draft"; |
92 val default_qualifier = "Draft"; |
56 |
93 |
57 type entry = {pos: Position.T, serial: serial}; |
94 type entry = {pos: Position.T, serial: serial}; |
63 {html_symbols = HTML.no_symbols, |
100 {html_symbols = HTML.no_symbols, |
64 session_positions = []: (string * entry) list, |
101 session_positions = []: (string * entry) list, |
65 session_directories = Symtab.empty: Path.T list Symtab.table, |
102 session_directories = Symtab.empty: Path.T list Symtab.table, |
66 session_chapters = Symtab.empty: string Symtab.table, |
103 session_chapters = Symtab.empty: string Symtab.table, |
67 bibtex_entries = Symtab.empty: string list Symtab.table, |
104 bibtex_entries = Symtab.empty: string list Symtab.table, |
|
105 timings = empty_timings, |
68 docs = []: (string * entry) list, |
106 docs = []: (string * entry) list, |
69 global_theories = Symtab.empty: string Symtab.table, |
107 global_theories = Symtab.empty: string Symtab.table, |
70 loaded_theories = Symtab.empty: unit Symtab.table}; |
108 loaded_theories = Symtab.empty: unit Symtab.table}; |
71 |
109 |
72 val global_session_base = |
110 val global_session_base = |
73 Synchronized.var "Sessions.base" empty_session_base; |
111 Synchronized.var "Sessions.base" empty_session_base; |
74 |
112 |
75 fun init_session |
113 fun init_session |
76 {html_symbols, session_positions, session_directories, session_chapters, |
114 {html_symbols, session_positions, session_directories, session_chapters, |
77 bibtex_entries, docs, global_theories, loaded_theories} = |
115 bibtex_entries, command_timings, docs, global_theories, loaded_theories} = |
78 Synchronized.change global_session_base |
116 Synchronized.change global_session_base |
79 (fn _ => |
117 (fn _ => |
80 {html_symbols = HTML.make_symbols html_symbols, |
118 {html_symbols = HTML.make_symbols html_symbols, |
81 session_positions = sort_by #1 (map (apsnd make_entry) session_positions), |
119 session_positions = sort_by #1 (map (apsnd make_entry) session_positions), |
82 session_directories = |
120 session_directories = |
83 fold_rev (fn (dir, name) => Symtab.cons_list (name, Path.explode dir)) |
121 fold_rev (fn (dir, name) => Symtab.cons_list (name, Path.explode dir)) |
84 session_directories Symtab.empty, |
122 session_directories Symtab.empty, |
85 session_chapters = Symtab.make session_chapters, |
123 session_chapters = Symtab.make session_chapters, |
86 bibtex_entries = Symtab.make bibtex_entries, |
124 bibtex_entries = Symtab.make bibtex_entries, |
|
125 timings = make_timings command_timings, |
87 docs = sort_by #1 (map (apsnd make_entry o rpair []) docs), |
126 docs = sort_by #1 (map (apsnd make_entry o rpair []) docs), |
88 global_theories = Symtab.make global_theories, |
127 global_theories = Symtab.make global_theories, |
89 loaded_theories = Symtab.make_set loaded_theories}); |
128 loaded_theories = Symtab.make_set loaded_theories}); |
90 |
129 |
91 fun init_session_yxml yxml = |
130 fun init_session_yxml yxml = |
92 let |
131 let |
93 val (html_symbols, (session_positions, (session_directories, (session_chapters, |
132 val (html_symbols, (session_positions, (session_directories, (session_chapters, |
94 (bibtex_entries, (docs, (global_theories, loaded_theories))))))) = |
133 (bibtex_entries, (command_timings, (docs, (global_theories, loaded_theories)))))))) = |
95 YXML.parse_body yxml |> |
134 YXML.parse_body yxml |> |
96 let open XML.Decode in |
135 let open XML.Decode in |
97 pair (list (pair string int)) (pair (list (pair string properties)) |
136 pair (list (pair string int)) |
98 (pair (list (pair string string)) (pair (list (pair string string)) |
137 (pair (list (pair string properties)) |
99 (pair (list (pair string (list string))) (pair (list string) |
138 (pair (list (pair string string)) (pair (list (pair string string)) |
100 (pair (list (pair string string)) (list string))))))) |
139 (pair (list (pair string (list string))) (pair (list properties) |
|
140 (pair (list string) (pair (list (pair string string)) (list string)))))))) |
101 end; |
141 end; |
102 in |
142 in |
103 init_session |
143 init_session |
104 {html_symbols = html_symbols, |
144 {html_symbols = html_symbols, |
105 session_positions = session_positions, |
145 session_positions = session_positions, |
106 session_directories = session_directories, |
146 session_directories = session_directories, |
107 session_chapters = session_chapters, |
147 session_chapters = session_chapters, |
108 bibtex_entries = bibtex_entries, |
148 bibtex_entries = bibtex_entries, |
|
149 command_timings = command_timings, |
109 docs = docs, |
150 docs = docs, |
110 global_theories = global_theories, |
151 global_theories = global_theories, |
111 loaded_theories = loaded_theories} |
152 loaded_theories = loaded_theories} |
112 end; |
153 end; |
113 |
154 |