32 override def toString: String = name |
32 override def toString: String = name |
33 def single: Boolean = false |
33 def single: Boolean = false |
34 def bytes: Boolean = false |
34 def bytes: Boolean = false |
35 def position: Properties.T = here.position |
35 def position: Properties.T = here.position |
36 def here: Scala_Project.Here |
36 def here: Scala_Project.Here |
37 def invoke(args: List[Bytes]): List[Bytes] |
37 def invoke(session: Session, args: List[Bytes]): List[Bytes] |
38 } |
38 } |
39 |
39 |
40 trait Single_Fun extends Fun { override def single: Boolean = true } |
40 trait Single_Fun extends Fun { override def single: Boolean = true } |
41 trait Bytes_Fun extends Fun { override def bytes: Boolean = true } |
41 trait Bytes_Fun extends Fun { override def bytes: Boolean = true } |
42 |
42 |
43 abstract class Fun_Strings(name: String, thread: Boolean = false) |
43 abstract class Fun_Strings(name: String, thread: Boolean = false) |
44 extends Fun(name, thread = thread) { |
44 extends Fun(name, thread = thread) { |
45 override def invoke(args: List[Bytes]): List[Bytes] = |
45 override def invoke(session: Session, args: List[Bytes]): List[Bytes] = |
46 apply(args.map(_.text)).map(Bytes.apply) |
46 apply(args.map(_.text)).map(Bytes.apply) |
47 def apply(args: List[String]): List[String] |
47 def apply(args: List[String]): List[String] |
48 } |
48 } |
49 |
49 |
50 abstract class Fun_String(name: String, thread: Boolean = false) |
50 abstract class Fun_String(name: String, thread: Boolean = false) |
54 def apply(arg: String): String |
54 def apply(arg: String): String |
55 } |
55 } |
56 |
56 |
57 abstract class Fun_Bytes(name: String, thread: Boolean = false) |
57 abstract class Fun_Bytes(name: String, thread: Boolean = false) |
58 extends Fun(name, thread = thread) with Single_Fun with Bytes_Fun { |
58 extends Fun(name, thread = thread) with Single_Fun with Bytes_Fun { |
59 override def invoke(args: List[Bytes]): List[Bytes] = |
59 override def invoke(session: Session, args: List[Bytes]): List[Bytes] = |
60 List(apply(Library.the_single(args))) |
60 List(apply(Library.the_single(args))) |
61 def apply(arg: Bytes): Bytes |
61 def apply(arg: Bytes): Bytes |
62 } |
62 } |
63 |
63 |
64 val encode_fun: XML.Encode.T[Fun] = { fun => |
64 val encode_fun: XML.Encode.T[Fun] = { fun => |
283 functions.find(fun => fun.name == name) match { |
296 functions.find(fun => fun.name == name) match { |
284 case Some(fun) => fun.thread |
297 case Some(fun) => fun.thread |
285 case None => false |
298 case None => false |
286 } |
299 } |
287 |
300 |
288 def function_body(name: String, args: List[Bytes]): (Tag.Value, List[Bytes]) = |
301 def function_body(session: Session, name: String, args: List[Bytes]): (Tag.Value, List[Bytes]) = |
289 functions.find(fun => fun.name == name) match { |
302 functions.find(fun => fun.name == name) match { |
290 case Some(fun) => |
303 case Some(fun) => |
291 Exn.capture { fun.invoke(args) } match { |
304 Exn.capture { fun.invoke(session, args) } match { |
292 case Exn.Res(null) => (Tag.NULL, Nil) |
305 case Exn.Res(null) => (Tag.NULL, Nil) |
293 case Exn.Res(res) => (Tag.OK, res) |
306 case Exn.Res(res) => (Tag.OK, res) |
294 case Exn.Exn(Exn.Interrupt()) => (Tag.INTERRUPT, Nil) |
307 case Exn.Exn(Exn.Interrupt()) => (Tag.INTERRUPT, Nil) |
295 case Exn.Exn(e) => (Tag.ERROR, List(Bytes(Exn.message(e)))) |
308 case Exn.Exn(e) => (Tag.ERROR, List(Bytes(Exn.message(e)))) |
296 } |
309 } |
327 |
340 |
328 private def invoke_scala(msg: Prover.Protocol_Output): Boolean = synchronized { |
341 private def invoke_scala(msg: Prover.Protocol_Output): Boolean = synchronized { |
329 msg.properties match { |
342 msg.properties match { |
330 case Markup.Invoke_Scala(name, id) => |
343 case Markup.Invoke_Scala(name, id) => |
331 def body(): Unit = { |
344 def body(): Unit = { |
332 val (tag, res) = Scala.function_body(name, msg.chunks) |
345 val (tag, res) = Scala.function_body(session, name, msg.chunks) |
333 result(id, tag, res) |
346 result(id, tag, res) |
334 } |
347 } |
335 val future = |
348 val future = |
336 if (Scala.function_thread(name)) { |
349 if (Scala.function_thread(name)) { |
337 Future.thread(name = Isabelle_Thread.make_name(base = "invoke_scala"))(body()) |
350 Future.thread(name = Isabelle_Thread.make_name(base = "invoke_scala"))(body()) |