src/Pure/PIDE/document.ML
changeset 62895 54c2abe7e9a4
parent 62826 eb94e570c1a4
child 62932 db12de2367ca
equal deleted inserted replaced
62894:047129a6e200 62895:54c2abe7e9a4
   207 
   207 
   208 fun the_entry node id =
   208 fun the_entry node id =
   209   (case Entries.lookup (get_entries node) id of
   209   (case Entries.lookup (get_entries node) id of
   210     NONE => err_undef "command entry" id
   210     NONE => err_undef "command entry" id
   211   | SOME (exec, _) => exec);
   211   | SOME (exec, _) => exec);
   212 
       
   213 fun the_default_entry node (SOME id) = (id, the_default Command.no_exec (the_entry node id))
       
   214   | the_default_entry _ NONE = (Document_ID.none, Command.no_exec);
       
   215 
   212 
   216 fun assign_entry (command_id, exec) node =
   213 fun assign_entry (command_id, exec) node =
   217   if is_none (Entries.lookup (get_entries node) command_id) then node
   214   if is_none (Entries.lookup (get_entries node) command_id) then node
   218   else map_entries (Entries.update (command_id, exec)) node;
   215   else map_entries (Entries.update (command_id, exec)) node;
   219 
   216 
   545 
   542 
   546     val parents =
   543     val parents =
   547       if null parents_reports then [Thy_Info.pure_theory ()] else map #1 parents_reports;
   544       if null parents_reports then [Thy_Info.pure_theory ()] else map #1 parents_reports;
   548     val _ = Position.reports (map #2 parents_reports);
   545     val _ = Position.reports (map #2 parents_reports);
   549   in Resources.begin_theory master_dir header parents end;
   546   in Resources.begin_theory master_dir header parents end;
       
   547 
       
   548 fun check_ml_root node =
       
   549   if #1 (#name (#header (get_header node))) = Thy_Header.ml_rootN then
       
   550     let
       
   551       val master_dir = master_directory node;
       
   552       val header = #header (get_header node);
       
   553       val parent = Thy_Info.get_theory Thy_Header.ml_bootstrapN;
       
   554     in SOME (Resources.begin_theory master_dir header [parent]) end
       
   555   else NONE;
   550 
   556 
   551 fun check_theory full name node =
   557 fun check_theory full name node =
   552   is_some (loaded_theory name) orelse
   558   is_some (loaded_theory name) orelse
   553   null (#errors (get_header node)) andalso (not full orelse is_some (get_result node));
   559   null (#errors (get_header node)) andalso (not full orelse is_some (get_result node));
   554 
   560 
   597         let val last = Entries.get_after (get_entries node) common
   603         let val last = Entries.get_after (get_entries node) common
   598         in (last, update_flags last flags) end
   604         in (last, update_flags last flags) end
   599       else (common, flags);
   605       else (common, flags);
   600   in (assign_update', common', flags') end;
   606   in (assign_update', common', flags') end;
   601 
   607 
   602 fun illegal_init _ = error "Illegal theory header after end of theory";
   608 fun illegal_init _ = error "Illegal theory header";
   603 
   609 
   604 fun new_exec keywords state node proper_init command_id' (assign_update, command_exec, init) =
   610 fun new_exec keywords state node proper_init command_id' (assign_update, command_exec, init) =
   605   if not proper_init andalso is_none init then NONE
   611   if not proper_init andalso is_none init then NONE
   606   else
   612   else
   607     let
   613     let
   649               deps = map (Future.task_of o #2) deps, pri = 1, interrupts = false}
   655               deps = map (Future.task_of o #2) deps, pri = 1, interrupts = false}
   650             (fn () =>
   656             (fn () =>
   651               timeit ("Document.update " ^ name) (fn () =>
   657               timeit ("Document.update " ^ name) (fn () =>
   652                 Runtime.exn_trace_system (fn () =>
   658                 Runtime.exn_trace_system (fn () =>
   653                   let
   659                   let
       
   660                     val ml_root = check_ml_root node;
   654                     val keywords = the_default (Session.get_keywords ()) (get_keywords node);
   661                     val keywords = the_default (Session.get_keywords ()) (get_keywords node);
   655                     val imports = map (apsnd Future.join) deps;
   662                     val imports = map (apsnd Future.join) deps;
   656                     val imports_result_changed = exists (#4 o #1 o #2) imports;
   663                     val imports_result_changed = exists (#4 o #1 o #2) imports;
   657                     val node_required = Symtab.defined required name;
   664                     val node_required = Symtab.defined required name;
   658                   in
   665                   in
   661                     then
   668                     then
   662                       let
   669                       let
   663                         val node0 = node_of old_version name;
   670                         val node0 = node_of old_version name;
   664                         val init = init_theory imports node;
   671                         val init = init_theory imports node;
   665                         val proper_init =
   672                         val proper_init =
   666                           check_theory false name node andalso
   673                           is_some ml_root orelse
   667                           forall (fn (name, (_, node)) => check_theory true name node) imports;
   674                             check_theory false name node andalso
       
   675                             forall (fn (name, (_, node)) => check_theory true name node) imports;
   668 
   676 
   669                         val (print_execs, common, (still_visible, initial)) =
   677                         val (print_execs, common, (still_visible, initial)) =
   670                           if imports_result_changed then (assign_update_empty, NONE, (true, true))
   678                           if imports_result_changed then (assign_update_empty, NONE, (true, true))
   671                           else last_common keywords state node_required node0 node;
   679                           else last_common keywords state node_required node0 node;
   672                         val common_command_exec = the_default_entry node common;
   680 
       
   681                         val common_command_exec =
       
   682                           (case common of
       
   683                             SOME id => (id, the_default Command.no_exec (the_entry node id))
       
   684                           | NONE => (Document_ID.none, Command.init_exec ml_root));
   673 
   685 
   674                         val (updated_execs, (command_id', (eval', _)), _) =
   686                         val (updated_execs, (command_id', (eval', _)), _) =
   675                           (print_execs, common_command_exec, if initial then SOME init else NONE)
   687                           (print_execs, common_command_exec, if initial then SOME init else NONE)
   676                           |> (still_visible orelse node_required) ?
   688                           |> (still_visible orelse node_required) ?
   677                             iterate_entries_after common
   689                             iterate_entries_after common
   725 
   737 
   726 fun state () = Synchronized.value global_state;
   738 fun state () = Synchronized.value global_state;
   727 val change_state = Synchronized.change global_state;
   739 val change_state = Synchronized.change global_state;
   728 
   740 
   729 end;
   741 end;
   730