src/Pure/System/session.scala
changeset 46687 7e47ae85e161
parent 46682 4a74fbd6f28b
child 46737 09ab89658a5d
equal deleted inserted replaced
46686:b2ae19322ff8 46687:7e47ae85e161
   260       val (perspective, version) = Thy_Syntax.edit_perspective(previous, name, text_perspective)
   260       val (perspective, version) = Thy_Syntax.edit_perspective(previous, name, text_perspective)
   261 
   261 
   262       val text_edits: List[Document.Edit_Text] =
   262       val text_edits: List[Document.Edit_Text] =
   263         List((name, Document.Node.Perspective(text_perspective)))
   263         List((name, Document.Node.Perspective(text_perspective)))
   264       val change =
   264       val change =
   265         global_state.change_yield(
   265         global_state >>>
   266           _.continue_history(Future.value(previous), text_edits, Future.value(version)))
   266           (_.continue_history(Future.value(previous), text_edits, Future.value(version)))
   267 
   267 
   268       val assignment = global_state().the_assignment(previous).check_finished
   268       val assignment = global_state().the_assignment(previous).check_finished
   269       global_state.change(_.define_version(version, assignment))
   269       global_state >> (_.define_version(version, assignment))
   270       global_state.change_yield(_.assign(version.id))
   270       global_state >>> (_.assign(version.id))
   271 
   271 
   272       prover.get.update_perspective(previous.id, version.id, name, perspective)
   272       prover.get.update_perspective(previous.id, version.id, name, perspective)
   273     }
   273     }
   274 
   274 
   275 
   275 
   284 
   284 
   285       prover.get.cancel_execution()
   285       prover.get.cancel_execution()
   286 
   286 
   287       val text_edits = header_edit(name, header) :: edits.map(edit => (name, edit))
   287       val text_edits = header_edit(name, header) :: edits.map(edit => (name, edit))
   288       val version = Future.promise[Document.Version]
   288       val version = Future.promise[Document.Version]
   289       val change = global_state.change_yield(_.continue_history(previous, text_edits, version))
   289       val change = global_state >>> (_.continue_history(previous, text_edits, version))
   290 
   290 
   291       change_parser ! Text_Edits(syntax, name, previous, text_edits, version)
   291       change_parser ! Text_Edits(syntax, name, previous, text_edits, version)
   292     }
   292     }
   293     //}}}
   293     //}}}
   294 
   294 
   296     /* exec state assignment */
   296     /* exec state assignment */
   297 
   297 
   298     def handle_assign(id: Document.Version_ID, assign: Document.Assign)
   298     def handle_assign(id: Document.Version_ID, assign: Document.Assign)
   299     //{{{
   299     //{{{
   300     {
   300     {
   301       val cmds = global_state.change_yield(_.assign(id, assign))
   301       val cmds = global_state >>> (_.assign(id, assign))
   302       for (cmd <- cmds) delay_commands_changed.invoke(cmd)
   302       for (cmd <- cmds) delay_commands_changed.invoke(cmd)
   303     }
   303     }
   304     //}}}
   304     //}}}
   305 
   305 
   306 
   306 
   307     /* removed versions */
   307     /* removed versions */
   308 
   308 
   309     def handle_removed(removed: List[Document.Version_ID])
   309     def handle_removed(removed: List[Document.Version_ID])
   310     //{{{
   310     //{{{
   311     {
   311     {
   312       global_state.change(_.removed_versions(removed))
   312       global_state >> (_.removed_versions(removed))
   313     }
   313     }
   314     //}}}
   314     //}}}
   315 
   315 
   316 
   316 
   317     /* resulting changes */
   317     /* resulting changes */
   325       val doc_edits = change.doc_edits
   325       val doc_edits = change.doc_edits
   326 
   326 
   327       def id_command(command: Command)
   327       def id_command(command: Command)
   328       {
   328       {
   329         if (!global_state().defined_command(command.id)) {
   329         if (!global_state().defined_command(command.id)) {
   330           global_state.change(_.define_command(command))
   330           global_state >> (_.define_command(command))
   331           prover.get.define_command(command)
   331           prover.get.define_command(command)
   332         }
   332         }
   333       }
   333       }
   334       doc_edits foreach {
   334       doc_edits foreach {
   335         case (_, edit) =>
   335         case (_, edit) =>
   336           edit foreach { case (c1, c2) => c1 foreach id_command; c2 foreach id_command }
   336           edit foreach { case (c1, c2) => c1 foreach id_command; c2 foreach id_command }
   337       }
   337       }
   338 
   338 
   339       val assignment = global_state().the_assignment(previous).check_finished
   339       val assignment = global_state().the_assignment(previous).check_finished
   340       global_state.change(_.define_version(version, assignment))
   340       global_state >> (_.define_version(version, assignment))
   341       prover.get.update(previous.id, version.id, doc_edits)
   341       prover.get.update(previous.id, version.id, doc_edits)
   342     }
   342     }
   343     //}}}
   343     //}}}
   344 
   344 
   345 
   345 
   356 
   356 
   357       result.properties match {
   357       result.properties match {
   358 
   358 
   359         case Position.Id(state_id) if !result.is_raw =>
   359         case Position.Id(state_id) if !result.is_raw =>
   360           try {
   360           try {
   361             val st = global_state.change_yield(_.accumulate(state_id, result.message))
   361             val st = global_state >>> (_.accumulate(state_id, result.message))
   362             delay_commands_changed.invoke(st.command)
   362             delay_commands_changed.invoke(st.command)
   363           }
   363           }
   364           catch {
   364           catch {
   365             case _: Document.State.Fail => bad_result(result)
   365             case _: Document.State.Fail => bad_result(result)
   366           }
   366           }
   372               catch { case _: Document.State.Fail => bad_result(result) }
   372               catch { case _: Document.State.Fail => bad_result(result) }
   373             case _ => bad_result(result)
   373             case _ => bad_result(result)
   374           }
   374           }
   375           // FIXME separate timeout event/message!?
   375           // FIXME separate timeout event/message!?
   376           if (prover.isDefined && System.currentTimeMillis() > prune_next) {
   376           if (prover.isDefined && System.currentTimeMillis() > prune_next) {
   377             val old_versions = global_state.change_yield(_.prune_history(prune_size))
   377             val old_versions = global_state >>> (_.prune_history(prune_size))
   378             if (!old_versions.isEmpty) prover.get.remove_versions(old_versions)
   378             if (!old_versions.isEmpty) prover.get.remove_versions(old_versions)
   379             prune_next = System.currentTimeMillis() + prune_delay.ms
   379             prune_next = System.currentTimeMillis() + prune_delay.ms
   380           }
   380           }
   381 
   381 
   382         case Isabelle_Markup.Removed_Versions if result.is_raw =>
   382         case Isabelle_Markup.Removed_Versions if result.is_raw =>
   439             prover = Some(new Isabelle_Process(timeout, receiver.invoke _, args) with Protocol)
   439             prover = Some(new Isabelle_Process(timeout, receiver.invoke _, args) with Protocol)
   440           }
   440           }
   441 
   441 
   442         case Stop =>
   442         case Stop =>
   443           if (phase == Session.Ready) {
   443           if (phase == Session.Ready) {
   444             global_state.change(_ => Document.State.init)  // FIXME event bus!?
   444             global_state >> (_ => Document.State.init)  // FIXME event bus!?
   445             phase = Session.Shutdown
   445             phase = Session.Shutdown
   446             prover.get.terminate
   446             prover.get.terminate
   447             prover = None
   447             prover = None
   448             phase = Session.Inactive
   448             phase = Session.Inactive
   449           }
   449           }