src/Pure/System/scala.scala
changeset 73419 22f3f2117ed7
parent 73418 7d7d959547a1
child 73431 f27d7b12e8a4
equal deleted inserted replaced
73418:7d7d959547a1 73419:22f3f2117ed7
    15 
    15 
    16 object Scala
    16 object Scala
    17 {
    17 {
    18   /** registered functions **/
    18   /** registered functions **/
    19 
    19 
    20   abstract class Fun(val name: String) extends Function[String, String]
    20   abstract class Fun(val name: String, val thread: Boolean = false)
       
    21     extends Function[String, String]
    21   {
    22   {
    22     override def toString: String = name
    23     override def toString: String = name
    23     def position: Properties.T = here.position
    24     def position: Properties.T = here.position
    24     def here: Scala_Project.Here
    25     def here: Scala_Project.Here
    25     def apply(arg: String): String
    26     def apply(arg: String): String
   153   object Tag extends Enumeration
   154   object Tag extends Enumeration
   154   {
   155   {
   155     val NULL, OK, ERROR, FAIL, INTERRUPT = Value
   156     val NULL, OK, ERROR, FAIL, INTERRUPT = Value
   156   }
   157   }
   157 
   158 
   158   def function(name: String, arg: String): (Tag.Value, String) =
   159   def function_thread(name: String): Boolean =
       
   160     functions.find(fun => fun.name == name) match {
       
   161       case Some(fun) => fun.thread
       
   162       case None => false
       
   163     }
       
   164 
       
   165   def function_body(name: String, arg: String): (Tag.Value, String) =
   159     functions.find(fun => fun.name == name) match {
   166     functions.find(fun => fun.name == name) match {
   160       case Some(fun) =>
   167       case Some(fun) =>
   161         Exn.capture { fun(arg) } match {
   168         Exn.capture { fun(arg) } match {
   162           case Exn.Res(null) => (Tag.NULL, "")
   169           case Exn.Res(null) => (Tag.NULL, "")
   163           case Exn.Res(res) => (Tag.OK, res)
   170           case Exn.Res(res) => (Tag.OK, res)
   200     }
   207     }
   201 
   208 
   202     private def invoke_scala(msg: Prover.Protocol_Output): Boolean = synchronized
   209     private def invoke_scala(msg: Prover.Protocol_Output): Boolean = synchronized
   203     {
   210     {
   204       msg.properties match {
   211       msg.properties match {
   205         case Markup.Invoke_Scala(name, id, thread) =>
   212         case Markup.Invoke_Scala(name, id) =>
   206           def body: Unit =
   213           def body: Unit =
   207           {
   214           {
   208             val (tag, res) = Scala.function(name, msg.text)
   215             val (tag, res) = Scala.function_body(name, msg.text)
   209             result(id, tag, res)
   216             result(id, tag, res)
   210           }
   217           }
   211           val future =
   218           val future =
   212             if (thread) {
   219             if (Scala.function_thread(name)) {
   213               Future.thread(name = Isabelle_Thread.make_name(base = "invoke_scala"))(body)
   220               Future.thread(name = Isabelle_Thread.make_name(base = "invoke_scala"))(body)
   214             }
   221             }
   215             else Future.fork(body)
   222             else Future.fork(body)
   216           futures += (id -> future)
   223           futures += (id -> future)
   217           true
   224           true