src/Pure/Tools/simplifier_trace.scala
author wenzelm
Mon, 21 Jul 2014 16:58:12 +0200
changeset 57593 2f7d91242b99
parent 56782 433cf57550fa
child 63805 c272680df665
permissions -rw-r--r--
proper Swing buttons instead of active areas within text (by Lars Hupel);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54730
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/Tools/simplifier_trace.scala
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
     2
    Author:     Lars Hupel
54730
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     3
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     4
Interactive Simplifier trace.
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     5
*/
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     6
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     7
package isabelle
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
     8
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
     9
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    10
import scala.annotation.tailrec
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    11
import scala.collection.immutable.SortedMap
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    12
54730
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
    13
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
    14
object Simplifier_Trace
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
    15
{
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    16
  /* trace items from the prover */
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    17
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    18
  val TEXT = "text"
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    19
  val Text = new Properties.String(TEXT)
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    20
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    21
  val PARENT = "parent"
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    22
  val Parent = new Properties.Long(PARENT)
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    23
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    24
  val SUCCESS = "success"
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    25
  val Success = new Properties.Boolean(SUCCESS)
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    26
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    27
  val MEMORY = "memory"
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    28
  val Memory = new Properties.Boolean(MEMORY)
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    29
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    30
  object Item
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    31
  {
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    32
    case class Data(
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    33
      serial: Long, markup: String, text: String,
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    34
      parent: Long, props: Properties.T, content: XML.Body)
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    35
    {
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    36
      def memory: Boolean = Memory.unapply(props) getOrElse true
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    37
    }
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    38
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    39
    def unapply(tree: XML.Tree): Option[(String, Data)] =
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    40
      tree match {
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    41
        case XML.Elem(Markup(Markup.RESULT, Markup.Serial(serial)),
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    42
          List(XML.Elem(Markup(markup, props), content)))
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    43
        if markup.startsWith("simp_trace_") =>  // FIXME proper comparison of string constants
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    44
          (props, props) match {
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    45
            case (Text(text), Parent(parent)) =>
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    46
              Some((markup, Data(serial, markup, text, parent, props, content)))
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    47
            case _ => None
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    48
          }
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    49
        case _ => None
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    50
      }
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
    51
  }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    52
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    53
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    54
  /* replies to the prover */
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    55
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    56
  case class Answer private[Simplifier_Trace](val name: String, val string: String)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    57
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    58
  object Answer
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    59
  {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    60
    object step
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    61
    {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    62
      val skip = Answer("skip", "Skip")
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    63
      val continue = Answer("continue", "Continue")
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    64
      val continue_trace = Answer("continue_trace", "Continue (with full trace)")
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    65
      val continue_passive = Answer("continue_passive", "Continue (without asking)")
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    66
      val continue_disable = Answer("continue_disable", "Continue (without any trace)")
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    67
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    68
      val all = List(continue, continue_trace, continue_passive, continue_disable, skip)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    69
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    70
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    71
    object hint_fail
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    72
    {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    73
      val exit = Answer("exit", "Exit")
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    74
      val redo = Answer("redo", "Redo")
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    75
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    76
      val all = List(redo, exit)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    77
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    78
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    79
55555
9c16317c91d1 prefer concrete list append;
wenzelm
parents: 55553
diff changeset
    80
  val all_answers: List[Answer] = Answer.step.all ::: Answer.hint_fail.all
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    81
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    82
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    83
  /* GUI interaction */
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    84
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    85
  case object Event
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    86
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    87
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
    88
  /* manager thread */
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    89
56717
d96b10ec397c tuned whitespace;
wenzelm
parents: 56715
diff changeset
    90
  private case class Handle_Results(
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
    91
    session: Session, id: Document_ID.Command, results: Command.Results, slot: Promise[Context])
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
    92
  private case class Generate_Trace(results: Command.Results, slot: Promise[Trace])
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    93
  private case class Cancel(serial: Long)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    94
  private object Clear_Memory
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    95
  case class Reply(session: Session, serial: Long, answer: Answer)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    96
57593
2f7d91242b99 proper Swing buttons instead of active areas within text (by Lars Hupel);
wenzelm
parents: 56782
diff changeset
    97
  case class Question(data: Item.Data, answers: List[Answer])
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    98
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
    99
  case class Context(
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   100
    last_serial: Long = 0L,
56717
d96b10ec397c tuned whitespace;
wenzelm
parents: 56715
diff changeset
   101
    questions: SortedMap[Long, Question] = SortedMap.empty)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   102
  {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   103
    def +(q: Question): Context =
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   104
      copy(questions = questions + ((q.data.serial, q)))
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   105
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   106
    def -(s: Long): Context =
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   107
      copy(questions = questions - s)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   108
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   109
    def with_serial(s: Long): Context =
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   110
      copy(last_serial = Math.max(last_serial, s))
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   111
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   112
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
   113
  case class Trace(entries: List[Item.Data])
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   114
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   115
  case class Index(text: String, content: XML.Body)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   116
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   117
  object Index
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   118
  {
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
   119
    def of_data(data: Item.Data): Index =
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   120
      Index(data.text, data.content)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   121
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   122
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   123
  def handle_results(session: Session, id: Document_ID.Command, results: Command.Results): Context =
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   124
  {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   125
    val slot = Future.promise[Context]
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   126
    manager.send(Handle_Results(session, id, results, slot))
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   127
    slot.join
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   128
  }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   129
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   130
  def generate_trace(results: Command.Results): Trace =
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   131
  {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   132
    val slot = Future.promise[Trace]
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   133
    manager.send(Generate_Trace(results, slot))
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   134
    slot.join
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   135
  }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   136
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   137
  def clear_memory() =
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   138
    manager.send(Clear_Memory)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   139
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   140
  def send_reply(session: Session, serial: Long, answer: Answer) =
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   141
    manager.send(Reply(session, serial, answer))
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   142
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   143
  private lazy val manager: Consumer_Thread[Any] =
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   144
  {
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   145
    var contexts = Map.empty[Document_ID.Command, Context]
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   146
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   147
    var memory_children = Map.empty[Long, Set[Long]]
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   148
    var memory = Map.empty[Index, Answer]
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   149
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   150
    def find_question(serial: Long): Option[(Document_ID.Command, Question)] =
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   151
      contexts collectFirst {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   152
        case (id, context) if context.questions contains serial =>
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   153
          (id, context.questions(serial))
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   154
      }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   155
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   156
    def do_cancel(serial: Long, id: Document_ID.Command)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   157
    {
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   158
      // To save memory, we could try to remove empty contexts at this point.
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   159
      // However, if a new serial gets attached to the same command_id after we deleted
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   160
      // its context, its last_serial counter will start at 0 again, and we'll think the
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   161
      // old serials are actually new
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   162
      contexts += (id -> (contexts(id) - serial))
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   163
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   164
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   165
    def do_reply(session: Session, serial: Long, answer: Answer)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   166
    {
56717
d96b10ec397c tuned whitespace;
wenzelm
parents: 56715
diff changeset
   167
      session.protocol_command(
d96b10ec397c tuned whitespace;
wenzelm
parents: 56715
diff changeset
   168
        "Simplifier_Trace.reply", Properties.Value.Long(serial), answer.name)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   169
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   170
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   171
    Consumer_Thread.fork[Any]("Simplifier_Trace.manager", daemon = true)(
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   172
      consume = (arg: Any) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   173
      {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   174
        arg match {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   175
          case Handle_Results(session, id, results, slot) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   176
            var new_context = contexts.getOrElse(id, Context())
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   177
            var new_serial = new_context.last_serial
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   178
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   179
            for ((serial, result) <- results.iterator if serial > new_context.last_serial)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   180
            {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   181
              result match {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   182
                case Item(markup, data) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   183
                  memory_children +=
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   184
                    (data.parent -> (memory_children.getOrElse(data.parent, Set.empty) + serial))
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   185
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   186
                  markup match {
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   187
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   188
                    case Markup.SIMP_TRACE_STEP =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   189
                      val index = Index.of_data(data)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   190
                      memory.get(index) match {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   191
                        case Some(answer) if data.memory =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   192
                          do_reply(session, serial, answer)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   193
                        case _ =>
57593
2f7d91242b99 proper Swing buttons instead of active areas within text (by Lars Hupel);
wenzelm
parents: 56782
diff changeset
   194
                          new_context += Question(data, Answer.step.all)
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   195
                      }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   196
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   197
                    case Markup.SIMP_TRACE_HINT =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   198
                      data.props match {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   199
                        case Success(false) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   200
                          results.get(data.parent) match {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   201
                            case Some(Item(Markup.SIMP_TRACE_STEP, _)) =>
57593
2f7d91242b99 proper Swing buttons instead of active areas within text (by Lars Hupel);
wenzelm
parents: 56782
diff changeset
   202
                              new_context += Question(data, Answer.hint_fail.all)
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   203
                            case _ =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   204
                              // unknown, better send a default reply
57593
2f7d91242b99 proper Swing buttons instead of active areas within text (by Lars Hupel);
wenzelm
parents: 56782
diff changeset
   205
                              do_reply(session, data.serial, Answer.hint_fail.exit)
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   206
                          }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   207
                        case _ =>
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   208
                      }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   209
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   210
                    case Markup.SIMP_TRACE_IGNORE =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   211
                      // At this point, we know that the parent of this 'IGNORE' entry is a 'STEP'
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   212
                      // entry, and that that 'STEP' entry is about to be replayed. Hence, we need
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   213
                      // to selectively purge the replies which have been memorized, going down from
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   214
                      // the parent to all leaves.
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   215
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   216
                      @tailrec
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   217
                      def purge(queue: Vector[Long]): Unit =
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   218
                        queue match {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   219
                          case s +: rest =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   220
                            for (Item(Markup.SIMP_TRACE_STEP, data) <- results.get(s))
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   221
                              memory -= Index.of_data(data)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   222
                            val children = memory_children.getOrElse(s, Set.empty)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   223
                            memory_children -= s
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   224
                            purge(rest ++ children.toVector)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   225
                          case _ =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   226
                        }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   227
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   228
                      purge(Vector(data.parent))
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   229
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   230
                    case _ =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   231
                  }
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   232
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   233
                case _ =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   234
              }
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   235
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   236
              new_serial = serial
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   237
            }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   238
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   239
            new_context = new_context.with_serial(new_serial)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   240
            contexts += (id -> new_context)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   241
            slot.fulfill(new_context)
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   242
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   243
          case Generate_Trace(results, slot) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   244
            // Since there are potentially lots of trace messages, we do not cache them here again.
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   245
            // Instead, everytime the trace is being requested, we re-assemble it based on the
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   246
            // current results.
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   247
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   248
            val items =
57593
2f7d91242b99 proper Swing buttons instead of active areas within text (by Lars Hupel);
wenzelm
parents: 56782
diff changeset
   249
              results.iterator.collect { case (_, Item(_, data)) => data }.toList
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   250
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   251
            slot.fulfill(Trace(items))
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   252
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   253
          case Cancel(serial) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   254
            find_question(serial) match {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   255
              case Some((id, _)) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   256
                do_cancel(serial, id)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   257
              case None =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   258
            }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   259
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   260
          case Clear_Memory =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   261
            memory_children = Map.empty
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   262
            memory = Map.empty
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   263
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   264
          case Reply(session, serial, answer) =>
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   265
            find_question(serial) match {
57593
2f7d91242b99 proper Swing buttons instead of active areas within text (by Lars Hupel);
wenzelm
parents: 56782
diff changeset
   266
              case Some((id, Question(data, _))) =>
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   267
                if (data.markup == Markup.SIMP_TRACE_STEP && data.memory)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   268
                {
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   269
                  val index = Index.of_data(data)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   270
                  memory += (index -> answer)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   271
                }
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   272
                do_cancel(serial, id)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   273
              case None =>
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56718
diff changeset
   274
                Output.warning("send_reply: unknown serial " + serial)
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   275
            }
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   276
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   277
            do_reply(session, serial, answer)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   278
            session.trace_events.post(Event)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   279
        }
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   280
        true
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   281
      },
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   282
      finish = () => contexts = Map.empty
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   283
    )
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   284
  }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   285
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   286
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   287
  /* protocol handler */
54730
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
   288
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
   289
  class Handler extends Session.Protocol_Handler
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
   290
  {
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   291
    assert(manager.is_active)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   292
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
   293
    private def cancel(prover: Prover, msg: Prover.Protocol_Output): Boolean =
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   294
      msg.properties match {
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
   295
        case Markup.Simp_Trace_Cancel(serial) =>
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   296
          manager.send(Cancel(serial))
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   297
          true
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   298
        case _ =>
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   299
          false
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   300
      }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   301
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
   302
    override def stop(prover: Prover) =
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   303
    {
56718
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   304
      manager.send(Clear_Memory)
096139bcfadd replaced manager Actor by Consumer_Thread, which is lazy to defer its start to actual Handler init time;
wenzelm
parents: 56717
diff changeset
   305
      manager.shutdown()
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   306
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54730
diff changeset
   307
55553
99409ccbe04a more standard names for protocol and markup elements;
wenzelm
parents: 55390
diff changeset
   308
    val functions = Map(Markup.SIMP_TRACE_CANCEL -> cancel _)
54730
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
   309
  }
de2d99b459b3 skeleton for Simplifier trace by Lars Hupel;
wenzelm
parents:
diff changeset
   310
}