src/Pure/System/session.scala
author wenzelm
Sun, 03 Jul 2011 19:53:35 +0200
changeset 43649 a912f0b02359
parent 43648 e32de528b5ef
child 43651 511df47bcadc
permissions -rw-r--r--
eliminated null;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36676
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     1
/*  Title:      Pure/System/session.scala
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     2
    Author:     Makarius
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
     3
    Options:    :folding=explicit:collapseFolds=1:
36676
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     4
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     5
Isabelle session, potentially with running prover.
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     6
*/
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
     7
34871
e596a0b71f3c incorporate "proofdocument" part into main Isabelle/Pure.jar -- except for html_panel.scala, which depends on external library (Lobo/Cobra browser);
wenzelm
parents: 34859
diff changeset
     8
package isabelle
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
     9
43520
cec9b95fa35d explicit import java.lang.System to prevent odd scope problems;
wenzelm
parents: 43443
diff changeset
    10
import java.lang.System
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    11
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
    12
import scala.actors.TIMEOUT
38226
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
    13
import scala.actors.Actor
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    14
import scala.actors.Actor._
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    15
34815
6bae73cd8e33 unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents: 34813
diff changeset
    16
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    17
object Session
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    18
{
43645
ac886d096c11 some support for Session.File_Store;
wenzelm
parents: 43644
diff changeset
    19
  /* abstract file store */
ac886d096c11 some support for Session.File_Store;
wenzelm
parents: 43644
diff changeset
    20
ac886d096c11 some support for Session.File_Store;
wenzelm
parents: 43644
diff changeset
    21
  abstract class File_Store
ac886d096c11 some support for Session.File_Store;
wenzelm
parents: 43644
diff changeset
    22
  {
ac886d096c11 some support for Session.File_Store;
wenzelm
parents: 43644
diff changeset
    23
    def read(path: Path): String
ac886d096c11 some support for Session.File_Store;
wenzelm
parents: 43644
diff changeset
    24
  }
ac886d096c11 some support for Session.File_Store;
wenzelm
parents: 43644
diff changeset
    25
ac886d096c11 some support for Session.File_Store;
wenzelm
parents: 43644
diff changeset
    26
34813
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    27
  /* events */
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    28
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    29
  case object Global_Settings
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    30
  case object Perspective
38849
2f198d107aef session_actor: await state assigment of previous change before signalling current change, and avoid crash in overrun situations;
wenzelm
parents: 38848
diff changeset
    31
  case object Assignment
38360
53224a4d2f0e specific Session.Commands_Changed;
wenzelm
parents: 38359
diff changeset
    32
  case class Commands_Changed(set: Set[Command])
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
    33
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
    34
  sealed abstract class Phase
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
    35
  case object Inactive extends Phase
39701
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
    36
  case object Startup extends Phase  // transient
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
    37
  case object Failed extends Phase
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
    38
  case object Ready extends Phase
39701
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
    39
  case object Shutdown extends Phase  // transient
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    40
}
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    41
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    42
43645
ac886d096c11 some support for Session.File_Store;
wenzelm
parents: 43644
diff changeset
    43
class Session(val system: Isabelle_System, val file_store: Session.File_Store)
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    44
{
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    45
  /* real time parameters */  // FIXME properties or settings (!?)
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    46
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    47
  // user input (e.g. text edits, cursor movement)
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40566
diff changeset
    48
  val input_delay = Time.seconds(0.3)
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    49
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    50
  // prover output (markup, common messages)
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40566
diff changeset
    51
  val output_delay = Time.seconds(0.1)
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    52
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    53
  // GUI layout updates
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40566
diff changeset
    54
  val update_delay = Time.seconds(0.5)
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    55
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    56
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    57
  /* pervasive event buses */
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    58
39701
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
    59
  val phase_changed = new Event_Bus[Session.Phase]
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    60
  val global_settings = new Event_Bus[Session.Global_Settings.type]
39588
507fcf86e1e0 just one Session.raw_messages event bus;
wenzelm
parents: 39585
diff changeset
    61
  val raw_messages = new Event_Bus[Isabelle_Process.Result]
38360
53224a4d2f0e specific Session.Commands_Changed;
wenzelm
parents: 38359
diff changeset
    62
  val commands_changed = new Event_Bus[Session.Commands_Changed]
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
    63
  val perspective = new Event_Bus[Session.Perspective.type]
38849
2f198d107aef session_actor: await state assigment of previous change before signalling current change, and avoid crash in overrun situations;
wenzelm
parents: 38848
diff changeset
    64
  val assignments = new Event_Bus[Session.Assignment.type]
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    65
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
    66
34778
8eccd35e975e removed unused Session.prover_logic;
wenzelm
parents: 34777
diff changeset
    67
  /* unique ids */
8eccd35e975e removed unused Session.prover_logic;
wenzelm
parents: 34777
diff changeset
    68
38363
af7f41a8a0a8 clarified "state" (accumulated data) vs. "exec" (execution that produces data);
wenzelm
parents: 38360
diff changeset
    69
  private var id_count: Document.ID = 0
38419
f9dc924e54f8 renamed create_id to new_id;
wenzelm
parents: 38417
diff changeset
    70
  def new_id(): Document.ID = synchronized {
38355
8cb265fb12fe represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents: 38260
diff changeset
    71
    require(id_count > java.lang.Long.MIN_VALUE)
8cb265fb12fe represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents: 38260
diff changeset
    72
    id_count -= 1
8cb265fb12fe represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents: 38260
diff changeset
    73
    id_count
8cb265fb12fe represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents: 38260
diff changeset
    74
  }
34778
8eccd35e975e removed unused Session.prover_logic;
wenzelm
parents: 34777
diff changeset
    75
8eccd35e975e removed unused Session.prover_logic;
wenzelm
parents: 34777
diff changeset
    76
34826
6b38fc0b3406 eliminated redundant session documents database;
wenzelm
parents: 34825
diff changeset
    77
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    78
  /** buffered command changes (delay_first discipline) **/
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    79
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    80
  private case object Stop
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    81
39572
bb3469024b6a added Isabelle_Process.syslog;
wenzelm
parents: 39528
diff changeset
    82
  private val (_, command_change_buffer) =
bb3469024b6a added Isabelle_Process.syslog;
wenzelm
parents: 39528
diff changeset
    83
    Simple_Thread.actor("command_change_buffer", daemon = true)
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    84
  //{{{
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    85
  {
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    86
    var changed: Set[Command] = Set()
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    87
    var flush_time: Option[Long] = None
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    88
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    89
    def flush_timeout: Long =
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    90
      flush_time match {
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    91
        case None => 5000L
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40566
diff changeset
    92
        case Some(time) => (time - System.currentTimeMillis()) max 0
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    93
      }
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    94
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    95
    def flush()
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    96
    {
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    97
      if (!changed.isEmpty) commands_changed.event(Session.Commands_Changed(changed))
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    98
      changed = Set()
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
    99
      flush_time = None
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   100
    }
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   101
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   102
    def invoke()
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   103
    {
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40566
diff changeset
   104
      val now = System.currentTimeMillis()
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   105
      flush_time match {
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40566
diff changeset
   106
        case None => flush_time = Some(now + output_delay.ms)
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   107
        case Some(time) => if (now >= time) flush()
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   108
      }
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   109
    }
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   110
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   111
    var finished = false
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   112
    while (!finished) {
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   113
      receiveWithin(flush_timeout) {
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   114
        case command: Command => changed += command; invoke()
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   115
        case TIMEOUT => flush()
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   116
        case Stop => finished = true; reply(())
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   117
        case bad => System.err.println("command_change_buffer: ignoring bad message " + bad)
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   118
      }
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   119
    }
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   120
  }
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   121
  //}}}
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   122
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   123
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   124
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   125
  /** main protocol actor **/
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   126
43644
ea08ce1c314b tuned signature;
wenzelm
parents: 43553
diff changeset
   127
  val thy_header = new Thy_Header(system.symbols)
ea08ce1c314b tuned signature;
wenzelm
parents: 43553
diff changeset
   128
34851
304a86164dd2 provide global "Isabelle" within interpreter loop -- using import instead of val avoids pontential conflicts with later import isabelle.jedit._;
wenzelm
parents: 34848
diff changeset
   129
  @volatile private var syntax = new Outer_Syntax(system.symbols)
38569
9d480f6a2589 tuned signatures;
wenzelm
parents: 38446
diff changeset
   130
  def current_syntax(): Outer_Syntax = syntax
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   131
39626
a5d0bcfb95a3 manage persistent syslog via Session, not Isabelle_Process;
wenzelm
parents: 39625
diff changeset
   132
  @volatile private var reverse_syslog = List[XML.Elem]()
39629
08eb2730a8a1 tuned signature;
wenzelm
parents: 39626
diff changeset
   133
  def syslog(): String = reverse_syslog.reverse.map(msg => XML.content(msg).mkString).mkString("\n")
39626
a5d0bcfb95a3 manage persistent syslog via Session, not Isabelle_Process;
wenzelm
parents: 39625
diff changeset
   134
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   135
  @volatile private var _phase: Session.Phase = Session.Inactive
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   136
  def phase = _phase
39633
26a28110ece5 simplified Session.Phase;
wenzelm
parents: 39630
diff changeset
   137
  private def phase_=(new_phase: Session.Phase)
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   138
  {
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   139
    _phase = new_phase
39701
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
   140
    phase_changed.event(new_phase)
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   141
  }
43553
df80747342cb proper tokens only if session is ready;
wenzelm
parents: 43520
diff changeset
   142
  def is_ready: Boolean = phase == Session.Ready
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   143
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   144
  private val global_state = new Volatile(Document.State.init)
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   145
  def current_state(): Document.State = global_state.peek()
34816
d33312514220 maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents: 34815
diff changeset
   146
39593
1a34187f0b97 basic setup for Session_Dockable controls;
wenzelm
parents: 39589
diff changeset
   147
  private case object Interrupt_Prover
43648
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   148
  private case class Edit_Node(thy_name: String,
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   149
    header: Exn.Result[Thy_Header.Header], edits: List[Text.Edit])
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   150
  private case class Init_Node(thy_name: String,
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   151
    header: Exn.Result[Thy_Header.Header], text: String)
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40566
diff changeset
   152
  private case class Start(timeout: Time, args: List[String])
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   153
41534
f36cb6f233bd less verbosity;
wenzelm
parents: 40848
diff changeset
   154
  var verbose: Boolean = false
f36cb6f233bd less verbosity;
wenzelm
parents: 40848
diff changeset
   155
39572
bb3469024b6a added Isabelle_Process.syslog;
wenzelm
parents: 39528
diff changeset
   156
  private val (_, session_actor) = Simple_Thread.actor("session_actor", daemon = true)
38639
f642faca303e main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents: 38569
diff changeset
   157
  {
43648
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   158
    val this_actor = self
43649
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   159
    var prover: Option[Isabelle_Process with Isar_Document] = None
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   160
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   161
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   162
    /* document changes */
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   163
38227
6bbb42843b6e concentrate structural document notions in document.scala;
wenzelm
parents: 38226
diff changeset
   164
    def handle_change(change: Document.Change)
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   165
    //{{{
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   166
    {
38848
9483bb678d96 use Future.get_finished where this is the intended meaning -- prefer immediate crash over deadlock due to promises that are never fulfilled;
wenzelm
parents: 38842
diff changeset
   167
      val previous = change.previous.get_finished
39698
625a3bc4417b tuned signature;
wenzelm
parents: 39696
diff changeset
   168
      val (node_edits, version) = change.result.get_finished
38366
fea82d1add74 simplified/clarified Change: transition prev --edits--> result, based on futures;
wenzelm
parents: 38365
diff changeset
   169
38848
9483bb678d96 use Future.get_finished where this is the intended meaning -- prefer immediate crash over deadlock due to promises that are never fulfilled;
wenzelm
parents: 38842
diff changeset
   170
      var former_assignment = global_state.peek().the_assignment(previous).get_finished
38370
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   171
      for {
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   172
        (name, Some(cmd_edits)) <- node_edits
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   173
        (prev, None) <- cmd_edits
38417
b8922ae21111 renamed class Document to Document.Version etc.;
wenzelm
parents: 38416
diff changeset
   174
        removed <- previous.nodes(name).commands.get_after(prev)
38370
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   175
      } former_assignment -= removed
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   176
38150
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   177
      val id_edits =
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   178
        node_edits map {
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   179
          case (name, None) => (name, None)
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   180
          case (name, Some(cmd_edits)) =>
38370
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   181
            val ids =
38150
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   182
              cmd_edits map {
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   183
                case (c1, c2) =>
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   184
                  val id1 = c1.map(_.id)
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   185
                  val id2 =
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   186
                    c2 match {
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   187
                      case None => None
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   188
                      case Some(command) =>
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   189
                        if (global_state.peek().lookup_command(command.id).isEmpty) {
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   190
                          global_state.change(_.define_command(command))
43649
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   191
                          prover.get.
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   192
                            define_command(command.id, system.symbols.encode(command.source))
38150
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   193
                        }
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   194
                        Some(command.id)
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   195
                    }
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   196
                  (id1, id2)
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   197
              }
38370
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   198
            (name -> Some(ids))
38150
67fc24df3721 simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents: 37849
diff changeset
   199
        }
39698
625a3bc4417b tuned signature;
wenzelm
parents: 39696
diff changeset
   200
      global_state.change(_.define_version(version, former_assignment))
43649
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   201
      prover.get.edit_version(previous.id, version.id, id_edits)
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   202
    }
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   203
    //}}}
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   204
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   205
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   206
    /* prover results */
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   207
34836
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   208
    def bad_result(result: Isabelle_Process.Result)
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   209
    {
41534
f36cb6f233bd less verbosity;
wenzelm
parents: 40848
diff changeset
   210
      if (verbose)
f36cb6f233bd less verbosity;
wenzelm
parents: 40848
diff changeset
   211
        System.err.println("Ignoring prover result: " + result.message.toString)
34836
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   212
    }
b83c7a738eb8 singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents: 34835
diff changeset
   213
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   214
    def handle_result(result: Isabelle_Process.Result)
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   215
    //{{{
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   216
    {
38722
ba31936497c2 organized markup properties via apply/unapply patterns;
wenzelm
parents: 38639
diff changeset
   217
      result.properties match {
ba31936497c2 organized markup properties via apply/unapply patterns;
wenzelm
parents: 38639
diff changeset
   218
        case Position.Id(state_id) =>
38370
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   219
          try {
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   220
            val st = global_state.change_yield(_.accumulate(state_id, result.message))
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   221
            command_change_buffer ! st.command
38370
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   222
          }
38414
49f1f657adc2 more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents: 38413
diff changeset
   223
          catch { case _: Document.State.Fail => bad_result(result) }
38722
ba31936497c2 organized markup properties via apply/unapply patterns;
wenzelm
parents: 38639
diff changeset
   224
        case _ =>
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   225
          if (result.is_syslog) {
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   226
            reverse_syslog ::= result.message
40533
e38e80686ce5 somewhat adhoc replacement for 'thus' and 'hence';
wenzelm
parents: 40479
diff changeset
   227
            if (result.is_ready) {
e38e80686ce5 somewhat adhoc replacement for 'thus' and 'hence';
wenzelm
parents: 40479
diff changeset
   228
              // FIXME move to ML side
e38e80686ce5 somewhat adhoc replacement for 'thus' and 'hence';
wenzelm
parents: 40479
diff changeset
   229
              syntax += ("hence", Keyword.PRF_ASM_GOAL, "then have")
e38e80686ce5 somewhat adhoc replacement for 'thus' and 'hence';
wenzelm
parents: 40479
diff changeset
   230
              syntax += ("thus", Keyword.PRF_ASM_GOAL, "then show")
e38e80686ce5 somewhat adhoc replacement for 'thus' and 'hence';
wenzelm
parents: 40479
diff changeset
   231
              phase = Session.Ready
e38e80686ce5 somewhat adhoc replacement for 'thus' and 'hence';
wenzelm
parents: 40479
diff changeset
   232
            }
39701
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
   233
            else if (result.is_exit && phase == Session.Startup) phase = Session.Failed
39696
f4da0428dc78 more informative Session.Phase;
wenzelm
parents: 39633
diff changeset
   234
            else if (result.is_exit) phase = Session.Inactive
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   235
          }
39626
a5d0bcfb95a3 manage persistent syslog via Session, not Isabelle_Process;
wenzelm
parents: 39625
diff changeset
   236
          else if (result.is_stdout) { }
39625
fb0c851e4f9d tuned prover message categorization;
wenzelm
parents: 39593
diff changeset
   237
          else if (result.is_status) {
38370
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   238
            result.body match {
38417
b8922ae21111 renamed class Document to Document.Version etc.;
wenzelm
parents: 38416
diff changeset
   239
              case List(Isar_Document.Assign(id, edits)) =>
38849
2f198d107aef session_actor: await state assigment of previous change before signalling current change, and avoid crash in overrun situations;
wenzelm
parents: 38848
diff changeset
   240
                try {
38882
e1fb3bbc22ab Document state assignment indicates command change;
wenzelm
parents: 38850
diff changeset
   241
                  val cmds: List[Command] = global_state.change_yield(_.assign(id, edits))
e1fb3bbc22ab Document state assignment indicates command change;
wenzelm
parents: 38850
diff changeset
   242
                  for (cmd <- cmds) command_change_buffer ! cmd
38849
2f198d107aef session_actor: await state assigment of previous change before signalling current change, and avoid crash in overrun situations;
wenzelm
parents: 38848
diff changeset
   243
                  assignments.event(Session.Assignment)
2f198d107aef session_actor: await state assigment of previous change before signalling current change, and avoid crash in overrun situations;
wenzelm
parents: 38848
diff changeset
   244
                }
38414
49f1f657adc2 more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents: 38413
diff changeset
   245
                catch { case _: Document.State.Fail => bad_result(result) }
38370
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   246
              case List(Keyword.Command_Decl(name, kind)) => syntax += (name, kind)
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   247
              case List(Keyword.Keyword_Decl(name)) => syntax += name
39625
fb0c851e4f9d tuned prover message categorization;
wenzelm
parents: 39593
diff changeset
   248
              case _ => bad_result(result)
38370
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   249
            }
8b15d0f98962 explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents: 38366
diff changeset
   250
          }
39625
fb0c851e4f9d tuned prover message categorization;
wenzelm
parents: 39593
diff changeset
   251
          else bad_result(result)
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   252
        }
40566
36d4f2757f4f post raw messages last, to ensure that result has been handled by session actor already (e.g. to avoid race between Session.session_actor and Session_Dockable.main_actor);
wenzelm
parents: 40533
diff changeset
   253
36d4f2757f4f post raw messages last, to ensure that result has been handled by session actor already (e.g. to avoid race between Session.session_actor and Session_Dockable.main_actor);
wenzelm
parents: 40533
diff changeset
   254
      raw_messages.event(result)
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   255
    }
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   256
    //}}}
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   257
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   258
43648
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   259
    def edit_version(edits: List[Document.Edit_Text])
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   260
    //{{{
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   261
    {
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   262
      val previous = global_state.peek().history.tip.version
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   263
      val syntax = current_syntax()
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   264
      val result = Future.fork { Thy_Syntax.text_edits(syntax, new_id _, previous.join, edits) }
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   265
      val change = global_state.change_yield(_.extend_history(previous, edits, result))
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   266
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   267
      change.version.map(_ => {
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   268
        assignments.await { global_state.peek().is_assigned(previous.get_finished) }
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   269
        this_actor ! change })
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   270
    }
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   271
    //}}}
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   272
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   273
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   274
    /* main loop */
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   275
38639
f642faca303e main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents: 38569
diff changeset
   276
    var finished = false
f642faca303e main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents: 38569
diff changeset
   277
    while (!finished) {
f642faca303e main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents: 38569
diff changeset
   278
      receive {
39593
1a34187f0b97 basic setup for Session_Dockable controls;
wenzelm
parents: 39589
diff changeset
   279
        case Interrupt_Prover =>
43649
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   280
          prover.map(_.interrupt)
39593
1a34187f0b97 basic setup for Session_Dockable controls;
wenzelm
parents: 39589
diff changeset
   281
43649
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   282
        case Edit_Node(thy_name, header, text_edits) if prover.isDefined =>
43648
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   283
          edit_version(List((thy_name, Some(text_edits))))
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   284
          reply(())
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   285
43649
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   286
        case Init_Node(thy_name, header, text) if prover.isDefined =>
43648
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   287
          // FIXME compare with existing node
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   288
          edit_version(List(
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   289
            (thy_name, None),
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   290
            (thy_name, Some(List(Text.Edit.insert(0, text))))))
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   291
          reply(())
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   292
43649
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   293
        case change: Document.Change if prover.isDefined =>
43648
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   294
          handle_change(change)
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   295
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   296
        case result: Isabelle_Process.Result => handle_result(result)
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   297
43649
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   298
        case Start(timeout, args) if prover.isEmpty =>
39701
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
   299
          if (phase == Session.Inactive || phase == Session.Failed) {
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
   300
            phase = Session.Startup
43649
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   301
            prover =
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   302
              Some(new Isabelle_Process(system, timeout, this_actor, args:_*) with Isar_Document)
39701
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
   303
          }
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   304
39701
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
   305
        case Stop =>
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
   306
          if (phase == Session.Ready) {
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
   307
            global_state.change(_ => Document.State.init)  // FIXME event bus!?
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
   308
            phase = Session.Shutdown
43649
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   309
            prover.get.terminate
39701
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
   310
            phase = Session.Inactive
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
   311
          }
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   312
          finished = true
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   313
          reply(())
38850
5c3e5c548f12 session_actor: ignore spurious TIMEOUT (again) -- probably stemming from earlier use of receiveWithin;
wenzelm
parents: 38849
diff changeset
   314
43649
a912f0b02359 eliminated null;
wenzelm
parents: 43648
diff changeset
   315
        case bad if prover.isDefined =>
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   316
          System.err.println("session_actor: ignoring bad message " + bad)
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   317
      }
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   318
    }
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   319
  }
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   320
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   321
37129
4c83696b340e Command.toString: include id for debugging;
wenzelm
parents: 37065
diff changeset
   322
38226
9d8848d70b0a maintain editor history independently of Swing thread, which is potentially a bottle-neck or might be unavailable (e.g. in batch mode);
wenzelm
parents: 38222
diff changeset
   323
  /** main methods **/
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   324
40848
8662b9b1f123 more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents: 40566
diff changeset
   325
  def start(timeout: Time, args: List[String]) { session_actor ! Start(timeout, args) }
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   326
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   327
  def stop() { command_change_buffer !? Stop; session_actor !? Stop }
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   328
39593
1a34187f0b97 basic setup for Session_Dockable controls;
wenzelm
parents: 39589
diff changeset
   329
  def interrupt() { session_actor ! Interrupt_Prover }
1a34187f0b97 basic setup for Session_Dockable controls;
wenzelm
parents: 39589
diff changeset
   330
43648
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   331
  def edit_node(thy_name: String, header: Exn.Result[Thy_Header.Header], edits: List[Text.Edit])
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   332
  {
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   333
    session_actor !? Edit_Node(thy_name, header, edits)
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   334
  }
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   335
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   336
  def init_node(thy_name: String, header: Exn.Result[Thy_Header.Header], text: String)
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   337
  {
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   338
    session_actor !? Init_Node(thy_name, header, text)
e32de528b5ef more explicit edit_node vs. init_node;
wenzelm
parents: 43647
diff changeset
   339
  }
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   340
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   341
  def snapshot(name: String, pending_edits: List[Text.Edit]): Document.Snapshot =
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   342
    global_state.peek().snapshot(name, pending_edits)
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   343
}