Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Debugger): debugging interface #138

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Debugger.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include DebuggerSigs

module Make () = struct
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
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))

let run : act:(action -> unit) -> ('a ->
end
3 changes: 3 additions & 0 deletions src/Debugger.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include module type of DebuggerSigs

module Make () : S
16 changes: 16 additions & 0 deletions src/DebuggerSigs.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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
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
4 changes: 2 additions & 2 deletions src/Reporter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down Expand Up @@ -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

Expand Down
Loading