From 0cdaae29463fbf676da6413cdb881ddc6c5bdd26 Mon Sep 17 00:00:00 2001 From: favonia Date: Sun, 12 Nov 2023 08:57:26 -0600 Subject: [PATCH 1/2] feat(Logger): debugging interface --- src/Debugger.ml | 24 ++++++++++++++++++++++++ src/Debugger.mli | 3 +++ src/DebuggerSigs.ml | 8 ++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/Debugger.ml create mode 100644 src/Debugger.mli create mode 100644 src/DebuggerSigs.ml diff --git a/src/Debugger.ml b/src/Debugger.ml new file mode 100644 index 0000000..2272b0d --- /dev/null +++ b/src/Debugger.ml @@ -0,0 +1,24 @@ +include DebuggerSigs + +module Make () = struct + type 'a Effect.t += + | Debug : Loctext.t -> unit Effect.t + | CallBegin : Loctext.t -> unit Effect.t + | CallEnd : Loctext.t -> unit Effect.t + + let emit_loctext t = Effect.perform @@ Debug t + let emit ?loc s = emit_loctext @@ Loctext.make ?loc s + let emitf ?loc = Loctext.kmakef ?loc emit_loctext + + let trace_open_loctext t = Effect.perform @@ CallBegin t + let trace_close_loctext t = Effect.perform @@ CallEnd t + + let trace ?loc s f = + trace_open_loctext (Loctext.make ?loc s); + Fun.protect f + ~finally:(fun () -> trace_close_loctext (Loctext.make ?loc s)) + let tracef ?loc = + Text.kmakef @@ fun t f -> + trace_open_loctext (Range.locate_opt loc t); + Fun.protect f ~finally:(fun () -> trace_close_loctext (Range.locate_opt loc t)) +end diff --git a/src/Debugger.mli b/src/Debugger.mli new file mode 100644 index 0000000..b67cf24 --- /dev/null +++ b/src/Debugger.mli @@ -0,0 +1,3 @@ +include module type of DebuggerSigs + +module Make () : S diff --git a/src/DebuggerSigs.ml b/src/DebuggerSigs.ml new file mode 100644 index 0000000..5bf4578 --- /dev/null +++ b/src/DebuggerSigs.ml @@ -0,0 +1,8 @@ +module type S = +sig + val emit : ?loc:Range.t -> string -> unit + val emitf : ?loc:Range.t -> ('a, Format.formatter, unit, unit) format4 -> 'a + val trace : ?loc:Range.t -> string -> (unit -> 'a) -> 'a + val tracef : ?loc:Range.t -> ('b, Format.formatter, unit, (unit -> 'a) -> 'a) format4 -> 'b + val run : emit:(Loctext.t -> unit) -> trace:([`Open | `Close] -> Loctext.t -> unit) -> (unit -> 'a) -> 'a +end From 4f8b7b2665b9097f77031475af0e2eccfa33fd90 Mon Sep 17 00:00:00 2001 From: favonia Date: Wed, 9 Oct 2024 20:13:44 -0500 Subject: [PATCH 2/2] wip --- src/Debugger.ml | 9 +++++---- src/DebuggerSigs.ml | 8 ++++++++ src/Reporter.ml | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Debugger.ml b/src/Debugger.ml index 2272b0d..c43bdf4 100644 --- a/src/Debugger.ml +++ b/src/Debugger.ml @@ -1,10 +1,9 @@ include DebuggerSigs module Make () = struct - type 'a Effect.t += - | Debug : Loctext.t -> unit Effect.t - | CallBegin : Loctext.t -> unit Effect.t - | CallEnd : Loctext.t -> unit Effect.t + type 'a Effect.t += Act : action -> unit Effect.t + + let act ?loc s = emit_loctext @@ Loctext.make ?loc s let emit_loctext t = Effect.perform @@ Debug t let emit ?loc s = emit_loctext @@ Loctext.make ?loc s @@ -21,4 +20,6 @@ module Make () = struct Text.kmakef @@ fun t f -> trace_open_loctext (Range.locate_opt loc t); Fun.protect f ~finally:(fun () -> trace_close_loctext (Range.locate_opt loc t)) + + let run : act:(action -> unit) -> ('a -> end diff --git a/src/DebuggerSigs.ml b/src/DebuggerSigs.ml index 5bf4578..8848193 100644 --- a/src/DebuggerSigs.ml +++ b/src/DebuggerSigs.ml @@ -1,5 +1,13 @@ +module AttributeMap + +type entry = + | Event of Loctext.t * Map + | + | Trace of [`Open | `Close] * Loctext.t + module type S = sig + val log : entry -> unit val emit : ?loc:Range.t -> string -> unit val emitf : ?loc:Range.t -> ('a, Format.formatter, unit, unit) format4 -> 'a val trace : ?loc:Range.t -> string -> (unit -> 'a) -> 'a diff --git a/src/Reporter.ml b/src/Reporter.ml index 81653cb..6e4fe2b 100644 --- a/src/Reporter.ml +++ b/src/Reporter.ml @@ -3,7 +3,7 @@ open Bwd.Infix include ReporterSigs -module Make (Message : Message) : S with module Message := Message = +module Make (Message : Message) (*: S with module Message := Message*) = struct (* Backtraces *) @@ -67,7 +67,7 @@ struct (* Algebraic effects *) - let run ?init_loc ?(init_backtrace=Emp) ~emit ~fatal f = + let run ?init_loc ?(init_backtrace=Emp) ?debug ~emit ~fatal f = Traces.run ~env:(init_loc, init_backtrace) @@ fun () -> Effect.Deep.match_with f () @@ handler ~emit ~fatal