equal
deleted
inserted
replaced
4 Support for Scala at runtime. |
4 Support for Scala at runtime. |
5 *) |
5 *) |
6 |
6 |
7 signature SCALA = |
7 signature SCALA = |
8 sig |
8 sig |
9 val method: string -> string -> string |
9 val promise_function: string -> string -> string future |
10 val promise_method: string -> string -> string future |
10 val function: string -> string -> string |
|
11 val function_yxml: string -> XML.body -> XML.body |
11 exception Null |
12 exception Null |
12 end; |
13 end; |
13 |
14 |
14 structure Scala: SCALA = |
15 structure Scala: SCALA = |
15 struct |
16 struct |
16 |
17 |
17 (** invoke JVM method via Isabelle/Scala **) |
18 (** invoke Scala functions from ML **) |
18 |
19 |
19 val _ = Session.protocol_handler "isabelle.Scala"; |
20 val _ = Session.protocol_handler "isabelle.Scala"; |
20 |
21 |
21 |
22 |
22 (* pending promises *) |
23 (* pending promises *) |
25 |
26 |
26 val promises = |
27 val promises = |
27 Synchronized.var "Scala.promises" (Symtab.empty: string future Symtab.table); |
28 Synchronized.var "Scala.promises" (Symtab.empty: string future Symtab.table); |
28 |
29 |
29 |
30 |
30 (* method invocation *) |
31 (* invoke function *) |
31 |
32 |
32 fun promise_method name arg = |
33 fun promise_function name arg = |
33 let |
34 let |
34 val id = new_id (); |
35 val id = new_id (); |
35 fun abort () = Output.protocol_message (Markup.cancel_scala id) []; |
36 fun abort () = Output.protocol_message (Markup.cancel_scala id) []; |
36 val promise = Future.promise_name "invoke_scala" abort : string future; |
37 val promise = Future.promise_name "invoke_scala" abort : string future; |
37 val _ = Synchronized.change promises (Symtab.update (id, promise)); |
38 val _ = Synchronized.change promises (Symtab.update (id, promise)); |
38 val _ = Output.protocol_message (Markup.invoke_scala name id) [XML.Text arg]; |
39 val _ = Output.protocol_message (Markup.invoke_scala name id) [XML.Text arg]; |
39 in promise end; |
40 in promise end; |
40 |
41 |
41 fun method name arg = Future.join (promise_method name arg); |
42 fun function name arg = Future.join (promise_function name arg); |
|
43 |
|
44 fun function_yxml name = YXML.string_of_body #> function name #> YXML.parse_body; |
42 |
45 |
43 |
46 |
44 (* fulfill *) |
47 (* fulfill *) |
45 |
48 |
46 exception Null; |
49 exception Null; |