diff options
Diffstat (limited to '')
| -rw-r--r-- | lib/kernel/Source.ml | 26 | ||||
| -rw-r--r-- | lib/kernel/Source.mli | 25 |
2 files changed, 38 insertions, 13 deletions
diff --git a/lib/kernel/Source.ml b/lib/kernel/Source.ml index b3b7389..e5de6e8 100644 --- a/lib/kernel/Source.ml +++ b/lib/kernel/Source.ml @@ -34,25 +34,35 @@ let evaluator ~language run = method to_string = language ^ "-evaluator" method protocols : Protocols.Handle.protocol list = [Protocols.Evaluator.make self] - method invoke program = + method invoke program ~within = match text program with | None -> Error (Error.not_a_program language) | Some (given, _) when given <> language -> Error (Error.foreign language given) - | Some (_, source) -> run source + | Some (_, source) -> run ~within source end -let run root ~language source = +let evaluators = Path.("system" @/ "evaluator" @/ this) + +let bind directory ~within language program = let open Utilities.Result in let* evaluator = - Path.lookup root Path.("evaluator" @/ language @/ this) + Path.lookup directory Path.(language @/ this) |> Result.map_error (fun _ -> Error.no_evaluator language) in - let* evaluator = Protocols.Evaluator.require evaluator in - Protocols.Evaluator.invoke evaluator (program ~language source) + Fun.protect + ~finally:(fun () -> Protocols.Handle.release evaluator) + (fun () -> + let* evaluator = Protocols.Evaluator.require evaluator in + Protocols.Evaluator.invoke evaluator program ~within ) + +let run root ~language ~within source = + let open Utilities.Result in + let* directory = Path.lookup root evaluators in + bind directory ~within language (program ~language source) let register root ~language evaluator = let open Utilities.Result in - let* evaluators = Path.lookup root Path.("evaluator" @/ this) in - let* registry = Protocols.Handle.require Protocols.Registry.from evaluators in + let* directory = Path.lookup root evaluators in + let* registry = Protocols.Handle.require Protocols.Registry.from directory in let* _ = Protocols.Registry.update registry language None (Some evaluator) in Ok () diff --git a/lib/kernel/Source.mli b/lib/kernel/Source.mli index 1a51da2..0961dcc 100644 --- a/lib/kernel/Source.mli +++ b/lib/kernel/Source.mli @@ -10,21 +10,36 @@ val program : language:string -> string -> Protocols.Handle.t val text : Protocols.Handle.t -> (string * string) option (** an evaluator for [language]: it runs the text of a program in that - language, and refuses anything else. *) + language against the directory it is given, and refuses anything + else. *) val evaluator : language:string -> - (string -> (Protocols.Handle.t, Concepts.Condition.condition) result) -> + (within:Protocols.Handle.t -> string -> (Protocols.Handle.t, Concepts.Condition.condition) result) -> Protocols.Handle.t -(** look up the evaluator of [language] under [root]'s \evaluator and run - [text] with it. *) +(** where the evaluators are registered, from the root: \system\evaluator. *) +val evaluators : Path.t + +(** run [program] through the evaluator of [language] found in + [directory], against [within]. Usable as an + [EphemeralRelation.binding] once [directory] and [within] are given. *) +val bind : + Protocols.Handle.t -> + within:Protocols.Handle.t -> + string -> + Protocols.Handle.t -> + (Protocols.Handle.t, Concepts.Condition.condition) result + +(** run [text] in [language] against [within], with the evaluator + registered under [root]. *) val run : Protocols.Handle.t -> language:string -> + within:Protocols.Handle.t -> string -> (Protocols.Handle.t, Concepts.Condition.condition) result -(** register [evaluator] as \evaluator\[language] under [root]. *) +(** register [evaluator] for [language] under [root]. *) val register : Protocols.Handle.t -> language:string -> |
