From 3c1f6ba5d89a9928ffbe1d94396d628ffa89f953 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Wed, 7 Oct 2026 23:28:50 -0300 Subject: scratch root for testing with subsystems explorer --- lib/Scratch.ml | 23 +++++++++++++++++++++++ lib/Scratch.mli | 7 +++++++ 2 files changed, 30 insertions(+) create mode 100644 lib/Scratch.ml create mode 100644 lib/Scratch.mli (limited to 'lib') diff --git a/lib/Scratch.ml b/lib/Scratch.ml new file mode 100644 index 0000000..0779db3 --- /dev/null +++ b/lib/Scratch.ml @@ -0,0 +1,23 @@ +module LMDB = Backend.Storage.LMDB +module I = Kernel.Initialization.Make (LMDB) + +let rec remove path = + if Sys.is_directory path then begin + Array.iter (fun name -> remove (Filename.concat path name)) (Sys.readdir path); + Sys.rmdir path + end + else Sys.remove path + +let root ?(evaluators = ["fol", Evaluators.FOL.make ()]) () = + let open Utilities.Result in + let directory = Filename.temp_dir "rnt-scratch" "" in + let* connection = + Sexplib.Sexp.( + List [Atom "lmdb"; List [Atom "path"; Atom directory]; List [Atom "mode"; Atom "420"]] ) + |> Concepts.Configuration.term_of_sexp + |> LMDB.connect + in + at_exit (fun () -> + LMDB.disconnect connection; + try remove directory with Sys_error _ -> () ); + I.initialize ~evaluators connection diff --git a/lib/Scratch.mli b/lib/Scratch.mli new file mode 100644 index 0000000..804c2c2 --- /dev/null +++ b/lib/Scratch.mli @@ -0,0 +1,7 @@ +(** a root over a database of its own in a temporary directory, removed + when the program exits: for tests, and for trying things out. Its + system evaluators are [evaluators], FOL unless told otherwise. *) +val root : + ?evaluators:(string * Protocols.Handle.t) list -> + unit -> + (Protocols.Handle.t, Concepts.Condition.condition) result -- cgit v1.2.3