Skip to content

Commit

Permalink
✨ Implement basic event recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeta611 committed Nov 28, 2024
1 parent d95b99a commit 04ab1a1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bin/js/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let () =
let Interp.{ recording; _ } =
Interp.run
?fuel:(if fuel < 1 then None else Some fuel)
~recorder:(module Recorder)
~recorder:(module String_recorder)
prog
in
if Logs.err_count () > 0 then Error "error" else Ok recording)
Expand Down
28 changes: 26 additions & 2 deletions bin/js/recorder.ml → bin/js/string_recorder.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
open! Core
open Stdlib.Effect
open Stdlib.Effect.Deep
open React_trace
open Concrete_domains
open Interp_effects
include Recorder_intf

(* TODO: Replace the dummy string with an actual recording type *)
type recording = string

let emp_recording = "empty recording"
let emp_recording = "= Recording =\n"

let event_h =
{
Expand All @@ -20,21 +21,44 @@ let event_h =
Some
(fun (k : (a, _) continuation) ~(recording : recording) ->
let () = perform (Update_st (path, label, (v, q))) in
let recording =
recording
^ sprintf "[path %s] Update state %d -> %s\n"
(Sexp.to_string (Path.sexp_of_t path))
label
(Sexp.to_string (sexp_of_value v))
in
continue k () ~recording)
| Set_dec (path, dec) ->
Some
(fun (k : (a, _) continuation) ~(recording : recording) ->
let () = perform (Set_dec (path, dec)) in
let recording =
recording
^ sprintf "[path %s] Set decision %s\n"
(Sexp.to_string (Path.sexp_of_t path))
(Sexp.to_string (sexp_of_decision dec))
in
continue k () ~recording)
| Enq_eff (path, clos) ->
Some
(fun (k : (a, _) continuation) ~(recording : recording) ->
let () = perform (Enq_eff (path, clos)) in
let recording =
recording
^ sprintf "[path %s] Enqueue effect\n"
(Sexp.to_string (Path.sexp_of_t path))
in
continue k () ~recording)
| Alloc_pt ->
Some
(fun (k : (a, _) continuation) ~(recording : recording) ->
let path = perform Alloc_pt in
let recording =
recording
^ sprintf "Allocate path %s\n"
(Sexp.to_string (Path.sexp_of_t path))
in
continue k path ~recording)
| _ -> None);
}
File renamed without changes.

0 comments on commit 04ab1a1

Please sign in to comment.