aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-10-10 00:09:22 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-10-10 00:09:22 -0300
commit6044d2ee551eed72407027c58df625af8a7a8119 (patch)
tree878c920843d1919423543a5466f38de5ade11aa9 /lib
parentbdbb81241850c63150eee20a0424eb684f22f95d (diff)
downloadRNT-6044d2ee551eed72407027c58df625af8a7a8119.tar.gz
RNT-6044d2ee551eed72407027c58df625af8a7a8119.zip
invoke foreign program
Diffstat (limited to '')
-rw-r--r--lib/evaluators/FOL.ml18
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/evaluators/FOL.ml b/lib/evaluators/FOL.ml
index cdd29f1..8f44818 100644
--- a/lib/evaluators/FOL.ml
+++ b/lib/evaluators/FOL.ml
@@ -27,10 +27,6 @@ module Error = struct
condition "malformed-fol-program"
"A stored FOL program did not conform to what was expected. Is your database corrupted?" empty
- let foreign_program evaluator =
- condition "foreign-program" "A plan named a relation stored by another evaluator"
- ("evaluator" |=| Concepts.Value.String evaluator)
-
let cyclic_program code =
condition "cyclic-program" "A stored program reads itself"
("program" |=| Concepts.Value.String (Concepts.Hash.to_hum_string code))
@@ -78,11 +74,11 @@ let decode source = Bencode.of_bytes (Bytes.of_string source) |> Utilities.Resul
references. We partially do that here with the program calling
self, but if the flow is alternated, say between program A and B,
where B calls A and A calls B, we also must check. *)
-let instantiate resolve =
+let instantiate within =
let open Utilities.Result in
let rec bind expanding = function
| Base reference -> (
- let* relation = resolve reference in
+ let* relation = Kernel.Path.lookup within reference in
match Kernel.Program.image relation with
| None -> Ok (Base relation)
| Some {kind= Fol term; source; _} ->
@@ -91,9 +87,11 @@ let instantiate resolve =
if List.exists (Concepts.Hash.hash_equals identity) expanding then
Error (Error.cyclic_program identity)
else bind (identity :: expanding) term
- | Some {evaluator; _} ->
- Protocols.Handle.release relation;
- Error (Error.foreign_program evaluator) )
+ | Some _ ->
+ Protocols.Handle.releasing relation (fun () ->
+ let* program = Protocols.Executable.require relation in
+ let* result = Protocols.Executable.invoke program [] ~within in
+ Ok (Base result) ) )
| Project (term, attributes) ->
let* plan = bind expanding term in
Ok (Project (plan, attributes))
@@ -186,7 +184,7 @@ class evaluator =
let open Utilities.Result in
match kind with
| Fol term ->
- let* plan = instantiate (Kernel.Path.lookup within) term in
+ let* plan = instantiate within term in
execute plan
| _ -> Error (Error.not_a_plan ())