mirror of
https://github.com/c-cube/sidekick.git
synced 2025-12-07 03:35:38 -05:00
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:
parent
40e124931c
commit
342bf87759
2 changed files with 18 additions and 12 deletions
|
|
@ -15,12 +15,9 @@ type Tr.entry_view +=
|
||||||
(* FIXME: remove when we decode *)
|
(* FIXME: remove when we decode *)
|
||||||
[@@ocaml.warning "-38"]
|
[@@ocaml.warning "-38"]
|
||||||
|
|
||||||
(* tracer *)
|
type state = { sink: Tr.Sink.t; emitted: Tr.Entry_id.t T.Weak_map.t }
|
||||||
type t = { 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_term_ (self : state) (t : Term.t) =
|
||||||
|
|
||||||
let emit (self : t) (t : T.t) : term_ref =
|
|
||||||
let module V = Ser_value in
|
let module V = Ser_value in
|
||||||
let rec loop t =
|
let rec loop t =
|
||||||
match T.Weak_map.find_opt self.emitted t with
|
match T.Weak_map.find_opt self.emitted t with
|
||||||
|
|
@ -58,4 +55,13 @@ let emit (self : t) (t : T.t) : term_ref =
|
||||||
in
|
in
|
||||||
loop t
|
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)
|
let emit' self t : unit = ignore (emit self t : term_ref)
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,15 @@ type Tr.entry_view +=
|
||||||
(* FIXME: remove *)
|
(* FIXME: remove *)
|
||||||
[@@ocaml.warning "-38"]
|
[@@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
|
val create : sink:Tr.Sink.t -> unit -> t
|
||||||
(** [create ~sink ()] makes a tracer that will write terms
|
(** [create ~sink ()] makes a tracer that will write terms
|
||||||
into the given sink. *)
|
into the given sink. *)
|
||||||
|
|
||||||
val emit : t -> Term.t -> term_ref
|
val emit : #t -> Term.t -> term_ref
|
||||||
val emit' : t -> Term.t -> unit
|
val emit' : #t -> Term.t -> unit
|
||||||
|
|
||||||
(* TODO
|
|
||||||
val reader : Term.store -> Tr.Entry_read.reader
|
|
||||||
*)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue