refactor(core/term): tracer is now a class

this way we can inherit it in tracers that can trace many things,
including terms.
This commit is contained in:
Simon Cruanes 2022-09-26 22:43:49 -04:00
parent 40e124931c
commit 342bf87759
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 18 additions and 12 deletions

View file

@ -15,12 +15,9 @@ type Tr.entry_view +=
(* FIXME: remove when we decode *)
[@@ocaml.warning "-38"]
(* tracer *)
type t = { sink: Tr.Sink.t; emitted: Tr.Entry_id.t T.Weak_map.t }
type state = { sink: Tr.Sink.t; emitted: Tr.Entry_id.t T.Weak_map.t }
let create ~sink () : t = { sink; emitted = T.Weak_map.create 16 }
let emit (self : t) (t : T.t) : term_ref =
let emit_term_ (self : state) (t : Term.t) =
let module V = Ser_value in
let rec loop t =
match T.Weak_map.find_opt self.emitted t with
@ -58,4 +55,13 @@ let emit (self : t) (t : T.t) : term_ref =
in
loop t
(* tracer *)
class t ~sink =
object
val state = { sink; emitted = T.Weak_map.create 16 }
method emit_term (t : Term.t) : term_ref = emit_term_ state t
end
let create ~sink () : t = new t ~sink
let emit (self : #t) (t : T.t) : term_ref = self#emit_term t
let emit' self t : unit = ignore (emit self t : term_ref)

View file

@ -22,15 +22,15 @@ type Tr.entry_view +=
(* FIXME: remove *)
[@@ocaml.warning "-38"]
type t
class t :
sink:Tr.Sink.t
-> object
method emit_term : Term.t -> term_ref
end
val create : sink:Tr.Sink.t -> unit -> t
(** [create ~sink ()] makes a tracer that will write terms
into the given sink. *)
val emit : t -> Term.t -> term_ref
val emit' : t -> Term.t -> unit
(* TODO
val reader : Term.store -> Tr.Entry_read.reader
*)
val emit : #t -> Term.t -> term_ref
val emit' : #t -> Term.t -> unit