Skip to content

Commit 6b7a22f

Browse files
committed
Pull out common util functions
1 parent 6b6d094 commit 6b7a22f

File tree

5 files changed

+52
-72
lines changed

5 files changed

+52
-72
lines changed

ML/Muntac.sml

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
open Model_Checker;
2-
3-
(*** Printing utilites ***)
4-
fun println s = print (s ^ "\n")
5-
6-
fun list_to_string f = (fn x => "[" ^ x ^ "]") o String.concatWith ", " o map f;
7-
8-
fun print_result NONE = println("Invalid input\n")
9-
| print_result (SOME true) = println("Property is satisfied\n")
10-
| print_result (SOME false) = println("Property is not satisfied\n")
2+
open Util;
113

124
fun print_timings () =
135
let
146
val tab = Timing.get_timings ();
157
fun print_time (s, t) = println(s ^ ": " ^ Time.toString t);
16-
in map print_time tab; () end;
8+
in map print_time tab; () end
179

1810
(*** Wrapping up the checker ***)
19-
fun run_and_print implementation num_threads check_deadlock s =
11+
fun
12+
implementation num_threads check_deadlock s =
2013
let
2114
val debug_level: Int32.int Unsynchronized.ref = ref 0
2215
val _ = debug_level := 2
@@ -44,16 +37,6 @@ fun run_and_print implementation num_threads check_deadlock s =
4437
*)
4538
end;
4639

47-
fun read_lines stream =
48-
let
49-
val input = TextIO.inputLine stream
50-
handle Size => (println "Input line too long!"; raise Size)
51-
in
52-
case input of
53-
NONE => ""
54-
| SOME input => input ^ read_lines stream
55-
end;
56-
5740
fun check_and_verify_from_stream implementation num_threads model check_deadlock =
5841
let
5942
val stream = TextIO.openIn model
@@ -63,20 +46,10 @@ fun check_and_verify_from_stream implementation num_threads model check_deadlock
6346
if input = ""
6447
then println "Failed to read line from input!"
6548
(* We append a space to terminate the input for the parser *)
66-
else input ^ " " |> run_and_print implementation num_threads check_deadlock
49+
else input ^ " " |>
50+
implementation num_threads check_deadlock
6751
end;
6852

69-
fun find_with_arg P [] = NONE
70-
| find_with_arg P [_] = NONE
71-
| find_with_arg P (x :: y :: xs) = if P x then SOME y else find_with_arg P (y :: xs)
72-
73-
fun read_file f =
74-
let
75-
val file = TextIO.openIn f
76-
val s = read_lines file
77-
val _ = TextIO.closeIn file
78-
in s end;
79-
8053
(* For IntInf as the default int type *)
8154
(* val to_large_int = IntInf.fromInt; *)
8255
(* For Int as the default int type *)

ML/Muntax.sml

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
open Model_Checker;
2-
3-
(*** Printing utilites ***)
4-
fun println s = print (s ^ "\n")
5-
6-
fun list_to_string f = (fn x => "[" ^ x ^ "]") o String.concatWith ", " o map f;
7-
8-
fun print_result NONE = println("Invalid input\n")
9-
| print_result (SOME true) = println("Property is satisfied\n")
10-
| print_result (SOME false) = println("Property is not satisfied\n")
2+
open Util;
113

124
(*** Wrapping up the checker ***)
135
fun run_and_print check_deadlock s =
@@ -34,16 +26,6 @@ fun run_and_print check_deadlock s =
3426
in println r end
3527
end;
3628

37-
fun read_lines stream =
38-
let
39-
val input = TextIO.inputLine stream
40-
handle Size => (println "Input line too long!"; raise Size)
41-
in
42-
case input of
43-
NONE => ""
44-
| SOME input => input ^ read_lines stream
45-
end;
46-
4729
fun check_and_verify_from_stream stream _ =
4830
let
4931
val args = CommandLine.arguments()
@@ -56,17 +38,6 @@ fun check_and_verify_from_stream stream _ =
5638
else input ^ " " |> run_and_print check_deadlock
5739
end;
5840

59-
fun find_with_arg P [] = NONE
60-
| find_with_arg P [_] = NONE
61-
| find_with_arg P (x :: y :: xs) = if P x then SOME y else find_with_arg P (y :: xs)
62-
63-
fun read_file f =
64-
let
65-
val file = TextIO.openIn f
66-
val s = read_lines file
67-
val _ = TextIO.closeIn file
68-
in s end;
69-
7041
val to_large_int = fn x => x;
7142

7243
fun print_usage () =
@@ -101,15 +72,6 @@ fun print_explored () =
10172
val _ = if length final > 0 then map println final else [()]
10273
in () end
10374

104-
fun print_json () =
105-
let
106-
val messages = Logging.get_trace ()
107-
val jsons = filter (fn (i, s) => i = 2) messages |> map snd
108-
val _ = println ""
109-
val _ = println "The following JSON was read by the parser:"
110-
val _ = if length jsons > 0 then println (hd jsons) else ()
111-
in () end
112-
11375
fun main () =
11476
let
11577
val args = CommandLine.arguments()

ML/Util.sml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
structure Util =
2+
struct
3+
4+
(*** Printing utilites ***)
5+
fun println s = print (s ^ "\n")
6+
7+
fun list_to_string f = (fn x => "[" ^ x ^ "]") o String.concatWith ", " o map f
8+
9+
fun print_result NONE = println("Invalid input\n")
10+
| print_result (SOME true) = println("Property is satisfied\n")
11+
| print_result (SOME false) = println("Property is not satisfied\n")
12+
13+
fun read_lines stream =
14+
let
15+
val input = TextIO.inputLine stream
16+
handle Size => (println "Input line too long!"; raise Size)
17+
in
18+
case input of
19+
NONE => ""
20+
| SOME input => input ^ read_lines stream
21+
end
22+
23+
fun find_with_arg P [] = NONE
24+
| find_with_arg P [_] = NONE
25+
| find_with_arg P (x :: y :: xs) = if P x then SOME y else find_with_arg P (y :: xs)
26+
27+
fun read_file f =
28+
let
29+
val file = TextIO.openIn f
30+
val s = read_lines file
31+
val _ = TextIO.closeIn file
32+
in s end
33+
34+
fun print_json () =
35+
let
36+
val messages = Logging.get_trace ()
37+
val jsons = filter (fn (i, s) => i = 2) messages |> map snd
38+
val _ = println ""
39+
val _ = println "The following JSON was read by the parser:"
40+
val _ = if length jsons > 0 then println (hd jsons) else ()
41+
in () end
42+
43+
end

ML/muntac.mlb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ Unsynchronized.sml
2929
$(MLUNTA_CERT)/prelude.sml
3030
$(MLUNTA_CERT)/serializable.sml
3131
$(MLUNTA_CERT)/certificate.sml
32+
Util.sml
3233
Muntac.sml
3334
Mlton_Main.sml

ML/muntax.mlb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ ann "nonexhaustiveMatch ignore" in
2020
library.ML
2121
end
2222
Unsynchronized.sml
23+
Util.sml
2324
Muntax.sml
2425
Mlton_Main.sml

0 commit comments

Comments
 (0)