-
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.
Effect commit is not correct now
- Loading branch information
Showing
6 changed files
with
119 additions
and
7 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
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 |
---|---|---|
|
@@ -26,7 +26,8 @@ | |
base | ||
fmt | ||
logs | ||
stdio) | ||
stdio | ||
(alcotest :with-test)) | ||
(tags | ||
(React "Static Analysis"))) | ||
|
||
|
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ depends: [ | |
"fmt" | ||
"logs" | ||
"stdio" | ||
"alcotest" {with-test} | ||
"odoc" {with-doc} | ||
] | ||
build: [ | ||
|
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,2 +1,3 @@ | ||
(test | ||
(libraries alcotest base react_trace) | ||
(name test_react_trace)) |
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,92 @@ | ||
open! Base | ||
open React_trace | ||
|
||
let fuel = 100 | ||
|
||
let set_in_effect_step_two_times () = | ||
let prog = | ||
let open Syntax in | ||
Prog.( | ||
Comp | ||
( { | ||
name = "C"; | ||
param = "x"; | ||
body = | ||
Expr.( | ||
Stt | ||
{ | ||
label = 0; | ||
stt = "s"; | ||
set = "setS"; | ||
init = Const (Int 42); | ||
body = | ||
Seq | ||
( Eff | ||
(App | ||
{ | ||
fn = Var "setS"; | ||
arg = Fn { param = "s"; body = Const (Int 43) }; | ||
}), | ||
View [ Const Unit ] ); | ||
}); | ||
}, | ||
Expr Expr.(View [ App { fn = Var "C"; arg = Const Unit } ]) )) | ||
in | ||
let { Interp.steps } = Interp.run ~fuel prog in | ||
Alcotest.(check' int) ~msg:"step two times" ~expected:2 ~actual:steps | ||
|
||
let set_in_effect_step_indefinitely () = | ||
let prog = | ||
let open Syntax in | ||
Prog.( | ||
Comp | ||
( { | ||
name = "C"; | ||
param = "x"; | ||
body = | ||
Expr.( | ||
Stt | ||
{ | ||
label = 0; | ||
stt = "s"; | ||
set = "setS"; | ||
init = Const (Int 42); | ||
body = | ||
Seq | ||
( Eff | ||
(App | ||
{ | ||
fn = Var "setS"; | ||
arg = | ||
Fn | ||
{ | ||
param = "s"; | ||
body = | ||
Bin_op | ||
{ | ||
op = Plus; | ||
left = Var "s"; | ||
right = Const (Int 1); | ||
}; | ||
}; | ||
}), | ||
View [ Const Unit ] ); | ||
}); | ||
}, | ||
Expr Expr.(View [ App { fn = Var "C"; arg = Const Unit } ]) )) | ||
in | ||
let { Interp.steps } = Interp.run ~fuel prog in | ||
Alcotest.(check' int) ~msg:"step indefintely" ~expected:fuel ~actual:steps | ||
|
||
let () = | ||
let open Alcotest in | ||
run "Interpreter" | ||
[ | ||
( "steps", | ||
[ | ||
test_case "Set in effect should step two times" `Quick | ||
set_in_effect_step_two_times; | ||
test_case "Set in effect should step indefintely" `Quick | ||
set_in_effect_step_indefinitely; | ||
] ); | ||
] |