use standard names in compiler tests

This commit is contained in:
Gabriel Scherer 2020-12-21 13:51:53 +01:00 committed by Nathanaël Courant
parent 57459d078d
commit 66d2988b37
26 changed files with 169 additions and 169 deletions

View File

@ -1 +1 @@
Bytecode size: 5678 bytes
Bytecode size: 5808 bytes

View File

@ -1,33 +1,33 @@
let () = print_endline "Arithmetic:"
let () = print_int (6 * 7)
let () = print_int (17 + 12)
let () = print_int (7 - 5)
let () = print_int (19 / 3)
let () = print_int (- (2) + 3) (* parentheses so that it is not parsed as a negative number *)
let () = print_int (19 mod 3)
let () = print_int (3 land 5)
let () = print_int (3 lor 5)
let () = print_int (3 lxor 5)
let () = print_int (7 lsl 1)
let () = print_int (7 lsr 1)
let () = print_int (7 asr 1)
let () = print_int (-1 lsr 1)
let () = print_int (1 lsl 62 - 1) (* Should be previous number *)
let () = print_int (-1 asr 1)
let () = show_int (6 * 7)
let () = show_int (17 + 12)
let () = show_int (7 - 5)
let () = show_int (19 / 3)
let () = show_int (- (2) + 3) (* parentheses so that it is not parsed as a negative number *)
let () = show_int (19 mod 3)
let () = show_int (3 land 5)
let () = show_int (3 lor 5)
let () = show_int (3 lxor 5)
let () = show_int (7 lsl 1)
let () = show_int (7 lsr 1)
let () = show_int (7 asr 1)
let () = show_int (-1 lsr 1)
let () = show_int (1 lsl 62 - 1) (* Should be previous number *)
let () = show_int (-1 asr 1)
let () = print_newline ()
let () = print_int (4 - 2 - 1)
let () = print_int (0 * 3 + 2)
let () = print_int (1 + 1 * 2)
let () = show_int (4 - 2 - 1)
let () = show_int (0 * 3 + 2)
let () = show_int (1 + 1 * 2)
let () = print_newline ()
let ( % ) a b = a mod b
let () = print_int (3 % 2)
let () = print_int (1 + 3 % 2)
let () = print_int (7 % 4 % 4)
let () = show_int (3 % 2)
let () = show_int (1 + 3 % 2)
let () = show_int (7 % 4 % 4)
let () = print_newline ()

View File

@ -1 +1 @@
Bytecode size: 3677 bytes
Bytecode size: 3807 bytes

View File

@ -1 +1 @@
Bytecode size: 8105 bytes
Bytecode size: 8235 bytes

View File

@ -8,35 +8,35 @@ exception E5 of { x : int }
let show_exn e =
match e with
| E1 -> print "E1"
| E2 i -> print "(E2"; print_int i; print ")"
| _ -> print "<unknown>"
| E1 -> print_string "E1"
| E2 i -> print_string "(E2"; show_int i; print_string ")"
| _ -> print_string "<unknown>"
let () =
try raise E1 with
| E1 -> print " ok"
| _ -> print " ko"
| E1 -> print_string " ok"
| _ -> print_string " ko"
let () =
try raise (E2 7) with
(* note: no leading bar *)
E2 x -> if x = 7 then print " ok" else print " ko"
| _ -> print " ko"
E2 x -> if x = 7 then print_string " ok" else print_string " ko"
| _ -> print_string " ko"
let () = print (try " ok" with _ -> " ko")
let () = print_string (try " ok" with _ -> " ko")
let () = try (try raise E1 with E2 _ -> print " ko") with E1 -> print " ok" | _ -> print " ko"
let () = try (try raise (E2 7) with E1 -> print " ko") with E2 x -> if x = 7 then print " ok" else print " ko" | _ -> print " ko"
let () = try (try raise E3 with E1 -> print " ko" | E2 _ -> print " ko") with _ -> print " ok"
let () = try (try raise (E4 7) with E1 -> print " ko" | E2 _ -> print " ko") with _ -> print " ok"
let () = try (try raise E1 with E2 _ -> print_string " ko") with E1 -> print_string " ok" | _ -> print_string " ko"
let () = try (try raise (E2 7) with E1 -> print_string " ko") with E2 x -> if x = 7 then print_string " ok" else print_string " ko" | _ -> print_string " ko"
let () = try (try raise E3 with E1 -> print_string " ko" | E2 _ -> print_string " ko") with _ -> print_string " ok"
let () = try (try raise (E4 7) with E1 -> print_string " ko" | E2 _ -> print_string " ko") with _ -> print_string " ok"
let () = try (try raise E1 with E1 -> print " ok") with _ -> print " ko"
let () = try (try raise (E2 7) with E2 x -> if x = 7 then print " ok" else print " ko") with _ -> print " ko"
let () = try (try raise E1 with E1 -> print_string " ok") with _ -> print_string " ko"
let () = try (try raise (E2 7) with E2 x -> if x = 7 then print_string " ok" else print_string " ko") with _ -> print_string " ko"
let () = print " "; show_exn E1
let () = print " "; show_exn (E2 7)
let () = print " "; show_exn E3
let () = print " "; show_exn (E4 7)
let () = try raise (E5 { x = 8 }) with E5 { x } -> print_int x
let () = print_string " "; show_exn E1
let () = print_string " "; show_exn (E2 7)
let () = print_string " "; show_exn E3
let () = print_string " "; show_exn (E4 7)
let () = try raise (E5 { x = 8 }) with E5 { x } -> show_int x
let () = print_newline ()

View File

@ -1 +1 @@
Bytecode size: 6865 bytes
Bytecode size: 6995 bytes

View File

@ -1,27 +1,27 @@
let () = print_endline "Local exits"
let () = print "simple: "
let () = print_string "simple: "
(* exit not taken *)
let () = print_int (let%exit ex = 42 in 0)
let () = show_int (let%exit ex = 42 in 0)
(* constant exit *)
let () = print_int (let%exit ex = 1 in [%exit] ex)
let () = show_int (let%exit ex = 1 in [%exit] ex)
(* one-parameter exit *)
let () = print_int (let%exit ex n = 2 * n in [%exit] ex 1)
let () = show_int (let%exit ex n = 2 * n in [%exit] ex 1)
(* two-parameters exit *)
let () =
let%exit ex m n = print_int (m * m + n) in
let%exit ex m n = show_int (m * m + n) in
[%exit] ex 1 (1 + 1)
let () = print_newline ()
let () = print "multi-exits: "
let () = print_string "multi-exits: "
(* two exits *)
let () =
print_int (
show_int (
let%exit ex1 = 0
and ex2 = 7
in
@ -31,7 +31,7 @@ let () =
(* two exits of different arity, max arity taken *)
let () =
print_int (
show_int (
let%exit ex1 n = n - 3
and ex2 = 3
in
@ -40,7 +40,7 @@ let () =
(* two exits of different arity, below-max arity taken *)
let () =
print_int (
show_int (
let%exit ex1 n = n + 4
and ex2 = 2
in
@ -48,7 +48,7 @@ let () =
)
let () = print_newline ()
let () = print "exceptions: "
let () = print_string "exceptions: "
exception Foo of int
@ -57,15 +57,15 @@ let () =
try
let%exit ex n = raise (Foo n) in
[%exit] ex 0
with Foo n -> print_int n
with Foo n -> show_int n
(* exiting across an exception handler *)
let () =
print_int (
show_int (
let%exit ex n = n + 2 in
try
[%exit] ex (-1)
with Foo n -> print_int n
with Foo n -> show_int n
)
(* exiting across two exception handlers *)
@ -76,8 +76,8 @@ let () =
try
[%exit] ex 2
with Invalid_argument _ -> ()
with Foo n -> print_int (2 * n)
with Foo n -> print_int n
with Foo n -> show_int (2 * n)
with Foo n -> show_int n
(* exiting from an exception handler which is not at the top of the stack;
we need another exception handler below, which is used, to observe
@ -89,7 +89,7 @@ let () =
try
let v = 1+0 in
[%exit] ex v
with Foo n -> print_int (2 * n)
with Foo n -> print_int n
with Foo n -> show_int (2 * n)
with Foo n -> show_int n
let () = print_newline ()

View File

@ -1 +1 @@
Bytecode size: 8549 bytes
Bytecode size: 8679 bytes

View File

@ -6,35 +6,35 @@ external obj_field : Obj.t -> int -> Obj.t = "%80"
let rec print_obj x =
let t = obj_tag x in
if t = 1000 then print (format_int "%d" x)
else if t = 1001 then print "<out of heap>"
else if t = 1002 then print "<unaligned>"
else if t = 252 then (print "\""; print x; print "\"")
else (print (format_int "%d" t); print "["; print_obj_fields x 0; print "]")
if t = 1000 then print_string (format_int "%d" x)
else if t = 1001 then print_string "<out of heap>"
else if t = 1002 then print_string "<unaligned>"
else if t = 252 then (print_string "\""; print_string x; print_string "\"")
else (print_string (format_int "%d" t); print_string "["; print_obj_fields x 0; print_string "]")
and print_obj_fields x i =
if i = obj_size x then ()
else if i = obj_size x - 1 then print_obj (obj_field x i)
else (print_obj (obj_field x i); print " "; print_obj_fields x (i + 1))
else (print_obj (obj_field x i); print_string " "; print_obj_fields x (i + 1))
let print_exn e =
match e with
| Out_of_memory -> print "Out_of_memory"
| Sys_error s -> print "Sys_error \""; print s; print "\""
| Failure s -> print "Failure \""; print s; print "\""
| Invalid_argument s -> print "Invalid_argument \""; print s; print "\""
| End_of_file -> print "End_of_file"
| Division_by_zero -> print "Division_by_zero"
| Not_found -> print "Not_found"
| Match_failure _ -> print "Match_failure _"
| Stack_overflow -> print "Stack overflow"
| Sys_blocked_io -> print "Sys_blocked_io"
| Assert_failure _ -> print "Assert_failure _"
| Undefined_recursive_module _ -> print "Undefined_recursive_module _"
| _ -> print "<unknown>"
| Out_of_memory -> print_string "Out_of_memory"
| Sys_error s -> print_string "Sys_error \""; print_string s; print_string "\""
| Failure s -> print_string "Failure \""; print_string s; print_string "\""
| Invalid_argument s -> print_string "Invalid_argument \""; print_string s; print_string "\""
| End_of_file -> print_string "End_of_file"
| Division_by_zero -> print_string "Division_by_zero"
| Not_found -> print_string "Not_found"
| Match_failure _ -> print_string "Match_failure _"
| Stack_overflow -> print_string "Stack overflow"
| Sys_blocked_io -> print_string "Sys_blocked_io"
| Assert_failure _ -> print_string "Assert_failure _"
| Undefined_recursive_module _ -> print_string "Undefined_recursive_module _"
| _ -> print_string "<unknown>"
let run_and_print_exn f =
try f (); print "no exception\n" with e -> (print_obj e; print " "; print_exn e; print "\n")
try f (); print_string "no exception\n" with e -> (print_obj e; print_string " "; print_exn e; print_string "\n")
external int_of_string : string -> int = "caml_int_of_string"
external sys_getenv : string -> string = "caml_sys_getenv"

View File

@ -1 +1 @@
Bytecode size: 7521 bytes
Bytecode size: 7651 bytes

View File

@ -1,76 +1,76 @@
let _ = print_endline "Functions:"
let () = print "simple: "
let () = print_string "simple: "
(* let g x = let z = x * 2 in fun y -> z * 3 *)
let g x y = x - y
let h = g 6
let () = print_int (6 - 3)
let () = print_int (g 6 3)
let () = print_int (h 3)
let () = show_int (6 - 3)
let () = show_int (g 6 3)
let () = show_int (h 3)
let () = print_newline ()
let () = print "currified: "
let () = print_string "currified: "
let f1 = fun x -> fun y -> x * y
let f2 = f1 6
let () = print_int (f2 7)
let () = show_int (f2 7)
let () = print_newline ()
let () = print "higher-order: "
let () = print_string "higher-order: "
let double f x = f (f x)
let add2n n x = double (( + ) n) x
let () = print_int (add2n 20 2)
let () = print_int (double double double double (( + ) 1) 0)
let () = print_int (if false then 17 else 42)
let () = print_int (if true then 17 else 42)
let () = show_int (add2n 20 2)
let () = show_int (double double double double (( + ) 1) 0)
let () = show_int (if false then 17 else 42)
let () = show_int (if true then 17 else 42)
let f x = let x = x + x in x + x + x
let () = print_int (f 7)
let () = show_int (f 7)
let () = print_newline ()
let () = print "local: "
let () = print_string "local: "
let () =
let twice x = x + x in print_int (twice 21)
let twice x = x + x in show_int (twice 21)
let () = print_newline ()
let () = print "recursive: "
let () = print_string "recursive: "
let () =
let n = 10 in
let rec sum i = if i = n then 0 else i + sum (i + 1) in
print_int (sum 0)
show_int (sum 0)
let () =
let n = 10 in
let rec sum1 i = if i = n then 0 else i + sum2 (i + 1)
and sum2 i = if i = n then 0 else sum1 (i + 1) in
print_int (sum1 0); print_int (sum2 0)
show_int (sum1 0); show_int (sum2 0)
let () = print_newline ()
let () = print "let-binding tests: "
let () = print_string "let-binding tests: "
let () = print_int (let a = 17 in let b = 42 in if (let x = 2 in true) then a else b)
let () = print_int (let a = 17 in let b = 42 in if (let x = 2 in false) then a else b)
let () = show_int (let a = 17 in let b = 42 in if (let x = 2 in true) then a else b)
let () = show_int (let a = 17 in let b = 42 in if (let x = 2 in false) then a else b)
(* this ensures that the 'let' are not substituted away... as long as we don't support constant-folding *)
let () = print_int (let a = 16+1 in let b = 41+1 in if (let x = 1+1 in true) then a else b)
let () = print_int (let a = 16+1 in let b = 41+1 in if (let x = 1+1 in false) then a else b)
let () = show_int (let a = 16+1 in let b = 41+1 in if (let x = 1+1 in true) then a else b)
let () = show_int (let a = 16+1 in let b = 41+1 in if (let x = 1+1 in false) then a else b)
(* regression test for an infinite loop in 'Subst unfolding *)
let () = print_int (let x = 21 in let y = x in let x = y in x + y)
let () = show_int (let x = 21 in let y = x in let x = y in x + y)
let () = print_newline ()
let () = print "more recursion: "
let () = print_string "more recursion: "
let rec go n =
if n = 0 then () else (print_int n; go (n - 1))
if n = 0 then () else (show_int n; go (n - 1))
let () = go 10

View File

@ -1 +1 @@
Bytecode size: 4369 bytes
Bytecode size: 4499 bytes

View File

@ -6,11 +6,11 @@ end
module A = F(struct let x = 21 end)
module B = F(struct let x = 12 end)
module X = struct let () = print " only once" let x = 16 end
module X = struct let () = print_string " only once" let x = 16 end
module C = F(X)
module D = F(X)
let () =
print_int A.x; print_int B.x; if C.x = D.x then print " ok" else print " ko"
show_int A.x; show_int B.x; if C.x = D.x then print_string " ok" else print_string " ko"
let () = print_newline ()

View File

@ -1 +1 @@
Bytecode size: 4177 bytes
Bytecode size: 4307 bytes

View File

@ -1,8 +1,8 @@
let () = print_endline "Infix operators treated as sugar:"
let succ n = n + 1
let ignore_and_print_int () n = print_int n
let () = ignore_and_print_int () @@ succ @@ 1
let () = 2 |> succ |> ignore_and_print_int ()
let ignore_and_show_int () n = show_int n
let () = ignore_and_show_int () @@ succ @@ 1
let () = 2 |> succ |> ignore_and_show_int ()
let () = print_newline ()

View File

@ -1 +1 @@
Bytecode size: 5115 bytes
Bytecode size: 5245 bytes

View File

@ -1,18 +1,18 @@
let () = print_endline "Arguments:"
let f1 ~x ~y = print_int (x + 2 * y)
let f1 ~x ~y = show_int (x + 2 * y)
let () = f1 0 1
let () = f1 ~x:0 ~y:1
let () = f1 ~y:1 ~x:0
let f2 ?(x=1) ~y = print_int (x + 2 * y)
let f2 ?(x=1) ~y = show_int (x + 2 * y)
let () = f2 100
let () = f2 ~y:101 (* Note: this is different from ocaml *)
let () = f2 ?x:None ~y:102
let () = f2 ?x:(Some 0) ~y:103
let () = f2 ~x:0 ~y:104
let f3 () ?(x=1) (y1, y2) ~z = print_int x; print_int y1; print_int y2; print_int z
let f3 () ?(x=1) (y1, y2) ~z = show_int x; show_int y1; show_int y2; show_int z
let () = f3 () (2, 3) ~z:4
let () = f3 () ~x:0 (1, 2) ~z:3

View File

@ -1 +1 @@
Bytecode size: 4282 bytes
Bytecode size: 4412 bytes

View File

@ -6,10 +6,10 @@ module M = struct
end
let () =
print_int M.x;
M.(print_int x);
show_int M.x;
M.(show_int x);
let open M in
print_int (f 21)
show_int (f 21)
module N = struct
let f ~x ?(y=2) p = p (x * y)
@ -17,6 +17,6 @@ end
let () =
let open N in
f ~x:21 print_int
f ~x:21 show_int
let () = print_newline ()

View File

@ -34,17 +34,17 @@ let stdout = caml_ml_open_descriptor_out 1
let flush () = caml_ml_flush stdout
let print s = caml_ml_output stdout s 0 (caml_ml_bytes_length s)
let print_int n = print (format_int " %d" n)
let print_string s = caml_ml_output stdout s 0 (caml_ml_bytes_length s)
let print_int n = print_string (format_int "%d" n)
let show_int n = print_string " "; print_int n
let print_newline () =
print "\n";
print_string "\n";
flush ()
let print_endline s =
print s ;
print "\n" ;
print_string s ;
print_string "\n" ;
flush ()
(* various types used in the tests *)

View File

@ -1 +1 @@
Bytecode size: 6383 bytes
Bytecode size: 6513 bytes

View File

@ -7,7 +7,7 @@ let rec iter f l =
f x; iter f l
let print_list l =
print "["; iter print_int l; print "]"
print_string "["; iter show_int l; print_string "]"
let () = print_list [1; 2; 3; 4; 5; 6; 7; 8; 9]
@ -26,7 +26,7 @@ let rec iter_sep f sep l =
f x; sep (); iter_sep f sep l
let print_list l =
print "["; iter_sep print_int (fun () -> print ";") l; print "]"
print_string "["; iter_sep show_int (fun () -> print_string ";") l; print_string "]"
let () = print_list [1; 2; 3; 4; 5; 6; 7; 8; 9]

View File

@ -1 +1 @@
Bytecode size: 11507 bytes
Bytecode size: 11637 bytes

View File

@ -1,12 +1,12 @@
let () = print_endline "Pattern-matching:"
let () = print "simple: "
let () = print_string "simple: "
let () =
print_int (match [] with [] -> 2 | x :: l -> 3)
show_int (match [] with [] -> 2 | x :: l -> 3)
let () =
print_int (match 1 :: [] with
show_int (match 1 :: [] with
| [] -> 2 (* note: leading bar *)
| _ :: _ -> 3
)
@ -16,7 +16,7 @@ let test_function = function
| x :: _ -> x + 1 (* note: one of the pattern arguments is a wildcard *)
let () =
print_int (test_function (3 :: []))
show_int (test_function (3 :: []))
type 'a tree =
| Empty
@ -24,21 +24,21 @@ type 'a tree =
| Node of 'a tree * 'a tree
let () =
print_int (match Node (Leaf 1, Leaf 2) with
show_int (match Node (Leaf 1, Leaf 2) with
| Empty -> 4
| Leaf _ -> 4
| Node _ -> 5 (* note: a single wildcard for several arguments *)
)
let () = print_newline ()
let () = print "irrefutable patterns in let-bindings: "
let () = print_string "irrefutable patterns in let-bindings: "
let () = print_int (
let () = show_int (
let (a, b) = (2, 3) in b - a
)
let () = print_newline ()
let () = print "nested patterns: "
let () = print_string "nested patterns: "
let test_nested_patterns =
match Node(Leaf 0, Node(Leaf 8, Node(Leaf 2, Empty))) with
@ -57,36 +57,36 @@ let test_nested_patterns =
| Node (Leaf _, Leaf _) -> 1
| _ -> 2)
let () = print_int test_nested_patterns
let () = show_int test_nested_patterns
let () = print_newline ()
let () = print "as-patterns: "
let () = print_string "as-patterns: "
let () = print_int (match (2, 3) with
let () = show_int (match (2, 3) with
| (_ as a, _) as p ->
let (_, b) = p in
b - a
)
let () = print_newline ()
let () = print "or-patterns: "
let () = print_string "or-patterns: "
(* toplevel ors, no parentheses *)
let () = print_int (match 1 with
let () = show_int (match 1 with
| 0 | 1 | 2 -> 1 (* no parentheses *)
| 3 | 4 -> 2
| 5 | _ -> 3
)
(* toplevel ors, with parentheses *)
let () = print_int (match 3 with
let () = show_int (match 3 with
| (0 | 1 | 2) -> 1
| (3 | 4) -> 2 (* parentheses *)
| 5 | _ -> 3
)
(* in-depth ors *)
let () = print_int (match (2, 3) with
let () = show_int (match (2, 3) with
| ((0 | 1), _) -> 1
| (2, (0 | 1)) -> 2
| (2, (2 | 3)) -> 3
@ -95,7 +95,7 @@ let () = print_int (match (2, 3) with
)
(* oring constant and non-constant patterns *)
let () = print_int (match Node (Empty, Empty) with
let () = show_int (match Node (Empty, Empty) with
| Empty | Leaf _ -> 0
| Node ((Empty | Leaf _), Node _) -> 1
| Node (_, (Empty | Leaf _)) -> 4
@ -103,21 +103,21 @@ let () = print_int (match Node (Empty, Empty) with
)
let () = print_newline ()
let () = print "record patterns"
let () = print_string "record patterns"
type ('a, 'b) t = { a : 'a; b : 'b }
let () = print_int (match { a = Empty; b = Leaf 1 } with
let () = show_int (match { a = Empty; b = Leaf 1 } with
| { a = (Leaf _ | Node _) } -> 0
| { b = (Empty | Node _) } -> 2
| { a = Empty; b = Leaf n } -> n
)
let () = print_newline ()
let () = print "when-guards"
let () = print_string "when-guards"
let () = print_int (match Node (Leaf 2, Leaf 2) with
| Node _ when (print_int 1; false) -> 0
| Node (Leaf n, (Leaf _ | Empty)) when (print_int n; false) -> 0
let () = show_int (match Node (Leaf 2, Leaf 2) with
| Node _ when (show_int 1; false) -> 0
| Node (Leaf n, (Leaf _ | Empty)) when (show_int n; false) -> 0
| Node _ -> 3
| _ -> 4
)

View File

@ -1 +1 @@
Bytecode size: 5772 bytes
Bytecode size: 5902 bytes

View File

@ -1,45 +1,45 @@
let () = print_endline "Records:"
let () = print "simple: "
let () = print_string "simple: "
type t = { a : int ; b : int }
let () =
let u = { a = 5 ; b = 7 } in
print_int u.a; print_int u.b
show_int u.a; show_int u.b
let () =
let u = { b = 5 ; a = 7 } in
print_int u.a; print_int u.b
show_int u.a; show_int u.b
let () = print_newline ()
let () = print "with: "
let () = print_string "with: "
let () =
let u = { a = 5 ; b = 7 } in
let v = { u with a = 42 } in
let w = { u with b = 16 } in
print_int u.a; print_int u.b;
print_int v.a; print_int v.b;
print_int w.a; print_int w.b
show_int u.a; show_int u.b;
show_int v.a; show_int v.b;
show_int w.a; show_int w.b
let () = print_newline ()
let () = print "record field punning: "
let () = print_string "record field punning: "
let () =
let u = let a, b = 1, 2 in { a; b } in
match u with
| {a; b} -> print_int a; print_int b
| {a; b} -> show_int a; show_int b
let () = print_newline ()
let () = print "inline records: "
let () = print_string "inline records: "
type t =
| A of { x : int; y : int; u : int }
| B of { z : int }
let print_t = function
| A { x; u } -> print_int x; print_int u (* note: field y is ignored *)
| B { z = name } -> print_int name
| A { x; u } -> show_int x; show_int u (* note: field y is ignored *)
| B { z = name } -> show_int name
let rec loop = function
| [] -> ()