Skip to content

Commit

Permalink
Update CakeML code in benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
myreen committed Jan 24, 2019
1 parent 74ee7ca commit 306e8ea
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 86 deletions.
14 changes: 3 additions & 11 deletions compiler/benchmarks/cakeml_benchmarks/cakeml/bst_contain.sml
@@ -1,19 +1,11 @@

val with_inserts = True

fun num_compare v1 =
(fn v2 =>
if (v1 = v2)
then Equal
else (if (v1 < v2)
then Less
else Greater));

(* NB, 6561 (3^8) and 40000 (2^7 * 5^5) are chosen to be relatively prime so
* that all element of the array are hit *)
fun insert1 a n l =
if n < l then
(a := Map.insert num_compare n 1 (!a);
(a := Map.insert (!a) n 1;
insert1 a (n + 6561) l)
else if n > l then
insert1 a (n - l) l
Expand All @@ -22,7 +14,7 @@ fun insert1 a n l =

fun lookup1 a n l =
if n < l then
(Map.lookup num_compare n (!a);
(Map.lookup (!a) n;
lookup1 a (n + 6561) l)
else if n > l then
lookup1 a (n - l) l
Expand All @@ -36,7 +28,7 @@ fun ins_look a n len =
((if with_inserts then insert1 a 0 len else ()); lookup1 a 0 len; ins_look a (n - 1) len);

fun harness () =
let val a = Ref Tip in
let val a = Ref (Map.empty Int.compare) in
(insert1 a 0 40000;
ins_look a 1000 40000)
end;
Expand Down
10 changes: 5 additions & 5 deletions compiler/benchmarks/cakeml_benchmarks/cakeml/sptree_contain.sml
Expand Up @@ -10,12 +10,12 @@ val with_inserts = True

fun lookup v7 v8 =
case v8
of Ln => NONE
of Ln => None
| Ls(v1) => (if (v7 <= 0)
then (SOME(v1))
else NONE)
then (Some(v1))
else None)
| Bn v3 v2 => (if (v7 <= 0)
then NONE
then None
else (lookup ((let val k = v7 - 1
in
if (k < 0)
Expand All @@ -25,7 +25,7 @@ val with_inserts = True
then v3
else v2)))
| Bs v6 v5 v4 => (if (v7 <= 0)
then (SOME(v5))
then (Some(v5))
else (lookup ((let val k = v7 - 1
in
if (k < 0)
Expand Down
4 changes: 2 additions & 2 deletions compiler/benchmarks/mlton_benchmarks/cakeml/even-odd.sml
Expand Up @@ -2,10 +2,10 @@ fun abs i = if i < 0 then ~i else i
exception Fail of string

fun even' i = case i of
0 => true
0 => True
| _ => odd' (i-1)
and odd' i = case i of
0 => false
0 => False
| _ => even' (i-1)

fun even i = even' (abs i)
Expand Down
4 changes: 2 additions & 2 deletions compiler/benchmarks/mlton_benchmarks/cakeml/imp-for.sml
Expand Up @@ -2,7 +2,7 @@ exception Fail of string;

fun for start stop f
= let
val i = ref start
val i = Ref start
fun loop () = if !i >= stop
then ()
else (f (!i) ; i := !i + 1 ; loop ())
Expand All @@ -14,7 +14,7 @@ structure Main =
struct
fun doit ()
= let
val x = ref 0
val x = Ref 0

val u = for 0 10 (fn _ =>
for 0 10 (fn _ =>
Expand Down
28 changes: 14 additions & 14 deletions compiler/benchmarks/mlton_benchmarks/cakeml/knuth-bendix.sml
Expand Up @@ -9,22 +9,22 @@ structure Main =

fun length l = let
fun j p = case p of
(k, nil) => k
(k, []) => k
| (k, a::x) => j(k+1,x)
in
j(0,l)
end

fun append p = case p of
(nil, l) => l
([], l) => l
| (a::r, l) => a :: (append (r,l))

fun rev l = let
fun f p = case p of
(nil, h) => h
([], h) => h
| (a::r, h) => f(r, a::h)
in
f(l,nil)
f(l,[])
end

fun app f = let
Expand Down Expand Up @@ -70,14 +70,14 @@ fun it_list2 f =

fun exists p =
let fun exists_rec ls = case ls of
[] => false
[] => False
| (a::l) => (p a) orelse (exists_rec l)
in exists_rec
end

fun for_all p =
let fun for_all_rec ls = case ls of
[] => true
[] => True
| (a::l) => (p a) andalso (for_all_rec l)
in for_all_rec
end
Expand Down Expand Up @@ -106,7 +106,7 @@ fun partition p =

fun mem a =
let fun mem_rec ls = case ls of
[] => false
[] => False
| (b::l) => (a=b) orelse mem_rec l
in mem_rec
end
Expand All @@ -121,7 +121,7 @@ fun union l1 l2 =

fun mem_assoc a =
let fun mem_rec ls = case ls of
[] => false
[] => False
| ((b,_)::l) => (a=b) orelse mem_rec l
in mem_rec
end
Expand Down Expand Up @@ -296,10 +296,10 @@ fun reduce l m =
(* A more efficient version of can (rewrite1 (l,r)) for r arbitrary *)
fun reducible l =
let fun redrec m =
(matching l m; true)
(matching l m; True)
handle Failure _ =>
case m of Term _ sons => exists redrec sons
| _ => false
| _ => False
in redrec
end

Expand Down Expand Up @@ -341,9 +341,9 @@ pretty_term (mrewrite_all Group_rules m where m,_=<<A*(I(B)*B)>>);;

datatype ordering = Greater | Equal | NotGE;

fun ge_ord order pair = case order pair of NotGE => false | _ => true
and gt_ord order pair = case order pair of Greater => true | _ => false
and eq_ord order pair = case order pair of Equal => true | _ => false
fun ge_ord order pair = case order pair of NotGE => False | _ => True
and gt_ord order pair = case order pair of Greater => True | _ => False
and eq_ord order pair = case order pair of Equal => True | _ => False

fun rem_eq equiv =
let fun remrec x ls = case ls of
Expand Down Expand Up @@ -603,7 +603,7 @@ fun group_precedence op1 op2 =

val group_order = rpo group_precedence lex_ext

fun greater pair = (case group_order pair of Greater => true | _ => false)
fun greater pair = (case group_order pair of Greater => True | _ => False)

fun doit() = kb_complete greater [] geom_rules

Expand Down
8 changes: 4 additions & 4 deletions compiler/benchmarks/mlton_benchmarks/cakeml/life.sml
Expand Up @@ -24,8 +24,8 @@ structure Main =


fun exists p = let fun existsp ls = case ls of
[] => false
| (a::x) => if p a then true else existsp x
[] => False
| (a::x) => if p a then True else existsp x
in existsp end

fun equal a b = (a = b)
Expand Down Expand Up @@ -53,7 +53,7 @@ structure Main =
| (a::x) => append (lexordset (filter (lexless a) x))
(append [a] (lexordset (filter (lexgreater a) x)))
and lexless(a1:int,b1:int)(a2,b2) =
if a2<a1 then true else if a2=a1 then b2<b1 else false
if a2<a1 then True else if a2=a1 then b2<b1 else False
and lexgreater pr1 pr2 = lexless pr2 pr1
fun collect f list =
let fun accumf sofar ls = case ls of
Expand Down Expand Up @@ -115,7 +115,7 @@ structure Main =
val glider = [(0,0),(0,2),(1,1),(1,2),(2,1)]
val bail = [(0,0),(0,1),(1,0),(1,1)]
fun barberpole n =
let fun f i = if i=n then (n+n-1,n+n)::(n+n,n+n)::nil
let fun f i = if i=n then (n+n-1,n+n)::(n+n,n+n)::[]
else (i+i,i+i+1)::(i+i+2,i+i+1)::f(i+1)
in (0,0)::(1,0):: f 0
end
Expand Down
24 changes: 12 additions & 12 deletions compiler/benchmarks/mlton_benchmarks/cakeml/logic.sml
Expand Up @@ -17,15 +17,15 @@ end;

structure Trail =
struct
val global_trail = ref (nil : Term.term option ref list)
val trail_counter = ref 0
val global_trail = Ref ([] : Term.term option ref list)
val trail_counter = Ref 0
fun unwind_trail ps =
case ps of
(0, tr) => tr
| (n, r::tr) => ( r := NONE ; unwind_trail (n-1, tr) )
| (n, r::tr) => ( r := None ; unwind_trail (n-1, tr) )
| (_, []) => raise Term.BadArg "unwind_trail"

fun reset_trail () = ( global_trail := nil )
fun reset_trail () = ( global_trail := [] )

fun trail func =
let
Expand All @@ -38,7 +38,7 @@ struct
end

fun bind (r, t) =
( r := SOME t ;
( r := Some t ;
global_trail := r::(!global_trail) ;
trail_counter := !trail_counter+1 )

Expand All @@ -51,20 +51,20 @@ struct
fun same_ref p =
case p of
(r, Term.REF(r')) => (r = r')
| _ => false
| _ => False

fun occurs_check r t =
let
fun oc p = case p of
(Term.STR _ ts) => ocs ts
| (Term.REF(r')) =>
(case !r' of
SOME(s) => oc s
Some(s) => oc s
| _ => r <> r')
| (Term.CON _) => true
| (Term.INT _) => true
| (Term.CON _) => True
| (Term.INT _) => True
and ocs ls = case ls of
[] => true
[] => True
| (t::ts) => oc t andalso ocs ts
in
oc t
Expand All @@ -74,7 +74,7 @@ struct
case t of
(Term.REF(x)) =>
(case !x of
SOME(s) => deref s
Some(s) => deref s
| _ => t)
| t => t

Expand Down Expand Up @@ -126,7 +126,7 @@ struct
val cON_nil_s = Term.CON(nil_s)
val cON_x_s = Term.CON(x_s)

fun exists sc = sc (Term.REF(ref(NONE)))
fun exists sc = sc (Term.REF(Ref(None)))

fun move_horiz (t_1, t_2) sc =
(
Expand Down
6 changes: 3 additions & 3 deletions compiler/benchmarks/mlton_benchmarks/cakeml/mpuz.sml
Expand Up @@ -83,7 +83,7 @@ structure Mpuz =
else ()
end

val values = List.map (fn v =>(v, ref false)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
val values = List.map (fn v =>(v, Ref False)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

(* Try all assignments of values to letters. *)
fun loop(letters) =
Expand All @@ -94,10 +94,10 @@ structure Mpuz =
(values, fn (v, r) =>
if !r
then ()
else (r := true
else (r := True
; setLetterValue(c, v)
; loop(letters)
; r := false))
; r := False))

in loop(letters)
end
Expand Down
18 changes: 9 additions & 9 deletions compiler/benchmarks/mlton_benchmarks/cakeml/pidigits.sml
Expand Up @@ -9,17 +9,17 @@ struct
let
fun loop b () =
case f b of
NONE => Nil
| SOME p => case p of (x,b) => (Cons x (loop b))
None => Nil
| Some p => case p of (x,b) => (Cons x (loop b))
in
loop
end

fun map f =
unfold (fn s =>
case s () of
Nil => NONE
| Cons x xs => SOME (f x, xs))
Nil => None
| Cons x xs => Some (f x, xs))

end

Expand Down Expand Up @@ -53,7 +53,7 @@ struct
val pi =
let
val init = unit
val lfts = Stream.map (fn k => (k, 4*k+2, 0, 2*k+1)) (Stream.unfold (fn i => SOME(i, i+1)) 1)
val lfts = Stream.map (fn k => (k, 4*k+2, 0, 2*k+1)) (Stream.unfold (fn i => Some(i, i+1)) 1)
fun floor_extr (q,r,s,t) x = (q * x + r) div (s * x + t)
fun next z = floor_extr z 3
fun safe z n = n = floor_extr z 4
Expand Down Expand Up @@ -98,10 +98,10 @@ struct
fun main (name, arguments) =
case arguments of
[n] => (case Int.fromString n of
SOME n => if n >= 1
Some n => if n >= 1
then (display n; OS.Process.success)
else usage name
| NONE => usage name)
| None => usage name)
| _ => usage name*)
end

Expand Down Expand Up @@ -132,10 +132,10 @@ struct
fun main (name, arguments) =
case arguments of
[n] => (case IntInf.fromString n of
SOME n => if n >= 1
Some n => if n >= 1
then (display n; OS.Process.success)
else usage name
| NONE => usage name)
| None => usage name)
| _ => usage name*)

val doit = display
Expand Down

0 comments on commit 306e8ea

Please sign in to comment.