author | wenzelm |
Sat, 07 Aug 2010 19:52:14 +0200 | |
changeset 38227 | 6bbb42843b6e |
parent 38226 | 9d8848d70b0a |
child 38230 | ed147003de4b |
permissions | -rw-r--r-- |
36676 | 1 |
/* Title: Pure/System/session.scala |
2 |
Author: Makarius |
|
38221 | 3 |
Options: :folding=explicit:collapseFolds=1: |
36676 | 4 |
|
5 |
Isabelle session, potentially with running prover. |
|
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 |
|
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
10 |
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
11 |
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
|
12 |
import scala.actors.Actor |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
13 |
import scala.actors.Actor._ |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
14 |
|
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
15 |
|
34791 | 16 |
object Session |
17 |
{ |
|
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
18 |
/* events */ |
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
19 |
|
34791 | 20 |
case object Global_Settings |
37849 | 21 |
case object Perspective |
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
22 |
|
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
23 |
|
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
24 |
/* managed entities */ |
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
25 |
|
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
26 |
type Entity_ID = String |
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
27 |
|
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
28 |
trait Entity |
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
29 |
{ |
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
30 |
val id: Entity_ID |
37129 | 31 |
def consume(message: XML.Tree, forward: Command => Unit): Unit |
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
32 |
} |
34791 | 33 |
} |
34 |
||
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
35 |
|
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
|
36 |
class Session(system: Isabelle_System) |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
37 |
{ |
37849 | 38 |
/* real time parameters */ // FIXME properties or settings (!?) |
39 |
||
40 |
// user input (e.g. text edits, cursor movement) |
|
41 |
val input_delay = 300 |
|
42 |
||
43 |
// prover output (markup, common messages) |
|
44 |
val output_delay = 100 |
|
45 |
||
46 |
// GUI layout updates |
|
47 |
val update_delay = 500 |
|
48 |
||
49 |
||
34809 | 50 |
/* pervasive event buses */ |
51 |
||
52 |
val global_settings = new Event_Bus[Session.Global_Settings.type] |
|
53 |
val raw_results = new Event_Bus[Isabelle_Process.Result] |
|
37065
2a73253b5898
separate event bus and dockable for raw output (stdout);
wenzelm
parents:
37063
diff
changeset
|
54 |
val raw_output = new Event_Bus[Isabelle_Process.Result] |
37129 | 55 |
val commands_changed = new Event_Bus[Command_Set] |
37849 | 56 |
val perspective = new Event_Bus[Session.Perspective.type] |
34809 | 57 |
|
58 |
||
34778 | 59 |
/* unique ids */ |
60 |
||
61 |
private var id_count: BigInt = 0 |
|
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
62 |
def create_id(): Session.Entity_ID = synchronized { id_count += 1; "j" + id_count } |
34778 | 63 |
|
64 |
||
34826 | 65 |
|
66 |
/** main actor **/ |
|
34809 | 67 |
|
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
|
68 |
@volatile private var syntax = new Outer_Syntax(system.symbols) |
34819 | 69 |
def current_syntax: Outer_Syntax = syntax |
34809 | 70 |
|
34816
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34815
diff
changeset
|
71 |
@volatile private var entities = Map[Session.Entity_ID, Session.Entity]() |
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34815
diff
changeset
|
72 |
def lookup_entity(id: Session.Entity_ID): Option[Session.Entity] = entities.get(id) |
34835
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34833
diff
changeset
|
73 |
def lookup_command(id: Session.Entity_ID): Option[Command] = |
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34833
diff
changeset
|
74 |
lookup_entity(id) match { |
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34833
diff
changeset
|
75 |
case Some(cmd: Command) => Some(cmd) |
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34833
diff
changeset
|
76 |
case _ => None |
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34833
diff
changeset
|
77 |
} |
34816
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34815
diff
changeset
|
78 |
|
38221 | 79 |
private case class Started(timeout: Int, args: List[String]) |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
80 |
private case object Stop |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
81 |
|
37129 | 82 |
private lazy val session_actor = actor { |
34809 | 83 |
|
84 |
var prover: Isabelle_Process with Isar_Document = null |
|
85 |
||
34816
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34815
diff
changeset
|
86 |
def register(entity: Session.Entity) { entities += (entity.id -> entity) } |
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34815
diff
changeset
|
87 |
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
88 |
var documents = Map[Document.Version_ID, Document]() |
34835
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34833
diff
changeset
|
89 |
def register_document(doc: Document) { documents += (doc.id -> doc) } |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
90 |
register_document(Document.init) |
34835
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34833
diff
changeset
|
91 |
|
34809 | 92 |
|
93 |
/* document changes */ |
|
94 |
||
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38226
diff
changeset
|
95 |
def handle_change(change: Document.Change) |
38221 | 96 |
//{{{ |
34809 | 97 |
{ |
34824
ac35eee85f5c
renamed current_document to recent_document (might be a bit older than current_change);
wenzelm
parents:
34823
diff
changeset
|
98 |
require(change.parent.isDefined) |
34809 | 99 |
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
100 |
val (node_edits, doc) = change.result.join |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
101 |
val id_edits = |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
102 |
node_edits map { |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
103 |
case (name, None) => (name, None) |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
104 |
case (name, Some(cmd_edits)) => |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
105 |
val chs = |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
106 |
cmd_edits map { |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
107 |
case (c1, c2) => |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
108 |
val id1 = c1.map(_.id) |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
109 |
val id2 = |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
110 |
c2 match { |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
111 |
case None => None |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
112 |
case Some(command) => |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
113 |
if (!lookup_command(command.id).isDefined) { |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
114 |
register(command) |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
115 |
prover.define_command(command.id, system.symbols.encode(command.source)) |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
116 |
} |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
117 |
Some(command.id) |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
118 |
} |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
119 |
(id1, id2) |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
120 |
} |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
121 |
(name -> Some(chs)) |
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
122 |
} |
34835
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34833
diff
changeset
|
123 |
register_document(doc) |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
124 |
prover.edit_document(change.parent.get.id, doc.id, id_edits) |
34809 | 125 |
} |
38221 | 126 |
//}}} |
34809 | 127 |
|
128 |
||
129 |
/* prover results */ |
|
130 |
||
34836
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
131 |
def bad_result(result: Isabelle_Process.Result) |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
132 |
{ |
37041 | 133 |
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
|
134 |
} |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
135 |
|
34809 | 136 |
def handle_result(result: Isabelle_Process.Result) |
38221 | 137 |
//{{{ |
34809 | 138 |
{ |
139 |
raw_results.event(result) |
|
34799
0330a4284a9b
just one variable for outer syntax keywords and completion;
wenzelm
parents:
34795
diff
changeset
|
140 |
|
37689
628eabe2213a
simplified Isabelle_Process.Result: use markup directly;
wenzelm
parents:
37132
diff
changeset
|
141 |
val target_id: Option[Session.Entity_ID] = Position.get_id(result.message.attributes) |
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34810
diff
changeset
|
142 |
val target: Option[Session.Entity] = |
34835
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34833
diff
changeset
|
143 |
target_id match { |
34809 | 144 |
case None => None |
34835
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34833
diff
changeset
|
145 |
case Some(id) => lookup_entity(id) |
34809 | 146 |
} |
37129 | 147 |
if (target.isDefined) target.get.consume(result.message, indicate_command_change) |
37689
628eabe2213a
simplified Isabelle_Process.Result: use markup directly;
wenzelm
parents:
37132
diff
changeset
|
148 |
else if (result.is_status) { |
34818
7df68a8f0e3e
register Proof_Document instances as session entities -- handle Markup.EDIT messages locally;
wenzelm
parents:
34817
diff
changeset
|
149 |
// global status message |
34836
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
150 |
result.body match { |
34835
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34833
diff
changeset
|
151 |
|
35013 | 152 |
// document state assignment |
36682 | 153 |
case List(Isar_Document.Assign(edits)) if target_id.isDefined => |
34836
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
154 |
documents.get(target_id.get) match { |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
155 |
case Some(doc) => |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
156 |
val states = |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
157 |
for { |
36682 | 158 |
Isar_Document.Edit(cmd_id, state_id) <- edits |
34836
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
159 |
cmd <- lookup_command(cmd_id) |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
160 |
} yield { |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
161 |
val st = cmd.assign_state(state_id) |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
162 |
register(st) |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
163 |
(cmd, st) |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
164 |
} |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
165 |
doc.assign_states(states) |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
166 |
case None => bad_result(result) |
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
167 |
} |
34809 | 168 |
|
36682 | 169 |
// keyword declarations |
36947 | 170 |
case List(Keyword.Command_Decl(name, kind)) => syntax += (name, kind) |
171 |
case List(Keyword.Keyword_Decl(name)) => syntax += name |
|
34836
b83c7a738eb8
singleton status messages, with more precise patterns -- report bad messages;
wenzelm
parents:
34835
diff
changeset
|
172 |
|
34839 | 173 |
case _ => if (!result.is_ready) bad_result(result) |
34809 | 174 |
} |
175 |
} |
|
37689
628eabe2213a
simplified Isabelle_Process.Result: use markup directly;
wenzelm
parents:
37132
diff
changeset
|
176 |
else if (result.kind == Markup.EXIT) |
34809 | 177 |
prover = null |
37065
2a73253b5898
separate event bus and dockable for raw output (stdout);
wenzelm
parents:
37063
diff
changeset
|
178 |
else if (result.is_raw) |
2a73253b5898
separate event bus and dockable for raw output (stdout);
wenzelm
parents:
37063
diff
changeset
|
179 |
raw_output.event(result) |
37063 | 180 |
else if (!result.is_system) // FIXME syslog (!?) |
34837 | 181 |
bad_result(result) |
34809 | 182 |
} |
38221 | 183 |
//}}} |
34809 | 184 |
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
185 |
|
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
186 |
/* prover startup */ |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
187 |
|
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
188 |
def startup_error(): String = |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
189 |
{ |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
190 |
val buf = new StringBuilder |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
191 |
while ( |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
192 |
receiveWithin(0) { |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
193 |
case result: Isabelle_Process.Result => |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
194 |
if (result.is_raw) { |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
195 |
for (text <- XML.content(result.message)) |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
196 |
buf.append(text) |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
197 |
} |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
198 |
true |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
199 |
case TIMEOUT => false |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
200 |
}) {} |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
201 |
buf.toString |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
202 |
} |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
203 |
|
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
204 |
def prover_startup(timeout: Int): Option[String] = |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
205 |
{ |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
206 |
receiveWithin(timeout) { |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
207 |
case result: Isabelle_Process.Result |
37689
628eabe2213a
simplified Isabelle_Process.Result: use markup directly;
wenzelm
parents:
37132
diff
changeset
|
208 |
if result.kind == Markup.INIT => |
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
209 |
while (receive { |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
210 |
case result: Isabelle_Process.Result => |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
211 |
handle_result(result); !result.is_ready |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
212 |
}) {} |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
213 |
None |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
214 |
|
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
215 |
case result: Isabelle_Process.Result |
37689
628eabe2213a
simplified Isabelle_Process.Result: use markup directly;
wenzelm
parents:
37132
diff
changeset
|
216 |
if result.kind == Markup.EXIT => |
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
217 |
Some(startup_error()) |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
218 |
|
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
219 |
case TIMEOUT => // FIXME clarify |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
220 |
prover.kill; Some(startup_error()) |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
221 |
} |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
222 |
} |
34809 | 223 |
|
224 |
||
225 |
/* main loop */ |
|
226 |
||
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
227 |
val xml_cache = new XML.Cache(131071) |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
228 |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
229 |
loop { |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
230 |
react { |
38221 | 231 |
case Started(timeout, args) => |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
232 |
if (prover == null) { |
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
|
233 |
prover = new Isabelle_Process(system, self, args:_*) with Isar_Document |
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
234 |
val origin = sender |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
235 |
val opt_err = prover_startup(timeout) |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
236 |
if (opt_err.isDefined) prover = null |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
237 |
origin ! opt_err |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
238 |
} |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
239 |
else reply(None) |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
240 |
|
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
241 |
case Stop => // FIXME clarify; synchronous |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
242 |
if (prover != null) { |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
243 |
prover.kill |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
244 |
prover = null |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
245 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
246 |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38226
diff
changeset
|
247 |
case change: Document.Change if prover != null => |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
248 |
handle_change(change) |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
249 |
|
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
250 |
case result: Isabelle_Process.Result => |
34795 | 251 |
handle_result(result.cache(xml_cache)) |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
252 |
|
36782
0499d05663dd
ignore spurious TIMEOUT messages, maybe caused by change of actor semantics in scala-2.8;
wenzelm
parents:
36682
diff
changeset
|
253 |
case TIMEOUT => // FIXME clarify! |
0499d05663dd
ignore spurious TIMEOUT messages, maybe caused by change of actor semantics in scala-2.8;
wenzelm
parents:
36682
diff
changeset
|
254 |
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
255 |
case bad if prover != null => |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
256 |
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
|
257 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
258 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
259 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
260 |
|
34809 | 261 |
|
37129 | 262 |
|
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
|
263 |
/** buffered command changes (delay_first discipline) **/ |
37129 | 264 |
|
38221 | 265 |
private lazy val command_change_buffer = actor |
266 |
//{{{ |
|
267 |
{ |
|
37129 | 268 |
import scala.compat.Platform.currentTime |
269 |
||
270 |
var changed: Set[Command] = Set() |
|
271 |
var flush_time: Option[Long] = None |
|
272 |
||
273 |
def flush_timeout: Long = |
|
274 |
flush_time match { |
|
275 |
case None => 5000L |
|
276 |
case Some(time) => (time - currentTime) max 0 |
|
277 |
} |
|
278 |
||
279 |
def flush() |
|
280 |
{ |
|
281 |
if (!changed.isEmpty) commands_changed.event(Command_Set(changed)) |
|
282 |
changed = Set() |
|
283 |
flush_time = None |
|
284 |
} |
|
285 |
||
286 |
def invoke() |
|
287 |
{ |
|
288 |
val now = currentTime |
|
289 |
flush_time match { |
|
37849 | 290 |
case None => flush_time = Some(now + output_delay) |
37129 | 291 |
case Some(time) => if (now >= time) flush() |
292 |
} |
|
293 |
} |
|
294 |
||
295 |
loop { |
|
296 |
reactWithin(flush_timeout) { |
|
297 |
case command: Command => changed += command; invoke() |
|
298 |
case TIMEOUT => flush() |
|
299 |
case bad => System.err.println("command_change_buffer: ignoring bad message " + bad) |
|
300 |
} |
|
301 |
} |
|
302 |
} |
|
38221 | 303 |
//}}} |
37129 | 304 |
|
305 |
def indicate_command_change(command: Command) |
|
306 |
{ |
|
307 |
command_change_buffer ! command |
|
308 |
} |
|
309 |
||
310 |
||
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
|
311 |
|
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
|
312 |
/** editor history **/ |
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
|
313 |
|
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
|
314 |
private case class Edit_Document(edits: List[Document.Node_Text_Edit]) |
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
|
315 |
|
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
|
316 |
private val editor_history = new Actor |
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
|
317 |
{ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38226
diff
changeset
|
318 |
@volatile private var history = Document.Change.init |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38226
diff
changeset
|
319 |
def current_change(): Document.Change = history |
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
|
320 |
|
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
|
321 |
def act |
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
|
322 |
{ |
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 |
loop { |
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
|
324 |
react { |
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
|
325 |
case Edit_Document(edits) => |
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
|
326 |
val old_change = history |
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
|
327 |
val new_id = create_id() |
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
|
328 |
val result: isabelle.Future[(List[Document.Edit[Command]], Document)] = |
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
|
329 |
isabelle.Future.fork { |
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
|
330 |
val old_doc = old_change.join_document |
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
|
331 |
old_doc.await_assignment |
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
|
332 |
Document.text_edits(Session.this, old_doc, new_id, edits) |
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
|
333 |
} |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38226
diff
changeset
|
334 |
val new_change = new Document.Change(new_id, Some(old_change), edits, result) |
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
|
335 |
history = new_change |
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
|
336 |
new_change.result.map(_ => session_actor ! new_change) |
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
|
337 |
|
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
|
338 |
case bad => System.err.println("editor_model: ignoring bad message " + bad) |
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
|
339 |
} |
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
|
340 |
} |
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
|
341 |
} |
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
|
342 |
} |
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
|
343 |
editor_history.start |
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
|
344 |
|
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
|
345 |
|
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
|
346 |
|
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
|
347 |
/** main methods **/ |
34809 | 348 |
|
38221 | 349 |
def started(timeout: Int, args: List[String]): Option[String] = |
350 |
(session_actor !? Started(timeout, args)).asInstanceOf[Option[String]] |
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
351 |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
352 |
def stop() { session_actor ! Stop } |
38221 | 353 |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38226
diff
changeset
|
354 |
def current_change(): Document.Change = editor_history.current_change() |
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
|
355 |
def edit_document(edits: List[Document.Node_Text_Edit]) { editor_history ! Edit_Document(edits) } |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
356 |
} |