Skip to content

Commit

Permalink
Fixes for dune runtest
Browse files Browse the repository at this point in the history
  • Loading branch information
jnfoster committed Nov 20, 2020
1 parent f807261 commit 0c044c6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions bench/src/PolicyGen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ let shortest_paths_global_policy ((topo, _, _, _) : topo) =
match Node.device src with
| Node.Middlebox -> assert false (* SJS *)
| Node.Host -> (* first hop from host to switch *)
let () = assert (Node.device dst = Node.Switch) in
let () = assert (List.for_all rest ~f:((=) [])) in
let () = assert Poly.(Node.device dst = Node.Switch) in
let () = assert (List.for_all rest ~f:(Poly.(=) [])) in
let dst_sw = Node.id dst in
match_loc dst_sw dst_pt
| Node.Switch ->
let () = assert (List.for_all rest ~f:((<>) [])) in
let () = assert (List.for_all rest ~f:(Poly.(<>) [])) in
begin match Node.device dst with
| Node.Middlebox -> assert false (* SJS *)
| Node.Host -> (* last hop from switch to host *)
Expand Down
4 changes: 2 additions & 2 deletions bench/src/benchmark.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ let sdx filename =
let json = In_channel.with_file filename ~f:Yojson.Basic.from_channel in
let pols =
let open Yojson.Basic.Util in
assert (json |> member "type" |> to_string = "disjoint");
assert Poly.(json |> member "type" |> to_string = "disjoint");
json |> member "pols" |> to_list
|> List.map ~f:Netkat.Json.pol_of_json in
let open Netkat.Pretty in
Expand Down Expand Up @@ -162,7 +162,7 @@ let dot_to_virtual ~in_file =
~f:(fun (file, pred) -> write_all (file ^ ".kat") ~data:(string_of_pred pred))


let _ = match Array.to_list Sys.argv with
let _ = match Sys.get_argv () |> Array.to_list with
(* Run and benchmark the compiler.
The debug flag is not implemented, but it is intended to dump flow tables
Expand Down
2 changes: 1 addition & 1 deletion src/syntax/dune
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
(library
(name test)
(modules test)
(libraries core expect_test_helpers_kernel frenetic)
(libraries core frenetic)
(inline_tests)
(preprocess
(pps ppx_jane frenetic.ppx)))
14 changes: 7 additions & 7 deletions src/syntax/ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ let ext_keyw = "nk"
let ext_keyw_pred = ext_keyw ^ "_pred"

(* expands `s` in `let%nk x = {| s |}` *)
let expand_nk_string ~loc ~pred s =
let expand_nk_string ~loc ~pred s : expression =
let pos = Location.(loc.loc_start) in
(* string starts after '{' and '|' *)
let pos = Lexing.{ pos with pos_cnum = pos.pos_cnum + 2 } in
Lexer.parse_string ~ppx:true ~pos s Parser.(if pred then pred_eof else pol_eof)

(* expands `e` in `let%nk x = e` *)
let expand_bound_expr ~pred expr =
let expand_bound_expr ~pred expr : expression =
let loc = expr.pexp_loc in
match expr.pexp_desc with
(* only expand e if e = {| s |} *)
Expand All @@ -27,16 +27,16 @@ let expand_bound_expr ~pred expr =
Location.raise_errorf ~loc "'let%%%s' may only bind quoted NetKAT" ext_keyw

(* expands `x=e` in `let%nk x = e` *)
let expand_binding ~pred binding =
let expand_binding ~pred binding : value_binding =
{ binding with pvb_expr = expand_bound_expr ~pred binding.pvb_expr }

(* expands `let%nk <bindings>` *)
let expand_let_decl ~loc ~path:_ ~pred bindings =
let expand_let_decl ~loc ~path:_ ~pred bindings : structure_item =
let module B = Ast_builder.Make(struct let loc = loc end) in
B.(pstr_value Nonrecursive (List.map bindings ~f:(expand_binding ~pred)))

(* expands `let%nk <bindings> in body` *)
let expand_let_expr ~loc ~pred bindings body =
let expand_let_expr ~loc ~pred bindings body : expression =
let module B = Ast_builder.Make(struct let loc = loc end) in
B.(pexp_let Nonrecursive (List.map bindings ~f:(expand_binding ~pred)) body)

Expand All @@ -58,14 +58,14 @@ end


(* declare `let%nk x = e` extension *)
let nk_ext_struct pred =
let nk_ext_struct pred : Extension.t =
Extension.V2.declare
(if pred then ext_keyw_pred else ext_keyw)
Extension.Context.structure_item
Match.let_decl
(expand_let_decl ~pred)

let nk_ext_expr pred =
let nk_ext_expr pred : Extension.t =
Extension.declare
(if pred then ext_keyw_pred else ext_keyw)
Extension.Context.expression
Expand Down
5 changes: 2 additions & 3 deletions src/syntax/test.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
open! Core
open! Expect_test_helpers_kernel


(* let declaration *)
let%nk p = {| drop |}
Expand Down Expand Up @@ -38,7 +36,8 @@ let%nk iverson = {| [2 = 1+1]; port:=pipe("true") + [2=1]; port:=pipe("false")
let%nk iverson_pred = {| [2 > 1]; [2 < 1] |}

(* advanced iverson examples *)
let mk_link adj a b =
let mk_link (adj: int array array) (a:int) (b:int) =
let (<>) = Poly.(<>) in
let src,dst = Int32.(of_int_exn adj.(a).(b), of_int_exn adj.(b).(a)) in
let a,b = Int64.(of_int a + 1L, of_int b + 1L) in
let%nk l = {| [src <> 0l]; (switch={a} and port={src}); switch:={b}; port:={dst} |} in
Expand Down

0 comments on commit 0c044c6

Please sign in to comment.