| author | huffman |
| Wed, 10 Aug 2011 14:25:56 -0700 | |
| changeset 44138 | 0c9feac80852 |
| parent 43748 | c70bd78ec83c |
| child 44156 | 6aa25b80e1a5 |
| permissions | -rw-r--r-- |
| 36676 | 1 |
/* Title: Pure/System/session.scala |
2 |
Author: Makarius |
|
| 38221 | 3 |
Options: :folding=explicit:collapseFolds=1: |
| 36676 | 4 |
|
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
5 |
Main Isabelle/Scala session, potentially with running prover process. |
| 36676 | 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 | 17 |
object Session |
18 |
{
|
|
| 43716 | 19 |
/* file store */ |
| 43645 | 20 |
|
21 |
abstract class File_Store |
|
22 |
{
|
|
23 |
def read(path: Path): String |
|
24 |
} |
|
25 |
||
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 |
|
| 43716 | 29 |
//{{{
|
| 34791 | 30 |
case object Global_Settings |
| 37849 | 31 |
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
|
32 |
case object Assignment |
| 38360 | 33 |
case class Commands_Changed(set: Set[Command]) |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
34 |
|
|
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
35 |
sealed abstract class Phase |
|
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
36 |
case object Inactive extends Phase |
| 39701 | 37 |
case object Startup extends Phase // transient |
38 |
case object Failed extends Phase |
|
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
39 |
case object Ready extends Phase |
| 39701 | 40 |
case object Shutdown extends Phase // transient |
| 43716 | 41 |
//}}} |
| 34791 | 42 |
} |
43 |
||
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
44 |
|
|
43661
39fdbd814c7f
quasi-static Isabelle_System -- reduced tendency towards "functorial style";
wenzelm
parents:
43660
diff
changeset
|
45 |
class Session(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
|
46 |
{
|
| 37849 | 47 |
/* real time parameters */ // FIXME properties or settings (!?) |
48 |
||
| 43716 | 49 |
val input_delay = Time.seconds(0.3) // user input (e.g. text edits, cursor movement) |
50 |
val output_delay = Time.seconds(0.1) // prover output (markup, common messages) |
|
51 |
val update_delay = Time.seconds(0.5) // GUI layout updates |
|
| 37849 | 52 |
|
53 |
||
| 34809 | 54 |
/* pervasive event buses */ |
55 |
||
56 |
val global_settings = new Event_Bus[Session.Global_Settings.type] |
|
| 37849 | 57 |
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
|
58 |
val assignments = new Event_Bus[Session.Assignment.type] |
| 43716 | 59 |
val commands_changed = new Event_Bus[Session.Commands_Changed] |
60 |
val phase_changed = new Event_Bus[Session.Phase] |
|
|
43721
fad8634cee62
echo prover input via raw_messages, for improved protocol tracing;
wenzelm
parents:
43720
diff
changeset
|
61 |
val raw_messages = new Event_Bus[Isabelle_Process.Message] |
| 43716 | 62 |
|
| 34809 | 63 |
|
64 |
||
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
65 |
/** 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
|
66 |
|
| 43716 | 67 |
//{{{
|
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
68 |
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
|
69 |
|
| 39572 | 70 |
private val (_, command_change_buffer) = |
71 |
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
|
72 |
{
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
73 |
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
|
74 |
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
|
75 |
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
76 |
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
|
77 |
flush_time match {
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
78 |
case None => 5000L |
|
40848
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents:
40566
diff
changeset
|
79 |
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
|
80 |
} |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
81 |
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
82 |
def flush() |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
83 |
{
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
84 |
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
|
85 |
changed = Set() |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
86 |
flush_time = None |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
87 |
} |
|
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 invoke() |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
90 |
{
|
|
40848
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents:
40566
diff
changeset
|
91 |
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
|
92 |
flush_time match {
|
|
40848
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents:
40566
diff
changeset
|
93 |
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
|
94 |
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
|
95 |
} |
|
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 |
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
98 |
var finished = false |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
99 |
while (!finished) {
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
100 |
receiveWithin(flush_timeout) {
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
101 |
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
|
102 |
case TIMEOUT => flush() |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
} |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
106 |
} |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
107 |
} |
|
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 |
|
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
112 |
/** main protocol actor **/ |
| 34809 | 113 |
|
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
114 |
/* global state */ |
| 43644 | 115 |
|
| 43716 | 116 |
@volatile var verbose: Boolean = false |
117 |
||
118 |
@volatile private var loaded_theories: Set[String] = Set() |
|
|
43673
29eb1cd29961
Thy_Info.dependencies: ignore already loaded theories, according to initial prover session status;
wenzelm
parents:
43662
diff
changeset
|
119 |
|
|
43695
5130dfe1b7be
simplified Symbol based on lazy Symbol.Interpretation -- reduced odd "functorial style";
wenzelm
parents:
43673
diff
changeset
|
120 |
@volatile private var syntax = new Outer_Syntax |
| 38569 | 121 |
def current_syntax(): Outer_Syntax = syntax |
| 34809 | 122 |
|
|
39626
a5d0bcfb95a3
manage persistent syslog via Session, not Isabelle_Process;
wenzelm
parents:
39625
diff
changeset
|
123 |
@volatile private var reverse_syslog = List[XML.Elem]() |
| 39629 | 124 |
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
|
125 |
|
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
126 |
@volatile private var _phase: Session.Phase = Session.Inactive |
| 39633 | 127 |
private def phase_=(new_phase: Session.Phase) |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
128 |
{
|
|
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
129 |
_phase = new_phase |
| 39701 | 130 |
phase_changed.event(new_phase) |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
131 |
} |
| 43716 | 132 |
def phase = _phase |
| 43553 | 133 |
def is_ready: Boolean = phase == Session.Ready |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
134 |
|
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
135 |
private val global_state = new Volatile(Document.State.init) |
| 43719 | 136 |
def current_state(): Document.State = global_state() |
|
34816
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34815
diff
changeset
|
137 |
|
| 43716 | 138 |
def snapshot(name: String, pending_edits: List[Text.Edit]): Document.Snapshot = |
| 43719 | 139 |
global_state().snapshot(name, pending_edits) |
| 43716 | 140 |
|
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
141 |
|
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
142 |
/* theory files */ |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
143 |
|
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
144 |
val thy_load = new Thy_Load |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
145 |
{
|
|
43673
29eb1cd29961
Thy_Info.dependencies: ignore already loaded theories, according to initial prover session status;
wenzelm
parents:
43662
diff
changeset
|
146 |
override def is_loaded(name: String): Boolean = |
|
29eb1cd29961
Thy_Info.dependencies: ignore already loaded theories, according to initial prover session status;
wenzelm
parents:
43662
diff
changeset
|
147 |
loaded_theories.contains(name) |
|
29eb1cd29961
Thy_Info.dependencies: ignore already loaded theories, according to initial prover session status;
wenzelm
parents:
43662
diff
changeset
|
148 |
|
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
149 |
override def check_thy(dir: Path, name: String): (String, Thy_Header.Header) = |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
150 |
{
|
|
43661
39fdbd814c7f
quasi-static Isabelle_System -- reduced tendency towards "functorial style";
wenzelm
parents:
43660
diff
changeset
|
151 |
val file = Isabelle_System.platform_file(dir + Thy_Header.thy_path(name)) |
| 43652 | 152 |
if (!file.exists || !file.isFile) error("No such file: " + quote(file.toString))
|
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
153 |
val text = Standard_System.read_file(file) |
|
43661
39fdbd814c7f
quasi-static Isabelle_System -- reduced tendency towards "functorial style";
wenzelm
parents:
43660
diff
changeset
|
154 |
val header = Thy_Header.read(text) |
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
155 |
(text, header) |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
156 |
} |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
157 |
} |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
158 |
|
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
159 |
val thy_info = new Thy_Info(thy_load) |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
160 |
|
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
161 |
|
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
162 |
/* actor messages */ |
|
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
163 |
|
| 43716 | 164 |
private case class Start(timeout: Time, args: List[String]) |
165 |
private case object Interrupt |
|
|
43697
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43695
diff
changeset
|
166 |
private case class Init_Node(name: String, header: Document.Node.Header, text: String) |
| 43716 | 167 |
private case class Edit_Node(name: String, header: Document.Node.Header, edits: List[Text.Edit]) |
| 43722 | 168 |
private case class Change_Node( |
169 |
name: String, |
|
170 |
doc_edits: List[Document.Edit_Command], |
|
171 |
header_edits: List[(String, Thy_Header.Header)], |
|
172 |
previous: Document.Version, |
|
173 |
version: Document.Version) |
|
| 41534 | 174 |
|
| 39572 | 175 |
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
|
176 |
{
|
| 43648 | 177 |
val this_actor = self |
| 43649 | 178 |
var prover: Option[Isabelle_Process with Isar_Document] = None |
| 34809 | 179 |
|
180 |
||
| 43716 | 181 |
/* incoming edits */ |
182 |
||
| 43718 | 183 |
def handle_edits(name: String, |
184 |
header: Document.Node.Header, edits: List[Option[List[Text.Edit]]]) |
|
| 43716 | 185 |
//{{{
|
186 |
{
|
|
187 |
val syntax = current_syntax() |
|
| 43719 | 188 |
val previous = global_state().history.tip.version |
| 43718 | 189 |
val doc_edits = edits.map(edit => (name, edit)) |
| 43722 | 190 |
val result = Future.fork {
|
191 |
Thy_Syntax.text_edits(syntax, previous.join, doc_edits, List((name, header))) |
|
192 |
} |
|
193 |
val change = |
|
194 |
global_state.change_yield(_.extend_history(previous, doc_edits, result.map(_._3))) |
|
| 43716 | 195 |
|
| 43722 | 196 |
result.map {
|
197 |
case (doc_edits, header_edits, _) => |
|
198 |
assignments.await { global_state().is_assigned(previous.get_finished) }
|
|
199 |
this_actor ! |
|
200 |
Change_Node(name, doc_edits, header_edits, previous.join, change.version.join) |
|
201 |
} |
|
| 43716 | 202 |
} |
203 |
//}}} |
|
204 |
||
205 |
||
206 |
/* resulting changes */ |
|
| 34809 | 207 |
|
| 43722 | 208 |
def handle_change(change: Change_Node) |
| 38221 | 209 |
//{{{
|
| 34809 | 210 |
{
|
| 43722 | 211 |
val previous = change.previous |
212 |
val version = change.version |
|
213 |
val name = change.name |
|
214 |
val doc_edits = change.doc_edits |
|
215 |
val header_edits = change.header_edits |
|
|
38366
fea82d1add74
simplified/clarified Change: transition prev --edits--> result, based on futures;
wenzelm
parents:
38365
diff
changeset
|
216 |
|
| 43719 | 217 |
var former_assignment = global_state().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
|
218 |
for {
|
| 43722 | 219 |
(name, Some(cmd_edits)) <- doc_edits |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38366
diff
changeset
|
220 |
(prev, None) <- cmd_edits |
| 38417 | 221 |
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
|
222 |
} former_assignment -= removed |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38366
diff
changeset
|
223 |
|
| 43720 | 224 |
def id_command(command: Command): Document.Command_ID = |
225 |
{
|
|
226 |
if (global_state().lookup_command(command.id).isEmpty) {
|
|
227 |
global_state.change(_.define_command(command)) |
|
228 |
prover.get.define_command(command.id, Symbol.encode(command.source)) |
|
229 |
} |
|
230 |
command.id |
|
231 |
} |
|
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
232 |
val id_edits = |
| 43722 | 233 |
doc_edits map {
|
| 43720 | 234 |
case (name, edits) => |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38366
diff
changeset
|
235 |
val ids = |
| 43720 | 236 |
edits.map(_.map { case (c1, c2) => (c1.map(id_command), c2.map(id_command)) })
|
237 |
(name, ids) |
|
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
238 |
} |
| 43722 | 239 |
|
| 39698 | 240 |
global_state.change(_.define_version(version, former_assignment)) |
| 43722 | 241 |
prover.get.edit_version(previous.id, version.id, id_edits, header_edits) |
| 34809 | 242 |
} |
| 38221 | 243 |
//}}} |
| 34809 | 244 |
|
245 |
||
246 |
/* prover results */ |
|
247 |
||
248 |
def handle_result(result: Isabelle_Process.Result) |
|
| 38221 | 249 |
//{{{
|
| 34809 | 250 |
{
|
| 43716 | 251 |
def bad_result(result: Isabelle_Process.Result) |
252 |
{
|
|
253 |
if (verbose) |
|
254 |
System.err.println("Ignoring prover result: " + result.message.toString)
|
|
255 |
} |
|
256 |
||
|
38722
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38639
diff
changeset
|
257 |
result.properties match {
|
| 43748 | 258 |
case Position.Id(state_id) if !result.is_raw => |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38366
diff
changeset
|
259 |
try {
|
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
260 |
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
|
261 |
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
|
262 |
} |
| 43748 | 263 |
catch {
|
264 |
case _: Document.State.Fail => bad_result(result) |
|
265 |
} |
|
266 |
case Markup.Invoke_Scala(name, id) if result.is_raw => |
|
267 |
Future.fork {
|
|
268 |
val arg = XML.content(result.body).mkString |
|
269 |
val (tag, res) = Invoke_Scala.method(name, arg) |
|
270 |
prover.get.invoke_scala(id, tag, res) |
|
271 |
} |
|
|
38722
ba31936497c2
organized markup properties via apply/unapply patterns;
wenzelm
parents:
38639
diff
changeset
|
272 |
case _ => |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
273 |
if (result.is_syslog) {
|
|
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
274 |
reverse_syslog ::= result.message |
|
40533
e38e80686ce5
somewhat adhoc replacement for 'thus' and 'hence';
wenzelm
parents:
40479
diff
changeset
|
275 |
if (result.is_ready) {
|
| 43716 | 276 |
// FIXME move to ML side (!?) |
|
40533
e38e80686ce5
somewhat adhoc replacement for 'thus' and 'hence';
wenzelm
parents:
40479
diff
changeset
|
277 |
syntax += ("hence", Keyword.PRF_ASM_GOAL, "then have")
|
|
e38e80686ce5
somewhat adhoc replacement for 'thus' and 'hence';
wenzelm
parents:
40479
diff
changeset
|
278 |
syntax += ("thus", Keyword.PRF_ASM_GOAL, "then show")
|
|
e38e80686ce5
somewhat adhoc replacement for 'thus' and 'hence';
wenzelm
parents:
40479
diff
changeset
|
279 |
phase = Session.Ready |
|
e38e80686ce5
somewhat adhoc replacement for 'thus' and 'hence';
wenzelm
parents:
40479
diff
changeset
|
280 |
} |
| 39701 | 281 |
else if (result.is_exit && phase == Session.Startup) phase = Session.Failed |
| 39696 | 282 |
else if (result.is_exit) phase = Session.Inactive |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
283 |
} |
|
39626
a5d0bcfb95a3
manage persistent syslog via Session, not Isabelle_Process;
wenzelm
parents:
39625
diff
changeset
|
284 |
else if (result.is_stdout) { }
|
| 39625 | 285 |
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
|
286 |
result.body match {
|
| 38417 | 287 |
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
|
288 |
try {
|
|
38882
e1fb3bbc22ab
Document state assignment indicates command change;
wenzelm
parents:
38850
diff
changeset
|
289 |
val cmds: List[Command] = global_state.change_yield(_.assign(id, edits)) |
|
e1fb3bbc22ab
Document state assignment indicates command change;
wenzelm
parents:
38850
diff
changeset
|
290 |
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
|
291 |
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
|
292 |
} |
|
38414
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents:
38413
diff
changeset
|
293 |
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
|
294 |
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
|
295 |
case List(Keyword.Keyword_Decl(name)) => syntax += name |
|
43673
29eb1cd29961
Thy_Info.dependencies: ignore already loaded theories, according to initial prover session status;
wenzelm
parents:
43662
diff
changeset
|
296 |
case List(Thy_Info.Loaded_Theory(name)) => loaded_theories += name |
| 39625 | 297 |
case _ => bad_result(result) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38366
diff
changeset
|
298 |
} |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38366
diff
changeset
|
299 |
} |
| 39625 | 300 |
else bad_result(result) |
| 43748 | 301 |
} |
| 34809 | 302 |
} |
| 38221 | 303 |
//}}} |
| 34809 | 304 |
|
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
305 |
|
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
306 |
/* main loop */ |
| 34809 | 307 |
|
| 43716 | 308 |
//{{{
|
|
38639
f642faca303e
main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents:
38569
diff
changeset
|
309 |
var finished = false |
|
f642faca303e
main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents:
38569
diff
changeset
|
310 |
while (!finished) {
|
|
f642faca303e
main session actor as independent thread, to avoid starvation via regular worker pool;
wenzelm
parents:
38569
diff
changeset
|
311 |
receive {
|
| 43649 | 312 |
case Start(timeout, args) if prover.isEmpty => |
| 39701 | 313 |
if (phase == Session.Inactive || phase == Session.Failed) {
|
314 |
phase = Session.Startup |
|
|
43661
39fdbd814c7f
quasi-static Isabelle_System -- reduced tendency towards "functorial style";
wenzelm
parents:
43660
diff
changeset
|
315 |
prover = Some(new Isabelle_Process(timeout, this_actor, args:_*) with Isar_Document) |
| 39701 | 316 |
} |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
317 |
|
| 39701 | 318 |
case Stop => |
319 |
if (phase == Session.Ready) {
|
|
320 |
global_state.change(_ => Document.State.init) // FIXME event bus!? |
|
321 |
phase = Session.Shutdown |
|
| 43649 | 322 |
prover.get.terminate |
| 43717 | 323 |
prover = None |
| 39701 | 324 |
phase = Session.Inactive |
325 |
} |
|
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
326 |
finished = true |
|
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
327 |
reply(()) |
|
38850
5c3e5c548f12
session_actor: ignore spurious TIMEOUT (again) -- probably stemming from earlier use of receiveWithin;
wenzelm
parents:
38849
diff
changeset
|
328 |
|
| 43717 | 329 |
case Interrupt if prover.isDefined => |
330 |
prover.get.interrupt |
|
| 43716 | 331 |
|
332 |
case Init_Node(name, header, text) if prover.isDefined => |
|
333 |
// FIXME compare with existing node |
|
| 43718 | 334 |
handle_edits(name, header, List(None, Some(List(Text.Edit.insert(0, text))))) |
| 43716 | 335 |
reply(()) |
336 |
||
| 43718 | 337 |
case Edit_Node(name, header, text_edits) if prover.isDefined => |
338 |
handle_edits(name, header, List(Some(text_edits))) |
|
339 |
reply(()) |
|
340 |
||
| 43722 | 341 |
case change: Change_Node if prover.isDefined => |
342 |
handle_change(change) |
|
| 43716 | 343 |
|
|
43721
fad8634cee62
echo prover input via raw_messages, for improved protocol tracing;
wenzelm
parents:
43720
diff
changeset
|
344 |
case input: Isabelle_Process.Input => |
|
fad8634cee62
echo prover input via raw_messages, for improved protocol tracing;
wenzelm
parents:
43720
diff
changeset
|
345 |
raw_messages.event(input) |
|
fad8634cee62
echo prover input via raw_messages, for improved protocol tracing;
wenzelm
parents:
43720
diff
changeset
|
346 |
|
| 43716 | 347 |
case result: Isabelle_Process.Result => |
348 |
handle_result(result) |
|
|
43721
fad8634cee62
echo prover input via raw_messages, for improved protocol tracing;
wenzelm
parents:
43720
diff
changeset
|
349 |
raw_messages.event(result) |
| 43716 | 350 |
|
| 43717 | 351 |
case bad => System.err.println("session_actor: ignoring bad message " + bad)
|
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
352 |
} |
|
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
353 |
} |
| 43716 | 354 |
//}}} |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
355 |
} |
|
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
356 |
|
| 34809 | 357 |
|
| 43716 | 358 |
/* actions */ |
| 34809 | 359 |
|
|
40848
8662b9b1f123
more abstract/uniform handling of time, preferring seconds as Double;
wenzelm
parents:
40566
diff
changeset
|
360 |
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
|
361 |
|
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
362 |
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
|
363 |
|
| 43716 | 364 |
def interrupt() { session_actor ! Interrupt }
|
| 43648 | 365 |
|
|
43697
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43695
diff
changeset
|
366 |
def init_node(name: String, header: Document.Node.Header, text: String) |
| 43716 | 367 |
{ session_actor !? Init_Node(name, header, text) }
|
| 38221 | 368 |
|
| 43716 | 369 |
def edit_node(name: String, header: Document.Node.Header, edits: List[Text.Edit]) |
370 |
{ session_actor !? Edit_Node(name, header, edits) }
|
|
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
371 |
} |