-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 Pluggable recorder module for the interpreter
- Loading branch information
Showing
15 changed files
with
172 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(executable | ||
(name main) | ||
(modes js) | ||
(preprocess | ||
(pps ppx_jane js_of_ocaml-ppx)) | ||
(libraries react_trace base logs logs.fmt fmt fmt.tty js_of_ocaml)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
open! Core | ||
open React_trace | ||
|
||
let position (lexbuf : Lexing.lexbuf) : string = | ||
let open Lexing in | ||
let pos = lexbuf.lex_curr_p in | ||
sprintf "%s:%d:%d" pos.pos_fname pos.pos_lnum (pos.pos_cnum - pos.pos_bol + 1) | ||
|
||
let parse_with_error (lexbuf : Lexing.lexbuf) : Syntax.Prog.t = | ||
Parser.prog Lexer.read lexbuf | ||
|
||
let parse_program_str (program_str : string) : (Syntax.Prog.t, string) result = | ||
let lexbuf = Lexing.from_string program_str in | ||
match parse_with_error lexbuf with | ||
| prog -> Ok prog | ||
| exception Parser.Error -> | ||
Error (sprintf "%s: syntax error" (position lexbuf)) | ||
|
||
let () = | ||
Fmt_tty.setup_std_outputs (); | ||
Logs.set_reporter (Logs_fmt.reporter ()); | ||
Logs.set_level (Some Logs.Info); | ||
|
||
let open Js_of_ocaml in | ||
Js.export_all | ||
(object%js | ||
method run (fuel : int) program_str = | ||
(let open Result.Let_syntax in | ||
let%bind prog = parse_program_str program_str in | ||
let Interp.{ recording; _ } = | ||
Interp.run | ||
?fuel:(if fuel < 1 then None else Some fuel) | ||
~recorder:(module Recorder) | ||
prog | ||
in | ||
if Logs.err_count () > 0 then Error "error" else Ok recording) | ||
|> (function Ok s -> s | Error s -> s) | ||
|> Js.string | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
open Stdlib.Effect | ||
open Stdlib.Effect.Deep | ||
open React_trace | ||
include Recorder_intf | ||
|
||
(* TODO: Replace the dummy string with an actual recording type *) | ||
type recording = string | ||
|
||
let emp_recording = "empty recording" | ||
|
||
let event_h = | ||
{ | ||
retc = (fun v ~recording -> (v, recording)); | ||
exnc = raise; | ||
effc = | ||
(fun (type a) (eff : a t) -> | ||
match eff with | ||
| Evt_update_st (path, label, (v, q)) -> | ||
Some | ||
(fun (k : (a, _) continuation) ~(recording : recording) -> | ||
ignore (path, label, v, q); | ||
continue k () ~recording) | ||
| Evt_set_dec (path, dec) -> | ||
Some | ||
(fun (k : (a, _) continuation) ~(recording : recording) -> | ||
ignore (path, dec); | ||
continue k () ~recording) | ||
| Evt_enq_eff (path, clos) -> | ||
Some | ||
(fun (k : (a, _) continuation) ~(recording : recording) -> | ||
ignore (path, clos); | ||
continue k () ~recording) | ||
| Evt_alloc_pt path -> | ||
Some | ||
(fun (k : (a, _) continuation) ~(recording : recording) -> | ||
ignore path; | ||
continue k () ~recording) | ||
| _ -> None); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include React_trace.Recorder_intf.Intf with type recording = string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
(executable | ||
(public_name react_trace) | ||
(name main) | ||
(modes exe js) | ||
(preprocess | ||
(pps ppx_jane)) | ||
(libraries react_trace base logs logs.fmt fmt fmt.tty)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
open Stdlib.Effect | ||
open Stdlib.Effect.Deep | ||
include Recorder_intf | ||
|
||
type recording = unit | ||
|
||
let emp_recording = () | ||
|
||
let event_h = | ||
{ | ||
retc = (fun v ~recording -> (v, recording)); | ||
exnc = raise; | ||
effc = | ||
(fun (type a) (eff : a t) -> | ||
match eff with | ||
| Evt_update_st (path, label, (v, q)) -> | ||
Some | ||
(fun (k : (a, _) continuation) ~(recording : recording) -> | ||
ignore (path, label, v, q); | ||
continue k () ~recording) | ||
| Evt_set_dec (path, dec) -> | ||
Some | ||
(fun (k : (a, _) continuation) ~(recording : recording) -> | ||
ignore (path, dec); | ||
continue k () ~recording) | ||
| Evt_enq_eff (path, clos) -> | ||
Some | ||
(fun (k : (a, _) continuation) ~(recording : recording) -> | ||
ignore (path, clos); | ||
continue k () ~recording) | ||
| Evt_alloc_pt path -> | ||
Some | ||
(fun (k : (a, _) continuation) ~(recording : recording) -> | ||
ignore path; | ||
continue k () ~recording) | ||
| _ -> None); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include Recorder_intf.Intf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
open! Core | ||
open Stdlib.Effect | ||
open Stdlib.Effect.Deep | ||
open Syntax | ||
open Concrete_domains | ||
|
||
type _ Stdlib.Effect.t += | ||
| Evt_update_st : (Path.t * Label.t * (value * Job_q.t)) -> unit t | ||
| Evt_set_dec : (Path.t * decision) -> unit t | ||
| Evt_enq_eff : (Path.t * clos) -> unit t | ||
| Evt_alloc_pt : Path.t -> unit t | ||
|
||
module type Intf = sig | ||
type recording | ||
|
||
val emp_recording : recording | ||
val event_h : 'a. ('a, recording:recording -> 'a * recording) handler | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters