equal
deleted
inserted
replaced
155 (** global state -- document structure and execution process **) |
155 (** global state -- document structure and execution process **) |
156 |
156 |
157 abstype state = State of |
157 abstype state = State of |
158 {versions: version Inttab.table, (*version_id -> document content*) |
158 {versions: version Inttab.table, (*version_id -> document content*) |
159 commands: Toplevel.transition future Inttab.table, (*command_id -> transition (future parsing)*) |
159 commands: Toplevel.transition future Inttab.table, (*command_id -> transition (future parsing)*) |
160 execs: (bool * Toplevel.state) lazy Inttab.table, (*exec_id -> execution process*) |
160 execs: Toplevel.state lazy Inttab.table, (*exec_id -> execution process*) |
161 execution: unit future list} (*global execution process*) |
161 execution: unit future list} (*global execution process*) |
162 with |
162 with |
163 |
163 |
164 fun make_state (versions, commands, execs, execution) = |
164 fun make_state (versions, commands, execs, execution) = |
165 State {versions = versions, commands = commands, execs = execs, execution = execution}; |
165 State {versions = versions, commands = commands, execs = execs, execution = execution}; |
168 make_state (f (versions, commands, execs, execution)); |
168 make_state (f (versions, commands, execs, execution)); |
169 |
169 |
170 val init_state = |
170 val init_state = |
171 make_state (Inttab.make [(no_id, empty_version)], |
171 make_state (Inttab.make [(no_id, empty_version)], |
172 Inttab.make [(no_id, Future.value Toplevel.empty)], |
172 Inttab.make [(no_id, Future.value Toplevel.empty)], |
173 Inttab.make [(no_id, Lazy.value (true, Toplevel.toplevel))], |
173 Inttab.make [(no_id, Lazy.value Toplevel.toplevel)], |
174 []); |
174 []); |
175 |
175 |
176 |
176 |
177 (* document versions *) |
177 (* document versions *) |
178 |
178 |
227 fun get_theory state version_id pos name = |
227 fun get_theory state version_id pos name = |
228 let |
228 let |
229 val last = get_last (node_of (the_version state version_id) name); |
229 val last = get_last (node_of (the_version state version_id) name); |
230 val st = |
230 val st = |
231 (case Lazy.peek (the_exec state last) of |
231 (case Lazy.peek (the_exec state last) of |
232 SOME result => #2 (Exn.release result) |
232 SOME result => Exn.release result |
233 | NONE => error ("Unfinished execution for theory " ^ quote name ^ Position.str_of pos)); |
233 | NONE => error ("Unfinished execution for theory " ^ quote name ^ Position.str_of pos)); |
234 in Toplevel.end_theory pos st end; |
234 in Toplevel.end_theory pos st end; |
235 |
235 |
236 |
236 |
237 (* document execution *) |
237 (* document execution *) |
298 else run (is_init orelse is_proof) (Toplevel.set_print false tr) st; |
298 else run (is_init orelse is_proof) (Toplevel.set_print false tr) st; |
299 val _ = timing tr (Timing.result start); |
299 val _ = timing tr (Timing.result start); |
300 val _ = List.app (Toplevel.error_msg tr) errs; |
300 val _ = List.app (Toplevel.error_msg tr) errs; |
301 in |
301 in |
302 (case result of |
302 (case result of |
303 NONE => (Toplevel.status tr Markup.failed; (false, st)) |
303 NONE => (Toplevel.status tr Markup.failed; st) |
304 | SOME st' => |
304 | SOME st' => |
305 (Toplevel.status tr Markup.finished; |
305 (Toplevel.status tr Markup.finished; |
306 proof_status tr st'; |
306 proof_status tr st'; |
307 if do_print then async_state tr st' else (); |
307 if do_print then async_state tr st' else (); |
308 (true, st'))) |
308 st')) |
309 end; |
309 end; |
310 |
310 |
311 end; |
311 end; |
312 |
312 |
313 |
313 |
330 val exec_id' = new_id (); |
330 val exec_id' = new_id (); |
331 val future_tr = the_command state id; |
331 val future_tr = the_command state id; |
332 val exec' = |
332 val exec' = |
333 Lazy.lazy (fn () => |
333 Lazy.lazy (fn () => |
334 let |
334 let |
335 val st = #2 (Lazy.force exec); |
335 val st = Lazy.force exec; |
336 val exec_tr = Toplevel.put_id (print_id exec_id') (Future.join future_tr); |
336 val exec_tr = Toplevel.put_id (print_id exec_id') (Future.join future_tr); |
337 in run_command node_info exec_tr st end); |
337 in run_command node_info exec_tr st end); |
338 val state' = define_exec exec_id' exec' state; |
338 val state' = define_exec exec_id' exec' state; |
339 in (exec_id', (id, exec_id') :: updates, state') end; |
339 in (exec_id', (id, exec_id') :: updates, state') end; |
340 |
340 |