diff --git a/tests/hard_coded/merge_and_remove_dups.m b/tests/hard_coded/merge_and_remove_dups.m index fb3dccd26..cfcc83942 100644 --- a/tests/hard_coded/merge_and_remove_dups.m +++ b/tests/hard_coded/merge_and_remove_dups.m @@ -2,9 +2,10 @@ % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% % -% A regression test. Make sure list__merge_and_remove_dups works. +% A regression test. Make sure list.merge_and_remove_dups works. % The Mercury library of September 15th, 1998 failed this test. % Peter Herkenrath sent this one in. +% :- module merge_and_remove_dups. @@ -12,28 +13,28 @@ :- import_module io. -:- pred main(io.state::di, io.state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. :- import_module list. -main --> - { - List1 = [1, 2, 3], - List2 = [3, 4, 5], - P = (pred(I1::in, I2::in, R::out) is det :- +main(!IO) :- + List1 = [1, 2, 3], + List2 = [3, 4, 5], + P = + ( pred(I1::in, I2::in, R::out) is det :- compare(R, I1, I2) ), - list__merge_and_remove_dups(P, List1, List2, List3) - }, - io__write_string("List1: "), - io__print(List1), - io__write_string("\nList2: "), - io__print(List2), - io__write_string("\nList3: "), - io__print(List3), - io__write_string("\n"). + list.merge_and_remove_dups(P, List1, List2, List3), + + io.write_string("List1: ", !IO), + io.print(List1, !IO), + io.write_string("\nList2: ", !IO), + io.print(List2, !IO), + io.write_string("\nList3: ", !IO), + io.print(List3, !IO), + io.write_string("\n", !IO). % Output: % List1: [1, 2, 3] diff --git a/tests/hard_coded/mode_check_clauses.m b/tests/hard_coded/mode_check_clauses.m index 063500a62..990fa79e0 100644 --- a/tests/hard_coded/mode_check_clauses.m +++ b/tests/hard_coded/mode_check_clauses.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module mode_check_clauses. :- interface. @@ -20,15 +20,15 @@ main(!IO) :- solutions(test02_pragma, Pragma02), solutions(test11_base(1), Base11), solutions(test11_pragma(1), Pragma11), - ( Base02 = Pragma02 -> - io__write_string("02 test works\n", !IO) - ; - io__write_string("02 test doesn't work\n", !IO) + ( if Base02 = Pragma02 then + io.write_string("02 test works\n", !IO) + else + io.write_string("02 test doesn't work\n", !IO) ), - ( Base11 = Pragma11 -> - io__write_string("11 test works\n", !IO) - ; - io__write_string("11 test doesn't work\n", !IO) + ( if Base11 = Pragma11 then + io.write_string("11 test works\n", !IO) + else + io.write_string("11 test doesn't work\n", !IO) ). :- pred test02_base(pair(int)::out) is multi. diff --git a/tests/hard_coded/mode_choice.m b/tests/hard_coded/mode_choice.m index c8b3a4019..afb6fbad0 100644 --- a/tests/hard_coded/mode_choice.m +++ b/tests/hard_coded/mode_choice.m @@ -6,7 +6,7 @@ :- interface. :- import_module io. -:- pred main(state::di, state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. @@ -14,47 +14,47 @@ #include ""mercury_string.h"" "). -main --> - ( { test1("foo", T0, T0b) } -> - print("T0: "), print(T0), nl, - print("T0b: "), print(T0b), nl - ; - print("test1: failed") +main(!IO) :- + ( if test1("foo", T0, T0b) then + print("T0: ", !IO), print(T0, !IO), nl(!IO), + print("T0b: ", !IO), print(T0b, !IO), nl(!IO) + else + print("test1: failed", !IO) ), - ( { test1("foo", "fooie", T1) } -> - print("T1: "), print(T1), nl - ; - print("test1: failed") + ( if test1("foo", "fooie", T1) then + print("T1: ", !IO), print(T1, !IO), nl(!IO) + else + print("test1: failed", !IO) ), - { test2("bar", T2) }, - print("T2: "), print(T2), nl, - { Z = "z" }, - { test2(Z, T3) }, - print("T3: "), print(T3), nl, - { test2(Z, T4) }, - print("T4: "), print(T4), nl, - { mkany(Any) }, - { test3(Any, T5) }, - print("T5: "), print(T5), nl, - { test3(_, T6) }, - print("T6: "), print(T6), nl, - ( { test4("", "", T7) } -> - print("T7: "), print(T7), nl - ; - print("T7 failed\n") + test2("bar", T2), + print("T2: ", !IO), print(T2, !IO), nl(!IO), + Z = "z", + test2(Z, T3), + print("T3: ", !IO), print(T3, !IO), nl(!IO), + test2(Z, T4), + print("T4: ", !IO), print(T4, !IO), nl(!IO), + mkany(Any), + test3(Any, T5), + print("T5: ", !IO), print(T5, !IO), nl(!IO), + test3(_, T6), + print("T6: ", !IO), print(T6, !IO), nl(!IO), + ( if test4("", "", T7) then + print("T7: ", !IO), print(T7, !IO), nl(!IO) + else + print("T7 failed\n", !IO) ), - { test4("", T8, T9) }, - print("T8: "), print(T8), nl, - print("T9: "), print(T9), nl, - { test4(T10, "", T11) }, - print("T10: "), print(T10), nl, - print("T11: "), print(T11), nl, - { test5("a", "b", T12) }, - print("T12: "), print(T12), nl, - { test5("a", "a", T13) }, - print("T13: "), print(T13), nl, - { test5("b", "b", T14) }, - print("T14: "), print(T14), nl. + test4("", T8, T9), + print("T8: ", !IO), print(T8, !IO), nl(!IO), + print("T9: ", !IO), print(T9, !IO), nl(!IO), + test4(T10, "", T11), + print("T10: ", !IO), print(T10, !IO), nl(!IO), + print("T11: ", !IO), print(T11, !IO), nl(!IO), + test5("a", "b", T12), + print("T12: ", !IO), print(T12, !IO), nl(!IO), + test5("a", "a", T13), + print("T13: ", !IO), print(T13, !IO), nl(!IO), + test5("b", "b", T14), + print("T14: ", !IO), print(T14, !IO), nl(!IO). % prefer `in' to `out' diff --git a/tests/hard_coded/multi_map_test.m b/tests/hard_coded/multi_map_test.m index 209208c72..6f46c129f 100644 --- a/tests/hard_coded/multi_map_test.m +++ b/tests/hard_coded/multi_map_test.m @@ -29,12 +29,12 @@ main(!IO) :- % ( if multi_map.is_empty(EmptyMap) then io.write_string("PASSED: is_empty(EmptyMap) succeeded\n", !IO) - else + else io.write_string("FAILED: is_empty(EmptyMap) failed\n", !IO) ), ( if multi_map.is_empty(Map) then io.write_string("FAILED: is_empty(Map) succeeded\n", !IO) - else + else io.write_string("PASSED: is_empty(Map) failed\n", !IO) ), @@ -51,7 +51,7 @@ main(!IO) :- io.write_string("insert/4 (test 1): PASSED: ", !IO), io.write(AL2, !IO), io.nl(!IO) - else + else io.write_string("insert/4 test 1): FAILED\n", !IO) ), @@ -60,7 +60,7 @@ main(!IO) :- io.write_string("insert/4 (test 2) FAILED: ", !IO), io.write(AL3, !IO), io.nl(!IO) - else + else io.write_string("insert/4 (test 2) PASSED\n", !IO) ), @@ -77,7 +77,7 @@ main(!IO) :- io.write_string("update/4 (test 1): PASSED: ", !IO), io.write(UAL1, !IO), io.nl(!IO) - else + else io.write_string("update/4 (test 1): FAILED\n", !IO) ), @@ -86,7 +86,7 @@ main(!IO) :- io.write_string("update/4 (test 2): FAILED: ", !IO), io.write(UAL2, !IO), io.nl(!IO) - else + else io.write_string("update/4 (test 2): PASSED\n", !IO) ), @@ -103,7 +103,7 @@ main(!IO) :- io.write_string("replace/4 (test 1): PASSED: ", !IO), io.write(RAL1, !IO), io.nl(!IO) - else + else io.write_string("replace/4 (test 1): FAILED\n", !IO) ), @@ -112,7 +112,7 @@ main(!IO) :- io.write_string("replace/4 (test 2): FAILED: ", !IO), io.write(RAL2, !IO), io.nl(!IO) - else + else io.write_string("replace/4 (test 2): PASSED\n", !IO) ), diff --git a/tests/hard_coded/multimode.m b/tests/hard_coded/multimode.m index 5b610c5e8..d522fd4ec 100644 --- a/tests/hard_coded/multimode.m +++ b/tests/hard_coded/multimode.m @@ -1,40 +1,40 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module multimode. :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. :- pragma promise_pure(main/2). -main --> - { In = 42 }, - { In2 = In }, % this line (and the use of `In2' below, - % rather than `In') is needed to avoid - % triggering an unrelated bug -- see - % tests/valid/mode_selection.m. +main(!IO) :- + In = 42, + In2 = In, % this line (and the use of `In2' below, + % rather than `In') is needed to avoid + % triggering an unrelated bug -- see + % tests/valid/mode_selection.m. % test pure functions - print(func0), nl, - print(func1(In)), nl, - print(func1(_Out0)), nl, - print(func2(In, In2)), nl, - print(func2(In, _Out1)), nl, - print(func2(_Out2, In)), nl, - print(func2(_Out3, _Out4)), nl, + print_line(func0, !IO), + print_line(func1(In), !IO), + print_line(func1(_Out0), !IO), + print_line(func2(In, In2), !IO), + print_line(func2(In, _Out1), !IO), + print_line(func2(_Out2, In), !IO), + print_line(func2(_Out3, _Out4), !IO), % test impure predicates - { impure test0 }, - { impure test1(In) }, - { impure test1(_Out10) }, - { impure test2(In, In) }, - { impure test2(In, _Out11) }, - { impure test2(_Out12, In) }, - { impure test2(_Out13, _Out14) }. + impure test0, + impure test1(In), + impure test1(_Out10), + impure test2(In, In), + impure test2(In, _Out11), + impure test2(_Out12, In), + impure test2(_Out13, _Out14). :- func func0 = string. :- mode func0 = out is det. diff --git a/tests/hard_coded/multimode_addr.m b/tests/hard_coded/multimode_addr.m index 30289ac35..93e684c87 100644 --- a/tests/hard_coded/multimode_addr.m +++ b/tests/hard_coded/multimode_addr.m @@ -31,10 +31,10 @@ main(!IO) :- !:IO = my_foldl(echo, ["a", "b", "c"], !.IO), io.write_string("\nTEST 3\n", !IO), - ( RevB = my_foldl(maybe_cons, 1 .. 5, []) -> + ( if RevB = my_foldl(maybe_cons, 1 .. 5, []) then io.write(RevB, !IO), io.nl(!IO) - ; + else io.write_string("found a multiple of three\n", !IO) ). diff --git a/tests/hard_coded/mutable_decl.m b/tests/hard_coded/mutable_decl.m index 58e21bb99..cca42621c 100644 --- a/tests/hard_coded/mutable_decl.m +++ b/tests/hard_coded/mutable_decl.m @@ -16,7 +16,7 @@ :- import_module io. -:- impure pred main(io :: di, io :: uo) is cc_multi. +:- impure pred main(io::di, io::uo) is cc_multi. %---------------------------------------------------------------------------% %---------------------------------------------------------------------------% diff --git a/tests/hard_coded/mutable_excp.m b/tests/hard_coded/mutable_excp.m index 7f0446722..5096d0b0a 100644 --- a/tests/hard_coded/mutable_excp.m +++ b/tests/hard_coded/mutable_excp.m @@ -41,9 +41,9 @@ init_foo = X :- :- func init_bar = int. init_bar = - ( get_magic_number(3) -> + ( if get_magic_number(3) then throw(magic_number_exception) - ; + else 561 ). @@ -58,13 +58,14 @@ init_baz = X :- :- pred get_string(int::in, string::out) is det. get_string(X, Str) :- - ( X = 561 -> + ( if X = 561 then throw(magic_number_exception) - ; + else Str = "not 561" ). -:- type magic_number_exception ---> magic_number_exception. +:- type magic_number_exception + ---> magic_number_exception. :- pred get_magic_number(int::out) is det. diff --git a/tests/hard_coded/myset.m b/tests/hard_coded/myset.m index 713c62bc1..596c8867b 100644 --- a/tests/hard_coded/myset.m +++ b/tests/hard_coded/myset.m @@ -33,7 +33,7 @@ % :- mode [in | in] = out is det. :- mode [out | out] = in is cc_nondet. -:- pred print_myset_rep(set(T)::in, io__state::di, io__state::uo) is cc_multi. +:- pred print_myset_rep(set(T)::in, io::di, io::uo) is cc_multi. :- implementation. @@ -53,44 +53,50 @@ set(List) = set_rep(List). set_to_list(set_rep(List), List). set_to_sorted_list(Set) = - promise_only_solution((pred(Sorted::out) is cc_multi :- - Set = set_rep(Unsorted), - list__sort(Unsorted, Sorted) - )). + promise_only_solution( + ( pred(Sorted::out) is cc_multi :- + Set = set_rep(Unsorted), + list.sort(Unsorted, Sorted) + ) + ). {} = set_rep([]). {X} = set_rep([X]). is_empty(Set) :- - promise_only_solution((pred(Empty::out) is cc_multi :- - Set = set_rep(List), - Empty = (if List = [] then yes else no) - )) = yes. + promise_only_solution( + ( pred(Empty::out) is cc_multi :- + Set = set_rep(List), + Empty = (if List = [] then yes else no) + ) + ) = yes. Set1 + Set2 = - promise_only_solution((pred(Union::out) is cc_multi :- - Set1 = set_rep(List1), - Set2 = set_rep(List2), - list__append(List1, List2, UnionList), - Union = set_rep(UnionList) - )). + promise_only_solution( + ( pred(Union::out) is cc_multi :- + Set1 = set_rep(List1), + Set2 = set_rep(List2), + list.append(List1, List2, UnionList), + Union = set_rep(UnionList) + ) + ). % [Element | set_rep(Rest)] = set_rep([Element | Rest]). [Element | set_rep(Rest)] = UnionSet :- - ( is_empty(UnionSet) -> + ( if is_empty(UnionSet) then fail - ; + else UnionSet = set_rep(UnionList), - ( UnionList = [Element1 | Rest1] -> + ( if UnionList = [Element1 | Rest1] then Element = Element1, Rest = Rest1 - ; + else error("unexpected non-empty list") ) ). -print_myset_rep(set_rep(List)) --> - print("set_rep("), - print(List), - print(")"). +print_myset_rep(set_rep(List), !IO) :- + print("set_rep(", !IO), + print(List, !IO), + print(")", !IO). diff --git a/tests/hard_coded/myset_test.m b/tests/hard_coded/myset_test.m index cae00ca81..fa3f57ce9 100644 --- a/tests/hard_coded/myset_test.m +++ b/tests/hard_coded/myset_test.m @@ -1,37 +1,41 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% -% "Hello World" in Mercury. :- module myset_test. :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is cc_multi. +:- pred main(io::di, io::uo) is cc_multi. :- implementation. :- import_module myset. :- import_module list. -main --> - print_myset_rep({1}), nl, - print_myset_rep({1} + {2}), nl, - print_myset_rep({2} + {1}), nl, - ( { {1} + {2} = [First | Rest] } -> - print(First), print("+"), print_myset_rep(Rest), nl - ; - print("failed\n") +main(!IO) :- + print_myset_rep({1}, !IO), nl(!IO), + print_myset_rep({1} + {2}, !IO), nl(!IO), + print_myset_rep({2} + {1}, !IO), nl(!IO), + ( if {1} + {2} = [First | Rest] then + print(First, !IO), + print("+", !IO), + print_myset_rep(Rest, !IO), + nl(!IO) + else + print("failed\n", !IO) ), - ( { {2} + {1} = [First2 | Rest2] } -> - print(First2), print("+"), print_myset_rep(Rest2), nl - ; - print("failed\n") + ( if {2} + {1} = [First2 | Rest2] then + print(First2, !IO), + print("+", !IO), + print_myset_rep(Rest2, !IO), + nl(!IO) + else + print("failed\n", !IO) ), - { S1 = {3} + {4} }, - { S2 = {4} + {3} }, - ( { append([S1], [S2], [S2, S1]) } -> - print("yes"), nl - ; - print("no"), nl + S1 = {3} + {4}, + S2 = {4} + {3}, + ( if append([S1], [S2], [S2, S1]) then + print_line("yes", !IO) + else + print_line("no", !IO) ). diff --git a/tests/hard_coded/random_permutation.m b/tests/hard_coded/random_permutation.m index a0460a1a4..804530e61 100644 --- a/tests/hard_coded/random_permutation.m +++ b/tests/hard_coded/random_permutation.m @@ -6,7 +6,7 @@ :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. @@ -14,38 +14,34 @@ :- import_module list. :- import_module random. -main --> - { List = gen_sorted_list(1, 100) }, - { random__init(1, RS) }, - do_tests(List, 10, RS). +main(!IO) :- + List = gen_sorted_list(1, 100), + random.init(1, RS), + do_tests(List, 10, RS, !IO). -:- pred do_tests(list(int), int, random__supply, io__state, io__state). -:- mode do_tests(in, in, mdi, di, uo) is det. +:- pred do_tests(list(int)::in, int::in, random.supply::mdi, + io::di, io::uo) is det. -do_tests(List, Count, RS0) --> - ( - { Count > 1 } - -> - { random__permutation(List, Perm, RS0, RS1) }, - { list__sort_and_remove_dups(Perm, SortedList) }, - ( - { SortedList = List } - -> - io__write_string("Test passed.\n") - ; - io__write_string("Test failed!\n") +do_tests(List, Count, RS0, !IO) :- + ( if Count > 1 then + random.permutation(List, Perm, RS0, RS1), + list.sort_and_remove_dups(Perm, SortedList), + ( if SortedList = List then + io.write_string("Test passed.\n", !IO) + else + io.write_string("Test failed!\n", !IO) ), - do_tests(List, Count - 1, RS1) - ; - [] + do_tests(List, Count - 1, RS1, !IO) + else + true ). :- func gen_sorted_list(int, int) = list(int). gen_sorted_list(M, N) = - ( M > N -> + ( if M > N then [] - ; + else [M | gen_sorted_list(M + 1, N)] ). diff --git a/tests/hard_coded/random_simple.m b/tests/hard_coded/random_simple.m index bfcea3ff7..04d5f8aa9 100644 --- a/tests/hard_coded/random_simple.m +++ b/tests/hard_coded/random_simple.m @@ -6,35 +6,31 @@ :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. :- import_module int. :- import_module random. -main --> - { Seed = 3 }, - { random__init(Seed, RS0) }, - test(1, 20, RS0, RS1), - test(-1, 20, RS1, _). +main(!IO) :- + Seed = 3, + random.init(Seed, RS0), + test(1, 20, RS0, RS1, !IO), + test(-1, 20, RS1, _, !IO). -:- pred test(int::in, int::in, random__supply::mdi, random__supply::muo, - io__state::di, io__state::uo) is det. +:- pred test(int::in, int::in, random.supply::mdi, random.supply::muo, + io::di, io::uo) is det. -test(Range, Count, RS0, RS) --> - ( - { Count > 0 } - -> - { random__random(0, Range, N, RS0, RS1) }, - ( - { N = 0 } - -> - test(Range, Count - 1, RS1, RS) - ; - io__write_string("Test failed.\n"), - { RS = RS1 } +test(Range, Count, RS0, RS, !IO) :- + ( if Count > 0 then + random.random(0, Range, N, RS0, RS1), + ( if N = 0 then + test(Range, Count - 1, RS1, RS, !IO) + else + io.write_string("Test failed.\n", !IO), + RS = RS1 ) - ; - io__write_string("Test passed.\n"), - { RS = RS0 } + else + io.write_string("Test passed.\n", !IO), + RS = RS0 ). diff --git a/tests/hard_coded/read_binary_int16.m b/tests/hard_coded/read_binary_int16.m index 4579a75fe..b7a7defe6 100644 --- a/tests/hard_coded/read_binary_int16.m +++ b/tests/hard_coded/read_binary_int16.m @@ -92,8 +92,8 @@ run_test(ByteOrder, TestBytes, !IO) :- io.write_string(")\n", !IO) ; ReadResult = error(IO_Error), - io.format("Result: Error (%s)\n", [s(io.error_message(IO_Error))], - !IO) + io.format("Result: Error (%s)\n", + [s(io.error_message(IO_Error))], !IO) ), io.remove_file(test_file, _, !IO) ; diff --git a/tests/hard_coded/read_binary_int32.m b/tests/hard_coded/read_binary_int32.m index b901a0758..62150039b 100644 --- a/tests/hard_coded/read_binary_int32.m +++ b/tests/hard_coded/read_binary_int32.m @@ -87,8 +87,8 @@ run_test(ByteOrder, TestBytes, !IO) :- io.write_string(")\n", !IO) ; ReadResult = error(IO_Error), - io.format("Result: Error (%s)\n", [s(io.error_message(IO_Error))], - !IO) + io.format("Result: Error (%s)\n", + [s(io.error_message(IO_Error))], !IO) ), io.remove_file(test_file, _, !IO) ; diff --git a/tests/hard_coded/read_binary_int64.m b/tests/hard_coded/read_binary_int64.m index 59cdede52..93b3e3a68 100644 --- a/tests/hard_coded/read_binary_int64.m +++ b/tests/hard_coded/read_binary_int64.m @@ -46,9 +46,11 @@ run_test(ByteOrder, TestBytes, !IO) :- TestBytes = [Byte1, Byte2, Byte3, Byte4, Byte5, Byte6, Byte7, Byte8] then io.write_string(" (LE: ", !IO), - io.write_int64(from_bytes_le(Byte1, Byte2, Byte3, Byte4, Byte5, Byte6, Byte7, Byte8), !IO), + io.write_int64(from_bytes_le(Byte1, Byte2, Byte3, Byte4, + Byte5, Byte6, Byte7, Byte8), !IO), io.write_string(") (BE: ", !IO), - io.write_int64(from_bytes_be(Byte1, Byte2, Byte3, Byte4, Byte5, Byte6, Byte7, Byte8), !IO), + io.write_int64(from_bytes_be(Byte1, Byte2, Byte3, Byte4, + Byte5, Byte6, Byte7, Byte8), !IO), io.write_string(")\n", !IO) else io.nl(!IO) @@ -89,8 +91,8 @@ run_test(ByteOrder, TestBytes, !IO) :- io.write_string(")\n", !IO) ; ReadResult = error(IO_Error), - io.format("Result: Error (%s)\n", [s(io.error_message(IO_Error))], - !IO) + io.format("Result: Error (%s)\n", + [s(io.error_message(IO_Error))], !IO) ), io.remove_file(test_file, _, !IO) ; diff --git a/tests/hard_coded/read_binary_uint16.m b/tests/hard_coded/read_binary_uint16.m index ae72f5cdb..4a4c76536 100644 --- a/tests/hard_coded/read_binary_uint16.m +++ b/tests/hard_coded/read_binary_uint16.m @@ -92,8 +92,8 @@ run_test(ByteOrder, TestBytes, !IO) :- io.write_string(")\n", !IO) ; ReadResult = error(IO_Error), - io.format("Result: Error (%s)\n", [s(io.error_message(IO_Error))], - !IO) + io.format("Result: Error (%s)\n", + [s(io.error_message(IO_Error))], !IO) ), io.remove_file(test_file, _, !IO) ; diff --git a/tests/hard_coded/read_binary_uint32.m b/tests/hard_coded/read_binary_uint32.m index 810331713..ecf63262b 100644 --- a/tests/hard_coded/read_binary_uint32.m +++ b/tests/hard_coded/read_binary_uint32.m @@ -87,8 +87,8 @@ run_test(ByteOrder, TestBytes, !IO) :- io.write_string(")\n", !IO) ; ReadResult = error(IO_Error), - io.format("Result: Error (%s)\n", [s(io.error_message(IO_Error))], - !IO) + io.format("Result: Error (%s)\n", + [s(io.error_message(IO_Error))], !IO) ), io.remove_file(test_file, _, !IO) ; diff --git a/tests/hard_coded/read_binary_uint64.m b/tests/hard_coded/read_binary_uint64.m index 04c31404e..2119ddccf 100644 --- a/tests/hard_coded/read_binary_uint64.m +++ b/tests/hard_coded/read_binary_uint64.m @@ -46,9 +46,11 @@ run_test(ByteOrder, TestBytes, !IO) :- TestBytes = [Byte1, Byte2, Byte3, Byte4, Byte5, Byte6, Byte7, Byte8] then io.write_string(" (LE: ", !IO), - io.write_uint64(from_bytes_le(Byte1, Byte2, Byte3, Byte4, Byte5, Byte6, Byte7, Byte8), !IO), + io.write_uint64(from_bytes_le(Byte1, Byte2, Byte3, Byte4, + Byte5, Byte6, Byte7, Byte8), !IO), io.write_string(") (BE: ", !IO), - io.write_uint64(from_bytes_be(Byte1, Byte2, Byte3, Byte4, Byte5, Byte6, Byte7, Byte8), !IO), + io.write_uint64(from_bytes_be(Byte1, Byte2, Byte3, Byte4, + Byte5, Byte6, Byte7, Byte8), !IO), io.write_string(")\n", !IO) else io.nl(!IO) @@ -89,8 +91,8 @@ run_test(ByteOrder, TestBytes, !IO) :- io.write_string(")\n", !IO) ; ReadResult = error(IO_Error), - io.format("Result: Error (%s)\n", [s(io.error_message(IO_Error))], - !IO) + io.format("Result: Error (%s)\n", + [s(io.error_message(IO_Error))], !IO) ), io.remove_file(test_file, _, !IO) ; diff --git a/tests/hard_coded/setenv.m b/tests/hard_coded/setenv.m index d2ec6349e..457b0f75e 100644 --- a/tests/hard_coded/setenv.m +++ b/tests/hard_coded/setenv.m @@ -1,3 +1,7 @@ +%---------------------------------------------------------------------------% +% vim: ts=4 sw=4 et ft=mercury +%---------------------------------------------------------------------------% + :- module setenv. :- interface. diff --git a/tests/hard_coded/setjmp_test.m b/tests/hard_coded/setjmp_test.m index 96be29f7c..6ad58c529 100644 --- a/tests/hard_coded/setjmp_test.m +++ b/tests/hard_coded/setjmp_test.m @@ -7,22 +7,25 @@ % which had undefined behaviour according to ANSI/ISO C, % and which would in practice fail on some systems % (e.g. alpha*-dec-osf3.2 with egcs-1.1.2). +% :- module setjmp_test. :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is cc_multi. +:- pred main(io::di, io::uo) is cc_multi. :- implementation. :- import_module std_util. -main --> - (if { p(X) } then - print("X = "), print(X), nl - ; - print("no") +main(!IO) :- + ( if p(X) then + print("X = ", !IO), + print(X, !IO), + nl(!IO) + else + print("no", !IO) ). :- pragma inline(p/1). diff --git a/tests/hard_coded/sharing_comb.m b/tests/hard_coded/sharing_comb.m index da14de4c5..f88359d08 100644 --- a/tests/hard_coded/sharing_comb.m +++ b/tests/hard_coded/sharing_comb.m @@ -4,6 +4,7 @@ % % Regression test for bug which showed up when --structure-sharing-widening % was used. +% :- module sharing_comb. :- interface. @@ -12,7 +13,6 @@ :- pred main(io::di, io::uo) is det. -%---------------------------------------------------------------------------% %---------------------------------------------------------------------------% :- implementation. @@ -111,7 +111,7 @@ main(!IO) :- io.write(RP, !IO), io.nl(!IO), - ( find_intersection(RP, _, Surface) -> + ( if find_intersection(RP, _, Surface) then io.write_string("Surface = ", !IO), io.write(Surface, !IO), io.nl(!IO), @@ -122,7 +122,7 @@ main(!IO) :- io.write_string("NewSurface = ", !IO), io.write(NewSurface, !IO), io.nl(!IO) - ; + else io.write_string("find_intersection failed!\n", !IO) ), diff --git a/tests/hard_coded/simplify_multi_arm_switch.m b/tests/hard_coded/simplify_multi_arm_switch.m index 63dfc42c5..ae1415b4d 100644 --- a/tests/hard_coded/simplify_multi_arm_switch.m +++ b/tests/hard_coded/simplify_multi_arm_switch.m @@ -6,6 +6,7 @@ % Previously a singleton switch could be replaced by the case goal, possibly % with a functor test beforehand, but that's only true if the case arm is % applicable to only a single functor. +% :- module simplify_multi_arm_switch. :- interface. @@ -45,8 +46,8 @@ squishy(Fruit) :- IsSquishy = yes. main(!IO) :- - ( squishy(apple) -> + ( if squishy(apple) then io.write_string("bug!\n", !IO) - ; + else io.write_string("ok\n", !IO) ). diff --git a/tests/hard_coded/singleton_dups.m b/tests/hard_coded/singleton_dups.m index 97e120414..a9924eea2 100644 --- a/tests/hard_coded/singleton_dups.m +++ b/tests/hard_coded/singleton_dups.m @@ -5,6 +5,7 @@ % Regression test for a problem in Mercury 11.07 where checking whether % a set represented by an unordered list was singleton didn't account for % the representation containing duplicate elements. +% :- module singleton_dups. :- interface. @@ -25,7 +26,7 @@ main(!IO) :- io.write_string("Singleton with element ", !IO), io.write_int(X, !IO), io.nl(!IO) - else + else io.write_string("Not a singleton set\n", !IO) ) ), @@ -39,7 +40,7 @@ main(!IO) :- set_unordlist.insert(2, !Set2), ( if set_unordlist.singleton_set(2, !.Set2) then io.write_string("(in, in) test passed.\n", !IO) - else + else io.write_string("(in, in) test FAILED.\n", !IO) ) ). diff --git a/tests/hard_coded/solve_quadratic.m b/tests/hard_coded/solve_quadratic.m index 20e38f109..a04d688b4 100644 --- a/tests/hard_coded/solve_quadratic.m +++ b/tests/hard_coded/solve_quadratic.m @@ -1,78 +1,73 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module solve_quadratic. :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. :- import_module float. :- import_module math. -main --> +main(!IO) :- % Two roots (i.e. B^2 > 4AC) - check_quad(1.0, 3.0, -2.0), - check_quad(1.0, -5.0, 3.0), - check_quad(2.0, -5.0, 3.0), - check_quad(2.0, -5.0, -6.0), - check_quad(-15.0, 68.0, 34.5), - check_quad(-4.0, -17.0, 3.5), + check_quad(1.0, 3.0, -2.0, !IO), + check_quad(1.0, -5.0, 3.0, !IO), + check_quad(2.0, -5.0, 3.0, !IO), + check_quad(2.0, -5.0, -6.0, !IO), + check_quad(-15.0, 68.0, 34.5, !IO), + check_quad(-4.0, -17.0, 3.5, !IO), % One root (i.e. B^2 = 4AC) - check_quad(5.0, 10.0, 5.0), - check_quad(4.0, -8.0, 4.0), - check_quad(-3.0, -18.0, -27.0), + check_quad(5.0, 10.0, 5.0, !IO), + check_quad(4.0, -8.0, 4.0, !IO), + check_quad(-3.0, -18.0, -27.0, !IO), % No roots (i.e. B^2 < 4AC) - check_quad(4.0, 3.0, 2.0), - check_quad(1.0, 1.0, 1.0), - check_quad(-1.0, -2.0, -2.0), + check_quad(4.0, 3.0, 2.0, !IO), + check_quad(1.0, 1.0, 1.0, !IO), + check_quad(-1.0, -2.0, -2.0, !IO), % Special cases - check_quad(1.0, -2.0, 0.0), - check_quad(1.0, 0.0, -2.0), - check_quad(2.0, 0.0, 0.0), - check_quad(-100.0, 0.0, 0.0001). + check_quad(1.0, -2.0, 0.0, !IO), + check_quad(1.0, 0.0, -2.0, !IO), + check_quad(2.0, 0.0, 0.0, !IO), + check_quad(-100.0, 0.0, 0.0001, !IO). -:- pred check_quad(float, float, float, io__state, io__state). -:- mode check_quad(in, in, in, di, uo) is det. +:- pred check_quad(float::in, float::in, float::in, io::di, io::uo) is det. -check_quad(A, B, C) --> - { Ss = solve_quadratic(A, B, C) }, +check_quad(A, B, C, !IO) :- + Ss = solve_quadratic(A, B, C), ( - { Ss = no_roots }, - io__write_string("No roots.\n") + Ss = no_roots, + io.write_string("No roots.\n", !IO) ; - { Ss = one_root(R) }, - io__write_string("One root: "), - check_result(A, B, C, R), - io__write_string(".\n") + Ss = one_root(R), + io.write_string("One root: ", !IO), + check_result(A, B, C, R, !IO), + io.write_string(".\n", !IO) ; - { Ss = two_roots(R1, R2) }, - io__write_string("Two roots: "), - check_result(A, B, C, R1), - io__write_string(", "), - check_result(A, B, C, R2), - io__write_string(".\n") + Ss = two_roots(R1, R2), + io.write_string("Two roots: ", !IO), + check_result(A, B, C, R1, !IO), + io.write_string(", ", !IO), + check_result(A, B, C, R2, !IO), + io.write_string(".\n", !IO) ). -:- pred check_result(float, float, float, float, io__state, io__state). -:- mode check_result(in, in, in, in, di, uo) is det. +:- pred check_result(float::in, float::in, float::in, float::in, + io::di, io::uo) is det. -check_result(A, B, C, R) --> - { Val = ((A * R + B) * R) + C }, - ( - % - % This test is pretty conservative, since I don't know - % how much error should be expected. - % - { abs(Val) < 1E-6 } - -> - io__write_string("ok") - ; - io__write_string("problem: Val = "), - io__write_float(Val) +check_result(A, B, C, R, !IO) :- + Val = ((A * R + B) * R) + C, + % This test is pretty conservative, since I don't know + % how much error should be expected. + ( if abs(Val) < 1E-6 then + io.write_string("ok", !IO) + else + io.write_string("problem: Val = ", !IO), + io.write_float(Val, !IO) ). diff --git a/tests/hard_coded/solver_build_call.m b/tests/hard_coded/solver_build_call.m index ed6944a13..b0862e37d 100644 --- a/tests/hard_coded/solver_build_call.m +++ b/tests/hard_coded/solver_build_call.m @@ -7,7 +7,7 @@ % Tue Oct 18 15:30:39 EST 2005 % % This detects a bug where modes.build_call was using out-of-date versions -% of the varset and vartypes and then overwriting these fields in the +% of the varset and vartypes, and then overwriting these fields in the % mode_info, leading to a compiler abort: % % Uncaught Mercury exception: @@ -21,7 +21,7 @@ :- import_module io. -:- pred main(io :: di, io :: uo) is det. +:- pred main(io::di, io::uo) is det. %---------------------------------------------------------------------------% %---------------------------------------------------------------------------% @@ -35,14 +35,13 @@ main(!IO) :- promise_pure ( - if - solve_problem(Solution) - then - io.print("solution found: ", !IO), - io.print(Solution, !IO), - io.nl(!IO) - else - io.print("no solution found\n", !IO) + ( if solve_problem(Solution) then + io.print("solution found: ", !IO), + io.print(Solution, !IO), + io.nl(!IO) + else + io.print("no solution found\n", !IO) + ) ). :- pred solve_problem(int::out) is semidet. diff --git a/tests/hard_coded/solver_default_eq_cmp.m b/tests/hard_coded/solver_default_eq_cmp.m index 85aed9733..a88258a21 100644 --- a/tests/hard_coded/solver_default_eq_cmp.m +++ b/tests/hard_coded/solver_default_eq_cmp.m @@ -30,9 +30,9 @@ main(!IO) :- io.write_string("equality predicate not called", !IO) ; EqResult = exception(EqExcp), - ( univ_to_type(EqExcp, software_error(EqErr)) -> + ( if univ_to_type(EqExcp, software_error(EqErr)) then io.write_string(EqErr ++ "\n", !IO) - ; + else io.write_string("unknown exception thrown\n", !IO) ) ), @@ -43,9 +43,9 @@ main(!IO) :- io.write_string("comparison predicate not called", !IO) ; CmpResult = exception(CmpExcp), - ( univ_to_type(CmpExcp, software_error(CmpErr)) -> + ( if univ_to_type(CmpExcp, software_error(CmpErr)) then io.write_string(CmpErr ++ "\n", !IO) - ; + else io.write_string("unknown exception thrown\n", !IO) ) ). @@ -61,9 +61,12 @@ test_eq(unit, !IO) :- :- pred write_solver_type_eq(T::ia, T::ia, io::di, io::uo) is det. write_solver_type_eq(X, Y, !IO) :- - promise_pure ( if X = Y - then io.write_string("Same\n", !IO) - else io.write_string("Different\n", !IO) + promise_pure ( + ( if X = Y then + io.write_string("Same\n", !IO) + else + io.write_string("Different\n", !IO) + ) ). :- pred test_cmp(unit::out, io::di, io::uo) is det. diff --git a/tests/hard_coded/solver_disj_inits.m b/tests/hard_coded/solver_disj_inits.m index e9f7d8b84..430ad2359 100644 --- a/tests/hard_coded/solver_disj_inits.m +++ b/tests/hard_coded/solver_disj_inits.m @@ -55,9 +55,9 @@ write_foo(Foo, !IO) :- :- func f(bar::in) = (foo::oa) is det. f(Bar) = Foo :- - ( Bar = a - ; Bar = b, Foo = foo(1) - ; Bar = c, Foo = foo(2) + ( Bar = a + ; Bar = b, Foo = foo(1) + ; Bar = c, Foo = foo(2) ). %---------------------------------------------------------------------------% diff --git a/tests/hard_coded/solver_ite_inits.m b/tests/hard_coded/solver_ite_inits.m index 31006c6c2..7bfad8f82 100644 --- a/tests/hard_coded/solver_ite_inits.m +++ b/tests/hard_coded/solver_ite_inits.m @@ -21,7 +21,7 @@ :- import_module io. -:- pred main(io :: di, io :: uo) is det. +:- pred main(io::di, io::uo) is det. %---------------------------------------------------------------------------% %---------------------------------------------------------------------------% @@ -51,7 +51,10 @@ write_foo(Foo, !IO) :- io.print(X, !IO), io.nl(!IO). -:- type bar ---> a ; b ; c. +:- type bar + ---> a + ; b + ; c. :- func f(bar::in) = (foo::oa) is det. f(Bar) = Foo :- diff --git a/tests/hard_coded/source_file_map.m b/tests/hard_coded/source_file_map.m index fc20a0e29..8cbac27a8 100644 --- a/tests/hard_coded/source_file_map.m +++ b/tests/hard_coded/source_file_map.m @@ -8,9 +8,9 @@ :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. -main --> - io__write_string("OK\n"). +main(!IO) :- + io.write_string("OK\n", !IO). diff --git a/tests/hard_coded/space.m b/tests/hard_coded/space.m index 785bb42e7..fe281fcea 100644 --- a/tests/hard_coded/space.m +++ b/tests/hard_coded/space.m @@ -4,7 +4,7 @@ % % A regression test: the Mercury compiler dated May 20 1997 % generated incorrect code for this program. - +% %---------------------------------------------------------------------------% % % space : an ambient music generator @@ -21,7 +21,7 @@ :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. %---------------------------------------------------------------------------% @@ -99,37 +99,37 @@ %---------------------------------------------------------------------------% -main --> - % io__command_line_arguments(Args0), - { Args0 = ["-k", "dM", "-l", "30", "-s", "1"] }, +main(!IO) :- + % io.command_line_arguments(Args0), + Args0 = ["-k", "dM", "-l", "30", "-s", "1"], - { getopt__process_options( - option_ops(short, long, defaults), Args0, _Args, MOptTable) }, + Ops = option_ops_multi(short, long, defaults), + getopt.process_options(Ops, Args0, _Args, MOptTable), ( - { MOptTable = error(String) }, - { string__format("bad option: %s\n", [s(String)], Msg) }, - io__stderr_stream(Stderr), - io__write_string(Stderr, Msg) + MOptTable = error(String), + string.format("bad option: %s\n", [s(String)], Msg), + io.stderr_stream(Stderr, !IO), + io.write_string(Stderr, Msg, !IO) ; - { MOptTable = ok(Opts) }, + MOptTable = ok(Opts), ( - { getopt__lookup_bool_option(Opts, help, yes) } + getopt.lookup_bool_option(Opts, help, yes) -> - help + help(!IO) ; - { getopt__lookup_string_option(Opts, key, KeyStr) }, - { figure_key(KeyStr, Note, Qual, Kind) } + getopt.lookup_string_option(Opts, key, KeyStr), + figure_key(KeyStr, Note, Qual, Kind) -> - { getopt__lookup_int_option(Opts, length, Len) }, - { getopt__lookup_int_option(Opts, seed, Seed) }, - { random_init(Seed, Rnd) }, - { Chord0 = chord(i, Kind, up(ii)) }, - doit(Len, Note, Qual, Chord0, Rnd) + getopt.lookup_int_option(Opts, length, Len), + getopt.lookup_int_option(Opts, seed, Seed), + random_init(Seed, Rnd), + Chord0 = chord(i, Kind, up(ii)), + doit(Len, Note, Qual, Chord0, Rnd, !IO) ; - { getopt__lookup_string_option(Opts, key, KeyStr) }, - { string__format("illegal key: `%s'\n", [s(KeyStr)], Msg) }, - io__stderr_stream(Stderr), - io__write_string(Stderr, Msg) + getopt.lookup_string_option(Opts, key, KeyStr), + string.format("illegal key: `%s'\n", [s(KeyStr)], Msg), + io.stderr_stream(Stderr, !IO), + io.write_string(Stderr, Msg, !IO) ) ). @@ -161,138 +161,112 @@ figure_key("a#M", note(a, sharp, 2), min, min). figure_key("b", note(b, natural, 2), maj, maj). figure_key("bM", note(b, natural, 2), min, min). -:- pred doit(int, note, qualifier, chord, random_supply, io__state, io__state). -:- mode doit(in, in, in, in, mdi, di, uo) is det. +:- pred doit(int::in, note::in, qualifier::in, chord::in, + random_supply::mdi, io::di, io::uo) is det. -doit(N, Trans, Qual, Chord0, Rnd0) --> - ( - { N =< 0 } - -> - [] - ; - { chord_notes(Chord0, Qual, Notes0) }, - { list__map(trans(Trans), Notes0, Notes) }, - write_chord(Notes), - ( - { random_random(I, Rnd0, Rnd) }, - { next_chord(Chord0, Qual, I, Chord1) } - -> - { N1 = N - 1 }, - doit(N1, Trans, Qual, Chord1, Rnd) - ; - io__write_string("next_chord failed\n") +doit(N, Trans, Qual, Chord0, Rnd0, !IO) :- + ( if + N =< 0 + then + true + else + chord_notes(Chord0, Qual, Notes0), + list.map(trans(Trans), Notes0, Notes), + write_chord(Notes, !IO), + ( if + random_random(I, Rnd0, Rnd), + next_chord(Chord0, Qual, I, Chord1) + then + doit(N - 1, Trans, Qual, Chord1, Rnd, !IO) + else + io.write_string("next_chord failed\n", !IO) ) ). -:- pred write_chord(list(note), io__state, io__state). -:- mode write_chord(in, di, uo) is det. +:- pred write_chord(list(note)::in, io::di, io::uo) is det. -write_chord([]) --> io__nl. -write_chord([Note]) --> - { Note = note(Rank, Mod, Oct) }, - write_note(Rank, Mod, Oct), - io__nl. -write_chord([Note | Notes]) --> - { Notes = [_ | _] }, - { Note = note(Rank, Mod, Oct) }, - write_note(Rank, Mod, Oct), - io__write_string(" "), - write_chord(Notes). +write_chord([], !IO) :- + io.nl(!IO). +write_chord([Note], !IO) :- + Note = note(Rank, Mod, Oct), + write_note(Rank, Mod, Oct, !IO), + io.nl(!IO). +write_chord([Note | Notes], !IO) :- + Notes = [_ | _], + Note = note(Rank, Mod, Oct), + write_note(Rank, Mod, Oct, !IO), + io.write_string(" ", !IO), + write_chord(Notes, !IO). -:- pred write_note(rank, modifier, octave, io__state, io__state). -:- mode write_note(in, in, in, di, uo) is det. +:- pred write_note(rank::in, modifier::in, octave::in, io::di, io::uo) is det. -write_note(c, flat, Oct) --> - { Oct1 = Oct - 1 }, - { string__format("b%d", [i(Oct1)], Str) }, - io__write_string(Str). -write_note(c, natural, Oct) --> - { string__format("c%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(c, sharp, Oct) --> - { string__format("c#%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(d, flat, Oct) --> - { string__format("c#%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(d, natural, Oct) --> - { string__format("d%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(d, sharp, Oct) --> - { string__format("d#%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(e, flat, Oct) --> - { string__format("d#%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(e, natural, Oct) --> - { string__format("e%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(e, sharp, Oct) --> - { string__format("f%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(f, flat, Oct) --> - { string__format("e%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(f, natural, Oct) --> - { string__format("f%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(f, sharp, Oct) --> - { string__format("f#%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(g, flat, Oct) --> - { string__format("f#%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(g, natural, Oct) --> - { string__format("g%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(g, sharp, Oct) --> - { string__format("g#%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(a, flat, Oct) --> - { string__format("g#%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(a, natural, Oct) --> - { string__format("a%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(a, sharp, Oct) --> - { string__format("a#%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(b, flat, Oct) --> - { string__format("a#%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(b, natural, Oct) --> - { string__format("b%d", [i(Oct)], Str) }, - io__write_string(Str). -write_note(b, sharp, Oct) --> - { Oct1 = Oct + 1 }, - { string__format("c%d", [i(Oct1)], Str) }, - io__write_string(Str). +write_note(c, flat, Oct, !IO) :- + io.format("b%d", [i(Oct - 1)], !IO). +write_note(c, natural, Oct, !IO) :- + io.format("c%d", [i(Oct)], !IO). +write_note(c, sharp, Oct, !IO) :- + io.format("c#%d", [i(Oct)], !IO). +write_note(d, flat, Oct, !IO) :- + io.format("c#%d", [i(Oct)], !IO). +write_note(d, natural, Oct, !IO) :- + io.format("d%d", [i(Oct)], !IO). +write_note(d, sharp, Oct, !IO) :- + io.format("d#%d", [i(Oct)], !IO). +write_note(e, flat, Oct, !IO) :- + io.format("d#%d", [i(Oct)], !IO). +write_note(e, natural, Oct, !IO) :- + io.format("e%d", [i(Oct)], !IO). +write_note(e, sharp, Oct, !IO) :- + io.format("f%d", [i(Oct)], !IO). +write_note(f, flat, Oct, !IO) :- + io.format("e%d", [i(Oct)], !IO). +write_note(f, natural, Oct, !IO) :- + io.format("f%d", [i(Oct)], !IO). +write_note(f, sharp, Oct, !IO) :- + io.format("f#%d", [i(Oct)], !IO). +write_note(g, flat, Oct, !IO) :- + io.format("f#%d", [i(Oct)], !IO). +write_note(g, natural, Oct, !IO) :- + io.format("g%d", [i(Oct)], !IO). +write_note(g, sharp, Oct, !IO) :- + io.format("g#%d", [i(Oct)], !IO). +write_note(a, flat, Oct, !IO) :- + io.format("g#%d", [i(Oct)], !IO). +write_note(a, natural, Oct, !IO) :- + io.format("a%d", [i(Oct)], !IO). +write_note(a, sharp, Oct, !IO) :- + io.format("a#%d", [i(Oct)], !IO). +write_note(b, flat, Oct, !IO) :- + io.format("a#%d", [i(Oct)], !IO). +write_note(b, natural, Oct, !IO) :- + io.format("b%d", [i(Oct)], !IO). +write_note(b, sharp, Oct, !IO) :- + io.format("c%d", [i(Oct + 1)], !IO). %---------------------------------------------------------------------------% -:- pred next_chord(chord, qualifier, int, chord). -:- mode next_chord(in, in, in, out) is semidet. +:- pred next_chord(chord::in, qualifier::in, int::in, chord::out) is semidet. next_chord(Chord0, Qual, Pr, Chord) :- chord_notes(Chord0, Qual, Notes0), last(Notes0, TopNote0, _), Chord0 = chord(Int0, _, _), -/* - Lambda = lambda([Ch::out] is nondet, ( - next_interval(Int0, Qual, Int, Kind), - next_inversion(Inv), - Ch = chord(Int, Kind, Inv), - chord_notes(Ch, Qual, Notes), - last(Notes, TopNote, _), - next_topnote(TopNote0, Qual, TopNote) - )), - solutions(Lambda, List), -*/ + +% Lambda = lambda([Ch::out] is nondet, ( +% next_interval(Int0, Qual, Int, Kind), +% next_inversion(Inv), +% Ch = chord(Int, Kind, Inv), +% chord_notes(Ch, Qual, Notes), +% last(Notes, TopNote, _), +% next_topnote(TopNote0, Qual, TopNote) +% )), +% solutions(Lambda, List), + solutions(try_next_chord(Qual, Int0, TopNote0), List), - list__length(List, Len), + list.length(List, Len), Len > 0, Ind = Pr mod Len, - list__index0(List, Ind, Chord). + list.index0(List, Ind, Chord). :- pred try_next_chord(qualifier::in, interval::in, note::in, chord::out) is nondet. @@ -305,29 +279,24 @@ try_next_chord(Qual, Int0, TopNote0, Ch) :- last(Notes, TopNote, _), next_topnote(TopNote0, Qual, TopNote). -:- pred rotate(int, list(T), list(T)). -:- mode rotate(in, in, out) is det. +:- pred rotate(int::in, list(T)::in, list(T)::out) is det. rotate(_, [], []). rotate(I, [X | Xs], Zs) :- - ( - I > 0 - -> - list__append(Xs, [X], Ys), + ( if I > 0 then + list.append(Xs, [X], Ys), I1 = I - 1, rotate(I1, Ys, Zs) - ; - I < 0 - -> - list__append(Xs, [X], Ys), + else if I < 0 then + list.append(Xs, [X], Ys), I1 = I + 1, rotate(I1, Ys, Zs) - ; + else Zs = [X | Xs] ). -:- pred next_interval(interval, qualifier, interval, kind). -:- mode next_interval(in, in, out, out) is nondet. +:- pred next_interval(interval::in, qualifier::in, interval::out, kind::out) + is nondet. next_interval(i, maj, iv, maj). next_interval(i, maj, v, maj). @@ -397,8 +366,7 @@ next_inversion(down(i)). next_inversion(down(ii)). next_inversion(down(iii)). -:- pred next_topnote(note, qualifier, note). -:- mode next_topnote(in, in, out) is nondet. +:- pred next_topnote(note::in, qualifier::in, note::out) is nondet. next_topnote(Note0, Qual, Note) :- note_to_interval(Note0, Qual, Int0, Oct0), @@ -423,8 +391,8 @@ note_to_interval(note(a, sharp, Oct), min, vii, Oct). note_to_interval(note(b, flat, Oct), min, vii, Oct). note_to_interval(note(b, natural, Oct), maj, vii, Oct). -:- pred adj_interval(interval, octave, interval, octave). -:- mode adj_interval(in, in, out, out) is multi. +:- pred adj_interval(interval::in, octave::in, interval::out, octave::out) + is multi. adj_interval(i, Oct, vii, Oct1) :- Oct1 = Oct - 1. @@ -445,18 +413,16 @@ adj_interval(vii, Oct, i, Oct1) :- %---------------------------------------------------------------------------% -:- pred chord_notes(chord, qualifier, list(note)). -:- mode chord_notes(in, in, out) is det. +:- pred chord_notes(chord::in, qualifier::in, list(note)::out) is det. chord_notes(chord(Interval, Kind, Inversion), Qual, Notes) :- base_notes(Kind, Notes0), - list__map(transpose(Interval, Qual), Notes0, Notes1), + list.map(transpose(Interval, Qual), Notes0, Notes1), invert(Notes1, Inversion, Notes). %---------------------------------------------------------------------------% -:- pred base_notes(kind, list(note)). -:- mode base_notes(in, out) is det. +:- pred base_notes(kind::in, list(note)::out) is det. base_notes(maj, Notes) :- Notes = [ note(c, natural, 0), @@ -520,8 +486,7 @@ base_notes(dim, Notes) :- %---------------------------------------------------------------------------% -:- pred transpose(interval, qualifier, note, note). -:- mode transpose(in, in, in, out) is det. +:- pred transpose(interval::in, qualifier::in, note::in, note::out) is det. transpose(Trans, Qual, Note0, Note) :- interval_to_int(Trans, Qual, TNum), @@ -529,8 +494,7 @@ transpose(Trans, Qual, Note0, Note) :- NNum = TNum + NNum0, int_to_note(NNum, Note). -:- pred trans(note, note, note). -:- mode trans(in, in, out) is det. +:- pred trans(note::in, note::in, note::out) is det. trans(Trans, Note0, Note) :- note_to_int(Trans, TNum), @@ -540,10 +504,11 @@ trans(Trans, Note0, Note) :- %---------------------------------------------------------------------------% -:- type direction ---> up ; down . +:- type direction + ---> up + ; down. -:- pred invert(list(note), inversion, list(note)). -:- mode invert(in, in, out) is det. +:- pred invert(list(note)::in, inversion::in, list(note)::out) is det. invert(Notes, o, Notes). invert(Notes0, up(Degree), Notes) :- @@ -553,39 +518,37 @@ invert(Notes0, down(Degree), Notes) :- degree_to_int(Degree, N), invert_list(Notes0, down, -N, Notes). -:- pred invert_list(list(note), direction, int, list(note)). -:- mode invert_list(in, in, in, out) is det. +:- pred invert_list(list(note)::in, direction::in, int::in, list(note)::out) + is det. invert_list(Notes0, Dir, N, Notes) :- - ( + ( if N > 0, Notes0 = [Note0 | Notes1] - -> + then shift(Dir, Note0, Note), - list__append(Notes1, [Note], Notes2), + list.append(Notes1, [Note], Notes2), N1 = N - 1, invert_list(Notes2, Dir, N1, Notes) - ; + else if N < 0, last(Notes0, Note0, Notes1) - -> + then shift(Dir, Note0, Note), N1 = N + 1, invert_list([Note | Notes1], Dir, N1, Notes) - ; + else Notes = Notes0 ). -:- pred shift(direction, note, note). -:- mode shift(in, in, out) is det. +:- pred shift(direction::in, note::in, note::out) is det. shift(up, note(Rank, Mod, Oct), note(Rank, Mod, Oct1)) :- Oct1 = Oct + 1. shift(down, note(Rank, Mod, Oct), note(Rank, Mod, Oct1)) :- Oct1 = Oct - 1. -:- pred last(list(T), T, list(T)). -:- mode last(in, out, out) is semidet. +:- pred last(list(T)::in, T::out, list(T)::out) is semidet. last([X], X, []). last([X | Xs], Z, [X | Ys]) :- @@ -594,22 +557,21 @@ last([X | Xs], Z, [X | Ys]) :- %---------------------------------------------------------------------------% -:- pred inversion_to_int(inversion, int). -:- mode inversion_to_int(in, out) is det. +:- pred inversion_to_int(inversion::in, int::out) is det. inversion_to_int(o, 0). -inversion_to_int(up(Deg), Int) :- degree_to_int(Deg, Int). -inversion_to_int(down(Deg), -Int) :- degree_to_int(Deg, Int). +inversion_to_int(up(Deg), Int) :- + degree_to_int(Deg, Int). +inversion_to_int(down(Deg), -Int) :- + degree_to_int(Deg, Int). -:- pred degree_to_int(degree, int). -:- mode degree_to_int(in, out) is det. +:- pred degree_to_int(degree::in, int::out) is det. degree_to_int(i, 1). degree_to_int(ii, 2). degree_to_int(iii, 3). -:- pred interval_to_int(interval, qualifier, int). -:- mode interval_to_int(in, in, out) is det. +:- pred interval_to_int(interval::in, qualifier::in, int::out) is det. interval_to_int(i, _, 0). interval_to_int(ii, _, 2). @@ -622,8 +584,7 @@ interval_to_int(vi, maj, 9). interval_to_int(vii, min, 10). interval_to_int(vii, maj, 11). -:- pred note_to_int(note, int). -:- mode note_to_int(in, out) is det. +:- pred note_to_int(note::in, int::out) is det. note_to_int(note(c, flat, Oct), I) :- I = -1 + 12 * Oct. @@ -668,13 +629,12 @@ note_to_int(note(b, natural, Oct), I) :- note_to_int(note(b, sharp, Oct), I) :- I = 12 + 12 * Oct. -:- pred int_to_note(int, note). -:- mode int_to_note(in, out) is det. +:- pred int_to_note(int::in, note::out) is det. int_to_note(Num, note(Rank, Mod, Oct)) :- Oct = Num // 12, Off = Num mod 12, - ( + ( if ( Off = 0, Rank0 = c, Mod0 = natural ; @@ -700,58 +660,43 @@ int_to_note(Num, note(Rank, Mod, Oct)) :- ; Off = 11, Rank0 = b, Mod0 = natural ) - -> + then Rank = Rank0, Mod = Mod0 - ; + else error("Num mod 12 gave an illegal result!") ). %---------------------------------------------------------------------------% -:- pred short(char, option). -:- mode short(in, out) is semidet. +:- pred short(char::in, option::out) is semidet. short('h', help). short('k', key). short('l', length). short('s', seed). -:- pred long(string, option). -:- mode long(in, out) is semidet. +:- pred long(string::in, option::out) is semidet. long("help", help). long("key", key). long("length", length). long("seed", seed). -:- pred defaults(option, option_data). -:- mode defaults(out, out) is nondet. +:- pred defaults(option::out, option_data::out) is multi. -defaults(Opt, Data) :- - ( - semidet_succeed - -> - defaults0(Opt, Data) - ; - fail - ). +defaults(help, bool(no)). +defaults(key, string("c")). +defaults(length, int(16)). +defaults(seed, int(0)). -:- pred defaults0(option, option_data). -:- mode defaults0(out, out) is multi. +:- pred help(io::di, io::uo) is det. -defaults0(help, bool(no)). -defaults0(key, string("c")). -defaults0(length, int(16)). -defaults0(seed, int(0)). - -:- pred help(io__state::di, io__state::uo) is det. - -help --> - io__stderr_stream(StdErr), - io__write_string(StdErr, -"usage: space [-h | --help] [-k | --key key[M]] [-l | --length n] [-s | --seed n]\n" -). +help(!IO) :- + io.stderr_stream(StdErr, !IO), + io.write_string(StdErr, + "usage: space [-h | --help] [-k | --key key[M]] " ++ + "[-l | --length n] [-s | --seed n]\n", !IO). %---------------------------------------------------------------------------% @@ -769,9 +714,9 @@ random_init(Seed, Supply) :- random_random(Value, Supply0, Supply) :- Value = Supply0, - ( Supply0 < 100 -> + ( if Supply0 < 100 then Supply = Supply0 + 1 - ; + else Supply = 0 ). diff --git a/tests/hard_coded/spawn_native.m b/tests/hard_coded/spawn_native.m index 0a99a7858..7a483ef4c 100644 --- a/tests/hard_coded/spawn_native.m +++ b/tests/hard_coded/spawn_native.m @@ -25,7 +25,7 @@ %---------------------------------------------------------------------------% main(!IO) :- - ( can_spawn_native -> + ( if can_spawn_native then init_tl_key(!IO), thread.spawn_native(go("a"), _, !IO), msleep(100, !IO), @@ -34,7 +34,7 @@ main(!IO) :- thread.spawn_native(go("c"), _, !IO), msleep(100, !IO), go("d", !IO) - ; + else io.write_string("spawn_native not supported\n", !IO) ). diff --git a/tests/hard_coded/special_char.m b/tests/hard_coded/special_char.m index 64a96e3f8..00e9bdfb8 100644 --- a/tests/hard_coded/special_char.m +++ b/tests/hard_coded/special_char.m @@ -3,20 +3,21 @@ %---------------------------------------------------------------------------% % % Test output of special characters such as \r +% :- module special_char. :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. -main --> - print("Hello world\r\n"), - print("\r\n"), - print("\a\b\v\f\t\n"), - print("\077\"), - print("\0123\"), - print("\0321\"), - print("\n"). +main(!IO) :- + print("Hello world\r\n", !IO), + print("\r\n", !IO), + print("\a\b\v\f\t\n", !IO), + print("\077\", !IO), + print("\0123\", !IO), + print("\0321\", !IO), + print("\n", !IO). diff --git a/tests/hard_coded/stable_foreign.m b/tests/hard_coded/stable_foreign.m index 0c85c9cfa..a9ebaa1ea 100644 --- a/tests/hard_coded/stable_foreign.m +++ b/tests/hard_coded/stable_foreign.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module stable_foreign. :- interface. @@ -33,44 +33,44 @@ test(P1, P2, !IO) :- rep(P1, V1), rep(P2, V2), - io__write_int(V1, !IO), - ( unify(P1, P2) -> - io__write_string(" u= ", !IO) - ; - io__write_string(" u!= ", !IO) + io.write_int(V1, !IO), + ( if unify(P1, P2) then + io.write_string(" u= ", !IO) + else + io.write_string(" u!= ", !IO) ), - io__write_int(V2, !IO), - io__write_string("\n", !IO), + io.write_int(V2, !IO), + io.write_string("\n", !IO), compare(R, P1, P2), - io__write_int(V1, !IO), + io.write_int(V1, !IO), ( R = (<), - io__write_string(" c< ", !IO) + io.write_string(" c< ", !IO) ; R = (=), - io__write_string(" c= ", !IO) + io.write_string(" c= ", !IO) ; R = (>), - io__write_string(" c> ", !IO) + io.write_string(" c> ", !IO) ), - io__write_int(V2, !IO), - io__write_string("\n", !IO), + io.write_int(V2, !IO), + io.write_string("\n", !IO), compare_representation(RR, P1, P2), - io__write_int(V1, !IO), + io.write_int(V1, !IO), ( RR = (<), - io__write_string(" r< ", !IO) + io.write_string(" r< ", !IO) ; RR = (=), - io__write_string(" r= ", !IO) + io.write_string(" r= ", !IO) ; RR = (>), - io__write_string(" r> ", !IO) + io.write_string(" r> ", !IO) ), - io__write_int(V2, !IO), - io__write_string("\n", !IO). + io.write_int(V2, !IO), + io.write_string("\n", !IO). :- pragma foreign_decl(c, " #define STABLE_FOREIGN_MAX 100 diff --git a/tests/hard_coded/static_no_tag.m b/tests/hard_coded/static_no_tag.m index b653106e6..3ff0bc929 100644 --- a/tests/hard_coded/static_no_tag.m +++ b/tests/hard_coded/static_no_tag.m @@ -1,4 +1,6 @@ -% vim: ts=4 et ft=mercury +%---------------------------------------------------------------------------% +% vim: ts=4 sw=4 et ft=mercury +%---------------------------------------------------------------------------% % % This is a regression test for a problem in rotd-2008-01-15 and before. % In those versions of Mercury the MLDS->C code generator was generating @@ -13,6 +15,7 @@ % % This module also exercises creating static ground terms with other sorts % of no_tag type as well. +% :- module static_no_tag. :- interface. diff --git a/tests/hard_coded/stdlib_init.m b/tests/hard_coded/stdlib_init.m index 02ee471b7..c1cd5969a 100644 --- a/tests/hard_coded/stdlib_init.m +++ b/tests/hard_coded/stdlib_init.m @@ -1,4 +1,9 @@ +%---------------------------------------------------------------------------% +% vim: ts=4 sw=4 et ft=mercury +%---------------------------------------------------------------------------% +% % Test that the standard library is initialised before main/2 is called. +% :- module stdlib_init. :- interface. diff --git a/tests/hard_coded/stream_format.m b/tests/hard_coded/stream_format.m index 857527706..72771293f 100644 --- a/tests/hard_coded/stream_format.m +++ b/tests/hard_coded/stream_format.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module stream_format. :- interface. diff --git a/tests/hard_coded/stream_ignore_ws.m b/tests/hard_coded/stream_ignore_ws.m index 888984955..db2f97ee5 100644 --- a/tests/hard_coded/stream_ignore_ws.m +++ b/tests/hard_coded/stream_ignore_ws.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module stream_ignore_ws. :- interface. @@ -16,13 +16,13 @@ main(!IO) :- io.stdin_stream(Stdin, !IO), stream.ignore_whitespace(Stdin, IgnoreResult, !IO), - ( IgnoreResult = ok -> + ( if IgnoreResult = ok then io.read_file_as_string(Stdin, MaybePartialRes, !IO), - ( MaybePartialRes = ok(String) -> + ( if MaybePartialRes = ok(String) then io.write_string(String, !IO) - ; + else io.write_string("io.read_file_as_string FAILED\n", !IO) ) - ; + else io.write_string("stream.ignore_whitespace FAILED\n", !IO) ). diff --git a/tests/hard_coded/stream_test.m b/tests/hard_coded/stream_test.m index 964778824..9d51eba98 100644 --- a/tests/hard_coded/stream_test.m +++ b/tests/hard_coded/stream_test.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module stream_test. :- interface. @@ -17,7 +17,10 @@ :- import_module stream. :- import_module univ. -:- type foo ---> foo ; bar ; baz. +:- type foo + ---> foo + ; bar + ; baz. main(!IO) :- io.stdout_stream(Stdout, !IO), diff --git a/tests/hard_coded/string_alignment.m b/tests/hard_coded/string_alignment.m index 563cc8866..06b2db8f1 100644 --- a/tests/hard_coded/string_alignment.m +++ b/tests/hard_coded/string_alignment.m @@ -4,6 +4,7 @@ % % This module tests for possible problems that unaligned string literals % would cause if tagged. +% :- module string_alignment. :- interface. @@ -14,7 +15,11 @@ :- implementation. :- import_module require. -:- type t ---> f1(string) ; f2(string) ; f3(string) ; f4(string). +:- type t + ---> f1(string) + ; f2(string) + ; f3(string) + ; f4(string). main --> show(f1("foo")), @@ -22,10 +27,22 @@ main --> show(f1("oo")), show(f2("oo")). -:- pred show(t::in, io__state::di, io__state::uo) is det. +:- pred show(t::in, io::di, io::uo) is det. -show(f1(S)) --> io__write_string("f1: "), io__write_string(S), io__nl. -show(f2(S)) --> io__write_string("f2: "), io__write_string(S), io__nl. -show(f3(S)) --> io__write_string("f3: "), io__write_string(S), io__nl. -show(f4(S)) --> io__write_string("f4: "), io__write_string(S), io__nl. +show(f1(S), !IO) :- + io.write_string("f1: ", !IO), + io.write_string(S, !IO), + io.nl(!IO). +show(f2(S), !IO) :- + io.write_string("f2: ", !IO), + io.write_string(S, !IO), + io.nl(!IO). +show(f3(S), !IO) :- + io.write_string("f3: ", !IO), + io.write_string(S, !IO), + io.nl(!IO). +show(f4(S), !IO) :- + io.write_string("f4: ", !IO), + io.write_string(S, !IO), + io.nl(!IO). diff --git a/tests/hard_coded/string_alignment_bug.m b/tests/hard_coded/string_alignment_bug.m index 81e064132..dcda3ec72 100644 --- a/tests/hard_coded/string_alignment_bug.m +++ b/tests/hard_coded/string_alignment_bug.m @@ -5,6 +5,7 @@ % mercury 0.8 failed this test on some architectures, % because string literals were not aligned but deep_copy() % was assuming that they were. +% :- module string_alignment_bug. @@ -12,7 +13,7 @@ :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. @@ -28,15 +29,15 @@ :- import_module string. :- import_module univ. -main --> - init_globals, - { gen_tiles(10, 10, Tiles) }, - set_global("Tiles", Tiles), - { init_selection(Selection) }, - set_global("Selection", Selection), - { init_file(MFN) }, - set_global("CurrentFile", MFN). - %main(bedit__setup, ["robot"]). +main(!IO) :- + init_globals(!IO), + gen_tiles(10, 10, Tiles), + set_global("Tiles", Tiles, !IO), + init_selection(Selection), + set_global("Selection", Selection, !IO), + init_file(MFN), + set_global("CurrentFile", MFN, !IO). + % main(bedit.setup, ["robot"], !IO). :- pred init_file(maybe(string)::out) is det. @@ -51,36 +52,35 @@ init_file(no). :- pred init_selection(selection::out) is det. init_selection(Sel) :- - set_ordlist__init(Sel). + set_ordlist.init(Sel). %---------------------------------------------------------------------------% -:- type tiles == map(pos, tile). -:- type tile ---> tile(kind, list(attr)). -:- type kind ---> plain ; pit ; gear(chirality) ; conv(dir). -:- type chirality ---> clock ; anti. -:- type attr ---> wall(dir) ; start ; flag(int). -:- type dir ---> north ; south ; east ; west. +:- type tile + ---> tile(kind, list(int)). -:- pred gen_tiles(int, int, map(pos, tile)). -:- mode gen_tiles(in, in, out) is det. +:- type kind + ---> plain. + +:- pred gen_tiles(int::in, int::in, map(pos, tile)::out) is det. gen_tiles(Xmax, Ymax, Tiles) :- - map__init(Tiles0), - AllPos = (pred(Pos::out) is nondet :- - between(0, Xmax-1, X), - between(0, Ymax-1, Y), - Pos = X - Y - ), - AddTile = (pred(Pos::in, T0::in, T::out) is det :- - map__set(Pos, tile(plain, []), T0, T) - ), + map.init(Tiles0), + AllPos = + ( pred(Pos::out) is nondet :- + between(0, Xmax-1, X), + between(0, Ymax-1, Y), + Pos = X - Y + ), + AddTile = + ( pred(Pos::in, T0::in, T::out) is det :- + map.set(Pos, tile(plain, []), T0, T) + ), aggregate(AllPos, AddTile, Tiles0, Tiles). %---------------------------------------------------------------------------% -:- pred between(int, int, int). -:- mode between(in, in, out) is nondet. +:- pred between(int::in, int::in, int::out) is nondet. between(Min, Max, I) :- Min =< Max, @@ -93,74 +93,61 @@ between(Min, Max, I) :- %---------------------------------------------------------------------------% -:- pred init_globals(io__state, io__state). -:- mode init_globals(di, uo) is det. +:- pred init_globals(io::di, io::uo) is det. -:- pred get_global(string, T, io__state, io__state). -:- mode get_global(in, out, di, uo) is det. +init_globals(!IO) :- + my_map_init(Map), + type_to_univ(Map, UMap1), + copy(UMap1, UMap), + io.set_globals(UMap, !IO). -:- pred set_global(string, T, io__state, io__state). -:- mode set_global(in, in, di, uo) is det. +:- pred get_global(string::in, T::out, io::di, io::uo) is det. -init_globals --> - { my_map_init(Map) }, - { type_to_univ(Map, UMap1) }, - { copy(UMap1, UMap) }, - io__set_globals(UMap). - -get_global(Name, Value) --> - io__get_globals(UMap0), - ( - { univ_to_type(UMap0, Map0) } - -> - ( - { map__search(Map0, Name, UValue) } - -> - ( - { univ_to_type(UValue, Value0) } - -> - { Value = Value0 } - ; - { string__format( - "globals: value for `%s' has bad type", - [s(Name)], Str) }, - { error(Str) } +get_global(Name, Value, !IO) :- + io.get_globals(UMap0, !IO), + ( if univ_to_type(UMap0, Map0) then + ( if map.search(Map0, Name, UValue) then + ( if univ_to_type(UValue, Value0) then + Value = Value0 + else + string.format("globals: value for `%s' has bad type", + [s(Name)], Str), + error(Str) ) - ; - { string__format("globals: %s not found", - [s(Name)], Str) }, - { error(Str) } + else + string.format("globals: %s not found", [s(Name)], Str), + error(Str) ) - ; - { error("globals: global store stuffed up") } + else + error("globals: global store stuffed up") ). -set_global(Name, Value) --> - io__get_globals(UMap0), - ( - { univ_to_type(UMap0, Map0) } - -> - { type_to_univ(Value, UValue) }, - io__write_string("Current global store:\n"), - io__write(Map0), - nl, - io__write_string("Adding `"), - io__write_string(Name), - io__write_string("': "), - io__write(Value), - nl, - { map__set(Name, UValue, Map0, Map) }, - io__write_string("New global store:\n"), - io__write(Map), - nl, - { type_to_univ(Map, UMap1) }, - { copy(UMap1, UMap) }, - io__set_globals(UMap) - ; - { error("globals: global store stuffed up") } +:- pred set_global(string::in, T::in, io::di, io::uo) is det. + +set_global(Name, Value, !IO) :- + io.get_globals(UMap0, !IO), + ( if univ_to_type(UMap0, Map0) then + type_to_univ(Value, UValue), + io.write_string("Current global store:\n", !IO), + io.write(Map0, !IO), + nl(!IO), + io.write_string("Adding `", !IO), + io.write_string(Name, !IO), + io.write_string("': ", !IO), + io.write(Value, !IO), + nl(!IO), + map.set(Name, UValue, Map0, Map), + io.write_string("New global store:\n", !IO), + io.write(Map, !IO), + nl(!IO), + type_to_univ(Map, UMap1), + copy(UMap1, UMap), + io.set_globals(UMap, !IO) + else + error("globals: global store stuffed up") ). :- pred my_map_init(map(string, univ)::out) is det. my_map_init(Map) :- - map__init(Map). + map.init(Map). diff --git a/tests/hard_coded/string_append_iii.m b/tests/hard_coded/string_append_iii.m index 404494af6..3aaaebb5e 100644 --- a/tests/hard_coded/string_append_iii.m +++ b/tests/hard_coded/string_append_iii.m @@ -19,13 +19,13 @@ %---------------------------------------------------------------------------% main(!IO) :- - ( + ( if string.append("", "cat", "cat"), string.append("c", "at", "cat"), string.append("ca", "t", "cat"), string.append("cat", "", "cat") - -> + then io.write_string("test succeeded\n", !IO) - ; + else io.write_string("test failed\n", !IO) ). diff --git a/tests/hard_coded/string_append_ioi.m b/tests/hard_coded/string_append_ioi.m index 812d3a184..7c7b66ed2 100644 --- a/tests/hard_coded/string_append_ioi.m +++ b/tests/hard_coded/string_append_ioi.m @@ -20,15 +20,15 @@ %---------------------------------------------------------------------------% main(!IO) :- - ( + ( if string.append("", A, "cat"), string.append("c", B, "cat"), string.append("ca", C, "cat"), string.append("cat", D, "cat"), not string.append("cat", _, "dogcat") - -> + then io.write([A, B, C, D], !IO), io.nl(!IO) - ; + else io.write_string("tested failed\n", !IO) ). diff --git a/tests/hard_coded/string_append_ooi.m b/tests/hard_coded/string_append_ooi.m index e45432738..5bb87ab54 100644 --- a/tests/hard_coded/string_append_ooi.m +++ b/tests/hard_coded/string_append_ooi.m @@ -23,7 +23,7 @@ main(!IO) :- unsorted_solutions( - (pred(L - R::out) is multi :- + ( pred(L - R::out) is multi :- string.append(L, R, "cat") ), UnsortedSolutions), list.sort(UnsortedSolutions, Solutions), diff --git a/tests/hard_coded/string_case.m b/tests/hard_coded/string_case.m index 18d37e3b0..59beb3ffc 100644 --- a/tests/hard_coded/string_case.m +++ b/tests/hard_coded/string_case.m @@ -70,7 +70,7 @@ test_to_lower_in_out(S, !IO) :- list.map(char.to_lower, Chars, LowerChars), string.from_char_list(LowerChars, Expected), - expect(unify(LowerS, Expected), $module, $pred, "LowerS != Expected"). + expect(unify(LowerS, Expected), $pred, "LowerS != Expected"). :- pred test_to_upper_in_out(string::in, io::di, io::uo) is det. @@ -81,16 +81,16 @@ test_to_upper_in_out(S, !IO) :- list.map(char.to_upper, Chars, UpperChars), string.from_char_list(UpperChars, Expected), - expect(unify(UpperS, Expected), $module, $pred, "UpperS != Expected"). + expect(unify(UpperS, Expected), $pred, "UpperS != Expected"). :- pred test_to_lower_in_in({string, string}::in, io::di, io::uo) is det. test_to_lower_in_in({X, Y}, !IO) :- compare(Expected, to_lower(X), Y), ( if string.to_lower(X, Y) then - expect(unify(Expected, (=)), $module, $pred, "to_lower wrong") + expect(unify(Expected, (=)), $pred, "to_lower wrong") else - expect_not(unify(Expected, (=)), $module, $pred, "to_lower wrong") + expect_not(unify(Expected, (=)), $pred, "to_lower wrong") ). :- pred test_to_upper_in_in({string, string}::in, io::di, io::uo) is det. @@ -98,16 +98,17 @@ test_to_lower_in_in({X, Y}, !IO) :- test_to_upper_in_in({X, Y}, !IO) :- compare(Expected, to_upper(X), Y), ( if string.to_upper(X, Y) then - expect(unify(Expected, (=)), $module, $pred, "to_upper wrong") + expect(unify(Expected, (=)), $pred, "to_upper wrong") else - expect_not(unify(Expected, (=)), $module, $pred, "to_upper wrong") + expect_not(unify(Expected, (=)), $pred, "to_upper wrong") ). -:- pred test_compare_ignore_case_ascii({string, string}::in, io::di, io::uo) is det. +:- pred test_compare_ignore_case_ascii({string, string}::in, + io::di, io::uo) is det. test_compare_ignore_case_ascii({X, Y}, !IO) :- compare_ignore_case_ascii(ResIgnCase, X, Y), compare(ResLower, to_lower(X), to_lower(Y) : string), compare(ResUpper, to_upper(X), to_upper(Y) : string), - expect(unify(ResIgnCase, ResLower), $module, $pred, "ResIgnCase != ResLower"), - expect(unify(ResIgnCase, ResUpper), $module, $pred, "ResIgnCase != ResUpper"). + expect(unify(ResIgnCase, ResLower), $pred, "ResIgnCase != ResLower"), + expect(unify(ResIgnCase, ResUpper), $pred, "ResIgnCase != ResUpper"). diff --git a/tests/hard_coded/string_class.m b/tests/hard_coded/string_class.m index 87b3a7cea..c98ea03a8 100644 --- a/tests/hard_coded/string_class.m +++ b/tests/hard_coded/string_class.m @@ -45,9 +45,9 @@ test_is_all(Pred, Name, !IO) :- string::in, io::di, io::uo) is det. test_is_all_2(Pred, Name, Chars, !IO) :- - ( Pred(Chars) -> + ( if Pred(Chars) then io.format("%s(""%s"")\n", [s(Name), s(Chars)], !IO) - ; + else io.format("not %s(""%s"")\n", [s(Name), s(Chars)], !IO) ). diff --git a/tests/hard_coded/string_code_unit.m b/tests/hard_coded/string_code_unit.m index 2fd8bbe01..609eab0e6 100644 --- a/tests/hard_coded/string_code_unit.m +++ b/tests/hard_coded/string_code_unit.m @@ -48,9 +48,9 @@ test(String, !IO) :- io.write_string("UTF-8:\t\t", !IO), write_hex_ints(UTF8, !IO), io.nl(!IO), - ( string.from_utf8_code_unit_list(UTF8, String) -> + ( if string.from_utf8_code_unit_list(UTF8, String) then true - ; + else io.write_string("from_utf8_code_unit_list failed\n", !IO) ), @@ -58,9 +58,9 @@ test(String, !IO) :- io.write_string("UTF-16:\t\t", !IO), write_hex_ints(UTF16, !IO), io.nl(!IO), - ( string.from_utf16_code_unit_list(UTF16, String) -> + ( if string.from_utf16_code_unit_list(UTF16, String) then true - ; + else io.write_string("from_utf16_code_unit_list failed\n", !IO) ), io.nl(!IO). diff --git a/tests/hard_coded/string_codepoint.m b/tests/hard_coded/string_codepoint.m index 749a768a1..ea0551ff6 100644 --- a/tests/hard_coded/string_codepoint.m +++ b/tests/hard_coded/string_codepoint.m @@ -66,11 +66,11 @@ main(!IO) :- io.write(CodeUnitList, !IO), io.nl(!IO), - ( string.from_code_unit_list(CodeUnitList, Str2) -> + ( if string.from_code_unit_list(CodeUnitList, Str2) then io.write_string("\nfrom_code_unit_list:\n", !IO), io.write_string(Str2, !IO), io.nl(!IO) - ; + else true ), @@ -114,24 +114,24 @@ main(!IO) :- :- pred test_codepoint_offset(string::in, int::in, io::di, io::uo) is det. test_codepoint_offset(Str, Pos, !IO) :- - ( string.codepoint_offset(Str, Pos, Offset) -> + ( if string.codepoint_offset(Str, Pos, Offset) then io.format("string.codepoint_offset(Str, %d, %d)\n", [i(Pos), i(Offset)], !IO), - ( string.codepoint_offset(Str, Offset, 1, Offset2) -> + ( if string.codepoint_offset(Str, Offset, 1, Offset2) then io.format("string.codepoint_offset(Str, %d, 1, %d)\n", [i(Offset), i(Offset2)], !IO) - ; + else io.format("string.codepoint_offset(Str, %d, 1, _) failed\n", [i(Offset)], !IO) ), - ( string.index(Str, Offset, Char) -> + ( if string.index(Str, Offset, Char) then io.format("string.index(Str, %d, '%c')\n", [i(Offset), c(Char)], !IO) - ; + else io.format("string.index(Str, %d, _) failed\n", [i(Offset)], !IO) ) - ; + else io.format("string.codepoint_offset(Str, %d, _) failed\n", [i(Pos)], !IO) ). @@ -139,33 +139,33 @@ test_codepoint_offset(Str, Pos, !IO) :- :- pred test_index_next(string::in, int::in, io::di, io::uo) is det. test_index_next(Str, Index, !IO) :- - ( string.index_next(Str, Index, NextIndex, C) -> + ( if string.index_next(Str, Index, NextIndex, C) then io.format("index_next(Str, %d, %d, '%c')\n", [i(Index), i(NextIndex), c(C)], !IO), test_index_next(Str, NextIndex, !IO) - ; + else io.write_string("end\n", !IO) ). :- pred test_unsafe_index_next(string::in, int::in, io::di, io::uo) is det. test_unsafe_index_next(Str, Index, !IO) :- - ( string.unsafe_index_next(Str, Index, NextIndex, C) -> + ( if string.unsafe_index_next(Str, Index, NextIndex, C) then io.format("unsafe_index_next(Str, %d, %d, '%c')\n", [i(Index), i(NextIndex), c(C)], !IO), test_unsafe_index_next(Str, NextIndex, !IO) - ; + else io.write_string("end\n", !IO) ). :- pred test_unsafe_prev_index(string::in, int::in, io::di, io::uo) is det. test_unsafe_prev_index(Str, Index, !IO) :- - ( string.unsafe_prev_index(Str, Index, PrevIndex, C) -> + ( if string.unsafe_prev_index(Str, Index, PrevIndex, C) then io.format("unsafe_prev_index(Str, %d, %d, '%c')\n", [i(Index), i(PrevIndex), c(C)], !IO), test_unsafe_prev_index(Str, PrevIndex, !IO) - ; + else io.write_string("end\n", !IO) ). @@ -191,9 +191,9 @@ test_between_codepoints_2(Str, Start, End, !IO) :- [i(Start), i(End), s(SubString)], !IO), slow_between_codepoints(Str, Start, End, SlowSubString), - ( SubString = SlowSubString -> + ( if SubString = SlowSubString then true - ; + else io.write_string("but slow_between_codepoints returned: \"", !IO), io.write_string(SlowSubString, !IO), io.write_string("\"\n", !IO) diff --git a/tests/hard_coded/string_first_char.m b/tests/hard_coded/string_first_char.m index d6ab6502e..a7155c032 100644 --- a/tests/hard_coded/string_first_char.m +++ b/tests/hard_coded/string_first_char.m @@ -65,10 +65,10 @@ main(!IO) :- is det. test_first_char_iii(Str, FirstChar, Rest, !IO) :- - ( string.first_char(Str, FirstChar, Rest) -> + ( if string.first_char(Str, FirstChar, Rest) then io.format("first_char(""%s"", '%c', ""%s"")\n", [s(Str), c(FirstChar), s(Rest)], !IO) - ; + else io.format("not first_char(""%s"", '%c', ""%s"")\n", [s(Str), c(FirstChar), s(Rest)], !IO) ). @@ -76,10 +76,10 @@ test_first_char_iii(Str, FirstChar, Rest, !IO) :- :- pred test_first_char_ioi(string::in, string::in, io::di, io::uo) is det. test_first_char_ioi(Str, Rest, !IO) :- - ( string.first_char(Str, FirstChar, Rest) -> + ( if string.first_char(Str, FirstChar, Rest) then io.format("first_char(""%s"", '%c', ""%s"")\n", [s(Str), c(FirstChar), s(Rest)], !IO) - ; + else io.format("not first_char(""%s"", _, ""%s"")\n", [s(Str), s(Rest)], !IO) ). @@ -87,10 +87,10 @@ test_first_char_ioi(Str, Rest, !IO) :- :- pred test_first_char_iio(string::in, char::in, io::di, io::uo) is det. test_first_char_iio(Str, FirstChar, !IO) :- - ( string.first_char(Str, FirstChar, Rest) -> + ( if string.first_char(Str, FirstChar, Rest) then io.format("first_char(""%s"", '%c', ""%s"")\n", [s(Str), c(FirstChar), s(Rest)], !IO) - ; + else io.format("not first_char(""%s"", '%c', _)\n", [s(Str), c(FirstChar)], !IO) ). @@ -98,10 +98,10 @@ test_first_char_iio(Str, FirstChar, !IO) :- :- pred test_first_char_ioo(string::in, io::di, io::uo) is det. test_first_char_ioo(Str, !IO) :- - ( string.first_char(Str, FirstChar, Rest) -> + ( if string.first_char(Str, FirstChar, Rest) then io.format("first_char(""%s"", '%c', ""%s"")\n", [s(Str), c(FirstChar), s(Rest)], !IO) - ; + else io.format("not first_char(""%s"", _, _)\n", [s(Str)], !IO) ). diff --git a/tests/hard_coded/string_hash.m b/tests/hard_coded/string_hash.m index 5d534935b..30200b996 100644 --- a/tests/hard_coded/string_hash.m +++ b/tests/hard_coded/string_hash.m @@ -1,5 +1,7 @@ +%---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury - +%---------------------------------------------------------------------------% +% % Test that string.hash and MR_hash_string return the same value. % Do the same for: % * string.hash2 and MR_hash_string2, @@ -7,6 +9,7 @@ % * string.hash4 and MR_hash_string4, % * string.hash5 and MR_hash_string5, % * string.hash6 and MR_hash_string6. +% :- module string_hash. @@ -42,9 +45,9 @@ main(!IO) :- random.supply::mdi, random.supply::muo, io::di, io::uo) is det. test(Length, !Succeeded, !RS, !IO) :- - ( Length < 0 -> + ( if Length < 0 then true - ; + else make_char_list(Length, [], List, !RS), string.from_char_list(List, String), @@ -79,9 +82,9 @@ test(Length, !Succeeded, !RS, !IO) :- random.supply::mdi, random.supply::muo) is det. make_char_list(Length, !List, !RS) :- - ( Length = 0 -> + ( if Length = 0 then true - ; + else rand_char(Char, !RS), !:List = [Char | !.List], make_char_list(Length - 1, !List, !RS) @@ -104,9 +107,9 @@ rand_char(Char, !RS) :- bool::in, bool::out, io::di, io::uo) is det. test_hash(HashName, LibHash, RuntimeHash, String, !Succeeded, !IO) :- - ( LibHash = RuntimeHash -> + ( if LibHash = RuntimeHash then true - ; + else !:Succeeded = no, io.write_string("failed " ++ HashName ++ ": runtime ", !IO), io.write_int(RuntimeHash, !IO), diff --git a/tests/hard_coded/string_loop.m b/tests/hard_coded/string_loop.m index ef624b557..69c311ea1 100644 --- a/tests/hard_coded/string_loop.m +++ b/tests/hard_coded/string_loop.m @@ -3,6 +3,7 @@ %---------------------------------------------------------------------------% % % Tom says "The following module loops forever on mundook". +% :- module string_loop. @@ -10,7 +11,7 @@ :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. @@ -19,5 +20,5 @@ :- import_module string. main(IO0, IO) :- - string__format("%ei\n", [f(0.0)], Str), - io__write_string(Str, IO0, IO). + string.format("%ei\n", [f(0.0)], Str), + io.write_string(Str, IO0, IO). diff --git a/tests/hard_coded/string_presuffix.m b/tests/hard_coded/string_presuffix.m index af46c44f4..c07e9cfd1 100644 --- a/tests/hard_coded/string_presuffix.m +++ b/tests/hard_coded/string_presuffix.m @@ -3,6 +3,7 @@ %---------------------------------------------------------------------------% % % Test string prefix- and suffix-related predicates. +% :- module string_presuffix. :- interface. @@ -26,7 +27,7 @@ main(!IO) :- Str = "aรŸฮพๅ••๐€€.", io.write_string("prefix(in, in):\n", !IO), - ( + ( if string.prefix(Str, ""), string.prefix(Str, "a"), string.prefix(Str, "aรŸ"), @@ -35,9 +36,9 @@ main(!IO) :- string.prefix(Str, "aรŸฮพๅ••๐€€"), string.prefix(Str, "aรŸฮพๅ••๐€€."), not string.prefix(Str, "aรŸฮพๅ••๐€€.z") - -> + then io.write_string("pass\n", !IO) - ; + else io.write_string("fail\n", !IO) ), @@ -47,7 +48,7 @@ main(!IO) :- io.nl(!IO), io.write_string("\nsuffix(in, in):\n", !IO), - ( + ( if not string.suffix(Str, "aรŸฮพๅ••๐€€.z"), string.suffix(Str, "aรŸฮพๅ••๐€€."), string.suffix(Str, "รŸฮพๅ••๐€€."), @@ -56,9 +57,9 @@ main(!IO) :- string.suffix(Str, "๐€€."), string.suffix(Str, "."), string.suffix(Str, "") - -> + then io.write_string("pass\n", !IO) - ; + else io.write_string("fail\n", !IO) ), @@ -68,23 +69,23 @@ main(!IO) :- io.nl(!IO), io.write_string("\nremove_prefix:\n", !IO), - ( + ( if string.remove_prefix(Str, Str, ""), string.remove_prefix("aรŸฮพ", Str, "ๅ••๐€€."), not string.remove_prefix("โ˜ฟ", Str, Str) - -> + then io.write_string("pass\n", !IO) - ; + else io.write_string("fail\n", !IO) ), io.write_string("\nremove_suffix:\n", !IO), - ( + ( if string.remove_suffix(Str, Str, ""), string.remove_suffix(Str, "ๅ••๐€€.", "aรŸฮพ"), not string.remove_suffix(Str, "โ˜ฟ", Str) - -> + then io.write_string("pass\n", !IO) - ; + else io.write_string("fail\n", !IO) ). diff --git a/tests/hard_coded/string_set_char.m b/tests/hard_coded/string_set_char.m index 659016260..94a39a5ee 100644 --- a/tests/hard_coded/string_set_char.m +++ b/tests/hard_coded/string_set_char.m @@ -21,40 +21,40 @@ %---------------------------------------------------------------------------% main(!IO) :- - ( string.set_char('x', -1, "", _) -> + ( if string.set_char('x', -1, "", _) then error("test failed") - ; + else true ), - ( string.set_char('x', 0, "", _) -> + ( if string.set_char('x', 0, "", _) then error("test failed") - ; + else true ), - ( string.set_char('x', 1, "", _) -> + ( if string.set_char('x', 1, "", _) then error("test failed") - ; + else true ), - ( string.set_char('m', 0, "cat", "mat") -> + ( if string.set_char('m', 0, "cat", "mat") then true - ; + else error("test failed") ), - ( string.set_char('u', 1, "cat", "cut") -> + ( if string.set_char('u', 1, "cat", "cut") then true - ; + else error("test failed") ), - ( string.set_char('b', 2, "cat", "cab") -> + ( if string.set_char('b', 2, "cat", "cab") then true - ; + else error("test failed") ), - ( string.set_char('x', 3, "cat", _) -> + ( if string.set_char('x', 3, "cat", _) then error("test failed") - ; + else true ), @@ -64,54 +64,54 @@ main(!IO) :- % รฝ 2 code units % แบ 3 code units % U+10000 4 code units - ( + ( if set_char_by_cp(".aรŸฮพๅ••๐€€.", 1, 'y', ".yรŸฮพๅ••๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 1, 'รฝ', ".รฝรŸฮพๅ••๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 1, 'แบ', ".แบรŸฮพๅ••๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 1, '๐€€', ".๐€€รŸฮพๅ••๐€€.") - -> + then true - ; + else io.write_string("variable-width set_char failed (1)\n", !IO) ), - ( + ( if set_char_by_cp(".aรŸฮพๅ••๐€€.", 2, 'y', ".ayฮพๅ••๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 2, 'รฝ', ".aรฝฮพๅ••๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 2, 'แบ', ".aแบฮพๅ••๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 2, '๐€€', ".a๐€€ฮพๅ••๐€€.") - -> + then true - ; + else io.write_string("variable-width set_char failed (2)\n", !IO) ), - ( + ( if set_char_by_cp(".aรŸฮพๅ••๐€€.", 3, 'y', ".aรŸyๅ••๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 3, 'รฝ', ".aรŸรฝๅ••๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 3, 'แบ', ".aรŸแบๅ••๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 3, '๐€€', ".aรŸ๐€€ๅ••๐€€.") - -> + then true - ; + else io.write_string("variable-width set_char failed (3)\n", !IO) ), - ( + ( if set_char_by_cp(".aรŸฮพๅ••๐€€.", 4, 'y', ".aรŸฮพy๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 4, 'รฝ', ".aรŸฮพรฝ๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 4, 'แบ', ".aรŸฮพแบ๐€€."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 4, '๐€€', ".aรŸฮพ๐€€๐€€.") - -> + then true - ; + else io.write_string("variable-width set_char failed (4)\n", !IO) ), - ( + ( if set_char_by_cp(".aรŸฮพๅ••๐€€.", 5, 'y', ".aรŸฮพๅ••y."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 5, 'รฝ', ".aรŸฮพๅ••รฝ."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 5, 'แบ', ".aรŸฮพๅ••แบ."), set_char_by_cp(".aรŸฮพๅ••๐€€.", 5, '๐€€', ".aรŸฮพๅ••๐€€.") - -> + then true - ; + else io.write_string("variable-width set_char failed (5)\n", !IO) ), diff --git a/tests/hard_coded/string_split.m b/tests/hard_coded/string_split.m index 7ad61b10e..947a60279 100644 --- a/tests/hard_coded/string_split.m +++ b/tests/hard_coded/string_split.m @@ -14,36 +14,36 @@ :- import_module string. main(!IO) :- - io__write_list( - split_at_separator(char__is_upper, ""), - ":", io__write_string, !IO), - io__nl(!IO), - io__write_list( - split_at_separator(char__is_upper, "!"), - ":", io__write_string, !IO), - io__nl(!IO), - io__write_list( - split_at_separator(char__is_upper, "helloXworldXhowXareYyou!"), - ":", io__write_string, !IO), - io__nl(!IO), - io__write_list( - split_at_separator(char__is_whitespace, "hello world\thow are\t\tyou!"), - "", io__write_string, !IO), - io__nl(!IO), - io__write_list( + io.write_list( + split_at_separator(char.is_upper, ""), + ":", io.write_string, !IO), + io.nl(!IO), + io.write_list( + split_at_separator(char.is_upper, "!"), + ":", io.write_string, !IO), + io.nl(!IO), + io.write_list( + split_at_separator(char.is_upper, "helloXworldXhowXareYyou!"), + ":", io.write_string, !IO), + io.nl(!IO), + io.write_list( + split_at_separator(char.is_whitespace, "hello world\thow are\t\tyou!"), + "", io.write_string, !IO), + io.nl(!IO), + io.write_list( split_at_char(':', "user:group:id1:id2"), - "", io__write_string, !IO), - io__nl(!IO), - io__write_list( + "", io.write_string, !IO), + io.nl(!IO), + io.write_list( split_at_string("aa", "xaaayaaaz"), - "", io__write_string, !IO), - io__nl(!IO), - io__write_list( + "", io.write_string, !IO), + io.nl(!IO), + io.write_list( split_at_string("aaa", "xaaaa aaaaax aaa x"), - "", io__write_string, !IO), - io__nl(!IO), - io__write_list( + "", io.write_string, !IO), + io.nl(!IO), + io.write_list( split_at_string(":::", "col1:::col2:val2:::col3:::"), - "", io__write_string, !IO), - io__nl(!IO), + "", io.write_string, !IO), + io.nl(!IO), true. diff --git a/tests/hard_coded/string_split_2.m b/tests/hard_coded/string_split_2.m index d17c6174f..fc0de48c3 100644 --- a/tests/hard_coded/string_split_2.m +++ b/tests/hard_coded/string_split_2.m @@ -16,15 +16,15 @@ :- import_module string. main(!IO) :- - ( + ( if string.split("cat", -1, "", "cat"), string.split("cat", 0, "", "cat"), string.split("cat", 1, "c", "at"), string.split("cat", 2, "ca", "t"), string.split("cat", 3, "cat", ""), string.split("cat", 4, "cat", "") - -> + then io.write_string("test succeeded\n", !IO) - ; + else io.write_string("test failed\n", !IO) ). diff --git a/tests/hard_coded/string_sub_string_search.m b/tests/hard_coded/string_sub_string_search.m index 7e3c4e32b..d91b18cbf 100644 --- a/tests/hard_coded/string_sub_string_search.m +++ b/tests/hard_coded/string_sub_string_search.m @@ -16,7 +16,7 @@ :- import_module string. main(!IO) :- - ( + ( if string.sub_string_search("", "", 0), not string.sub_string_search("", "dog", _), not string.sub_string_search("cat", "catdog", _), @@ -40,8 +40,8 @@ main(!IO) :- not string.sub_string_search_start("catcatcat", "cat", 10, _), string.sub_string_search("cฮฑtcฮฑฯ„cat", "cฮฑฯ„", length("cฮฑt")) - -> + then io.write_string("test succeeded\n", !IO) - ; + else io.write_string("test failed\n", !IO) ). diff --git a/tests/hard_coded/string_substring.m b/tests/hard_coded/string_substring.m index df0bfeb3c..feffc7d02 100644 --- a/tests/hard_coded/string_substring.m +++ b/tests/hard_coded/string_substring.m @@ -17,7 +17,7 @@ :- import_module string. main(!IO) :- - ( + ( if string.between("cat", -1, max_int, "cat"), string.between("cat", 0, max_int, "cat"), string.between("cat", 1, max_int, "at"), @@ -34,8 +34,8 @@ main(!IO) :- string.between("cat", 1, 2, "a"), string.between("cat", 1, 3, "at"), string.between("cat", 1, 4, "at") - -> + then io.write_string("test succeeded\n", !IO) - ; + else io.write_string("test failed\n", !IO) ). diff --git a/tests/hard_coded/string_suffix_bug.m b/tests/hard_coded/string_suffix_bug.m index 8361db212..ce4be4ddd 100644 --- a/tests/hard_coded/string_suffix_bug.m +++ b/tests/hard_coded/string_suffix_bug.m @@ -12,9 +12,9 @@ :- import_module string. -main --> - ( { string__suffix("testing string__suffix", "suffix") } -> - io__write_string("yes\n") - ; - io__write_string("no\n") +main(!IO) :- + ( if string.suffix("testing string__suffix", "suffix") then + io.write_string("yes\n", !IO) + else + io.write_string("no\n", !IO) ). diff --git a/tests/hard_coded/string_switch.m b/tests/hard_coded/string_switch.m index aaf2f0e62..c3be1afe2 100644 --- a/tests/hard_coded/string_switch.m +++ b/tests/hard_coded/string_switch.m @@ -4,6 +4,7 @@ % % The code of this test is identical to the code of string_switch2 and % string_switch3, but we compile them with different compilation options. +% :- module string_switch. @@ -46,32 +47,32 @@ main(!IO) :- :- pred test_jump(string::in, io::di, io::uo) is det. test_jump(S, !IO) :- - ( jump(S, 50, N) -> + ( if jump(S, 50, N) then io.format("jump %s -> %d\n", [s(S), i(N)], !IO) - ; + else io.format("jump %s failed\n", [s(S)], !IO) ). :- pred test_one(string::in, io::di, io::uo) is det. test_one(S, !IO) :- - ( one(S, N) -> + ( if one(S, N) then io.format("one %s -> %d\n", [s(S), i(N)], !IO) - ; + else io.format("one %s failed\n", [s(S)], !IO) ). :- pred test_one_known(string::in, io::di, io::uo) is det. test_one_known(S, !IO) :- - ( + ( if ( S = "aa" ; S = "bb" ), one(S, N) - -> + then io.format("one known %s -> %d\n", [s(S), i(N)], !IO) - ; + else io.format("one known %s failed\n", [s(S)], !IO) ). diff --git a/tests/hard_coded/string_switch2.m b/tests/hard_coded/string_switch2.m index 53c369f47..59242baa5 100644 --- a/tests/hard_coded/string_switch2.m +++ b/tests/hard_coded/string_switch2.m @@ -46,32 +46,32 @@ main(!IO) :- :- pred test_jump(string::in, io::di, io::uo) is det. test_jump(S, !IO) :- - ( jump(S, 50, N) -> + ( if jump(S, 50, N) then io.format("jump %s -> %d\n", [s(S), i(N)], !IO) - ; + else io.format("jump %s failed\n", [s(S)], !IO) ). :- pred test_one(string::in, io::di, io::uo) is det. test_one(S, !IO) :- - ( one(S, N) -> + ( if one(S, N) then io.format("one %s -> %d\n", [s(S), i(N)], !IO) - ; + else io.format("one %s failed\n", [s(S)], !IO) ). :- pred test_one_known(string::in, io::di, io::uo) is det. test_one_known(S, !IO) :- - ( + ( if ( S = "aa" ; S = "bb" ), one(S, N) - -> + then io.format("one known %s -> %d\n", [s(S), i(N)], !IO) - ; + else io.format("one known %s failed\n", [s(S)], !IO) ). diff --git a/tests/hard_coded/string_switch3.m b/tests/hard_coded/string_switch3.m index c74884bde..5d10ce01a 100644 --- a/tests/hard_coded/string_switch3.m +++ b/tests/hard_coded/string_switch3.m @@ -46,32 +46,32 @@ main(!IO) :- :- pred test_jump(string::in, io::di, io::uo) is det. test_jump(S, !IO) :- - ( jump(S, 50, N) -> + ( if jump(S, 50, N) then io.format("jump %s -> %d\n", [s(S), i(N)], !IO) - ; + else io.format("jump %s failed\n", [s(S)], !IO) ). :- pred test_one(string::in, io::di, io::uo) is det. test_one(S, !IO) :- - ( one(S, N) -> + ( if one(S, N) then io.format("one %s -> %d\n", [s(S), i(N)], !IO) - ; + else io.format("one %s failed\n", [s(S)], !IO) ). :- pred test_one_known(string::in, io::di, io::uo) is det. test_one_known(S, !IO) :- - ( + ( if ( S = "aa" ; S = "bb" ), one(S, N) - -> + then io.format("one known %s -> %d\n", [s(S), i(N)], !IO) - ; + else io.format("one known %s failed\n", [s(S)], !IO) ). diff --git a/tests/hard_coded/string_to_float_overflow.m b/tests/hard_coded/string_to_float_overflow.m index b769fa552..46cf25dcd 100644 --- a/tests/hard_coded/string_to_float_overflow.m +++ b/tests/hard_coded/string_to_float_overflow.m @@ -3,6 +3,7 @@ %---------------------------------------------------------------------------% % % Test the overflow behaviour of string.to_float/2. +% :- module string_to_float_overflow. :- interface. @@ -16,11 +17,13 @@ :- import_module string. main(!IO) :- - ( if string.to_float("4123e358", Float1) - then io.print_line(Float1, !IO) - else io.print_line("conversion (+) failed", !IO) + ( if string.to_float("4123e358", Float1) then + io.print_line(Float1, !IO) + else + io.print_line("conversion (+) failed", !IO) ), - ( if string.to_float("-4123e358", Float2) - then io.print_line(Float2, !IO) - else io.print_line("conversion (-) failed", !IO) + ( if string.to_float("-4123e358", Float2) then + io.print_line(Float2, !IO) + else + io.print_line("conversion (-) failed", !IO) ). diff --git a/tests/hard_coded/string_various.m b/tests/hard_coded/string_various.m index 6652a80ca..e17d04a98 100644 --- a/tests/hard_coded/string_various.m +++ b/tests/hard_coded/string_various.m @@ -14,10 +14,9 @@ :- import_module string. main(!IO) :- - io__write_string(remove_suffix_if_present(".gz", "myfile"), !IO), - io__nl(!IO), - io__write_string(remove_suffix_if_present(".gz", "myfile.gz"), !IO), - io__nl(!IO), - io__write_string(remove_suffix_if_present(".gz", "myfile.gz.gz"), !IO), - io__nl(!IO), - true. + io.write_string(remove_suffix_if_present(".gz", "myfile"), !IO), + io.nl(!IO), + io.write_string(remove_suffix_if_present(".gz", "myfile.gz"), !IO), + io.nl(!IO), + io.write_string(remove_suffix_if_present(".gz", "myfile.gz.gz"), !IO), + io.nl(!IO). diff --git a/tests/hard_coded/sv_nested_closures.m b/tests/hard_coded/sv_nested_closures.m index 7dba89c65..6667c56f7 100644 --- a/tests/hard_coded/sv_nested_closures.m +++ b/tests/hard_coded/sv_nested_closures.m @@ -17,14 +17,16 @@ main(!IO) :- some [!X] ( !:X = 10, - Foo = (pred(I::in, !.IO::di, !:IO::uo) is det :- - Bar = (pred(J::in, !.IO::di, !:IO::uo) is det :- - Result = J + I + !.X, - io.write_int(Result, !IO), - io.nl(!IO) + Foo = + ( pred(I::in, !.IO::di, !:IO::uo) is det :- + Bar = + ( pred(J::in, !.IO::di, !:IO::uo) is det :- + Result = J + I + !.X, + io.write_int(Result, !IO), + io.nl(!IO) + ), + Bar(4, !IO) ), - Bar(4, !IO) - ), Foo(3, !IO) ), baz(-200, X, !IO), @@ -35,11 +37,13 @@ main(!IO) :- baz(!Y, !IO) :- io.format("(baz) !.Y = %d\n", [i(!.Y)], !IO), - BazFoo = (pred(!.Y::in, !:Y::out, !.IO::di, !:IO::uo) is det :- - io.format("(BazFoo) !.Y = %d\n", [i(!.Y)], !IO), - BazBar = (pred(!.Z::in, !:Z::out, !.IO::di, !:IO::uo) is det :- - io.format("(BazBar) !.Y = %d\n", [i(!.Y)], !IO) + BazFoo = + ( pred(!.Y::in, !:Y::out, !.IO::di, !:IO::uo) is det :- + io.format("(BazFoo) !.Y = %d\n", [i(!.Y)], !IO), + BazBar = + ( pred(!.Z::in, !:Z::out, !.IO::di, !:IO::uo) is det :- + io.format("(BazBar) !.Y = %d\n", [i(!.Y)], !IO) + ), + BazBar(400, _, !IO) ), - BazBar(400, _, !IO) - ), BazFoo(700, _, !IO). diff --git a/tests/hard_coded/sv_record_update.m b/tests/hard_coded/sv_record_update.m index b7ef50e90..030abd952 100644 --- a/tests/hard_coded/sv_record_update.m +++ b/tests/hard_coded/sv_record_update.m @@ -38,6 +38,7 @@ main(!IO) :- io.nl(!IO). :- pred test1(type1::in, type1::out) is det. + test1(!Type1) :- !Type1 ^ field2 := 12. diff --git a/tests/hard_coded/switch_detect.m b/tests/hard_coded/switch_detect.m index cc49f2fc0..b6e5bf637 100644 --- a/tests/hard_coded/switch_detect.m +++ b/tests/hard_coded/switch_detect.m @@ -9,6 +9,7 @@ % condition containing X = h(I, F): that unification is equivalent to false % in one arm of the generated switch and to true in the other, but it is % not redundant in the source code. +% :- module switch_detect. :- interface. @@ -31,18 +32,17 @@ main(!IO) :- read_t(X, !IO), ( X = f, - io__write_string("f\n", !IO) + io.write_string("f\n", !IO) ; ( X = g(_) ; X = h(_, _) ), - io__write(X, !IO), - io__nl(!IO), - ( X = h(I, F) -> + io.write_line(X, !IO), + ( if X = h(I, F) then io.write_string("h: ", !IO), io.write_int(I, !IO), io.write_string(" ", !IO), io.write_float(F, !IO), io.nl(!IO) - ; + else true ) ), @@ -60,13 +60,13 @@ main(!IO) :- Num = Num0 + 5 ) ), - io__write_int(Num, !IO), - io__nl(!IO). + io.write_int(Num, !IO), + io.nl(!IO). :- pred read_t(t::out, io::di, io::uo) is det. read_t(X, !IO) :- - io__read(Res, !IO), + io.read(Res, !IO), ( Res = ok(X) ; diff --git a/tests/hard_coded/system_sort.m b/tests/hard_coded/system_sort.m index 4ff9a15b3..d0b85d109 100644 --- a/tests/hard_coded/system_sort.m +++ b/tests/hard_coded/system_sort.m @@ -4,6 +4,7 @@ % % This test case is to ensure that stdin/stdout are redirected correctly for % system commands. +% :- module system_sort. @@ -11,9 +12,9 @@ :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. -main --> - io__call_system("sort", _). +main(!IO) :- + io.call_system("sort", _, !IO). diff --git a/tests/hard_coded/var_not_found.m b/tests/hard_coded/var_not_found.m index 930b04ad1..e5236ac99 100644 --- a/tests/hard_coded/var_not_found.m +++ b/tests/hard_coded/var_not_found.m @@ -6,7 +6,8 @@ % (Oct 98) got a `var not found' error for this test case, due to % mode analysis producing incorrect instmap delta annotations % for the complicated unification in the implied mode in the -% first call to map__from_assoc_list in next/3. +% first call to map.from_assoc_list in next/3. +% :- module var_not_found. @@ -14,7 +15,7 @@ :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. @@ -30,12 +31,12 @@ :- import_module std_util. :- import_module string. -main --> - { map__from_assoc_list([int(1) - int(2)], Map) }, - ( { next(Map, Map, Next) } -> - write(Next), nl - ; - write_string("failed (as we should)\n") +main(!IO) :- + map.from_assoc_list([int(1) - int(2)], Map), + ( if next(Map, Map, Next) then + io.write_line(Next, !IO) + else + io.write_string("failed (as we should)\n", !IO) ). :- type data @@ -45,21 +46,20 @@ main --> ; array(map(data, data)) ; void. -:- pred next(map(data, data), map(data, data), map(data, data)). -:- mode next(in, in, out) is semidet. +:- pred next(map(data, data)::in, map(data, data)::in, map(data, data)::out) + is semidet. next(Thing, Array, Next) :- - map__to_assoc_list(Thing, [int(0) - Key, int(1) - _]), - map__to_assoc_list(Array, List), + map.to_assoc_list(Thing, [int(0) - Key, int(1) - _]), + map.to_assoc_list(Array, List), next_pair(List, Key, NewKey - NewValue), - map__from_assoc_list([int(0) - NewKey, int(1) - NewValue], Next). + map.from_assoc_list([int(0) - NewKey, int(1) - NewValue], Next). -:- pred next_pair(list(pair(data)), data, pair(data)). -:- mode next_pair(in, in, out) is semidet. +:- pred next_pair(list(pair(data))::in, data::in, pair(data)::out) is semidet. next_pair([Pair0 | Pairs], Key, Pair) :- - ( Pair0 = Key - _ -> + ( if Pair0 = Key - _ then Pairs = [Pair | _] - ; + else next_pair(Pairs, Key, Pair) ). diff --git a/tests/hard_coded/version_array_test.m b/tests/hard_coded/version_array_test.m index 172b18a6d..6162b9b03 100644 --- a/tests/hard_coded/version_array_test.m +++ b/tests/hard_coded/version_array_test.m @@ -31,7 +31,7 @@ main(!IO) :- A0 = version_array.empty, A1 = version_array(0`..`20), - % These two updates are overwritten but they're here to help test that + % These two updates are overwritten, but they are here to help test that % the rollback rolls back to the correct version, that is that changes % are applied in the correct order. version_array.set(3, 333, A1, A10), @@ -97,39 +97,45 @@ main(!IO) :- A8 = version_array([2, 4, 6, 8]), io.write_string("all_true(int.even A8): ", !IO), - ( if version_array.all_true(int.even, A8) - then io.write_string("passed\n", !IO) - else io.write_string("failed\n", !IO) + ( if version_array.all_true(int.even, A8) then + io.write_string("passed\n", !IO) + else + io.write_string("failed\n", !IO) ), io.write_string("all_false(int.odd, A8): ", !IO), - ( if version_array.all_false(int.odd, A8) - then io.write_string("passed\n", !IO) - else io.write_string("failed\n", !IO) + ( if version_array.all_false(int.odd, A8) then + io.write_string("passed\n", !IO) + else + io.write_string("failed\n", !IO) ), io.write_string("all_true(int.even, A0): ", !IO), - ( if version_array.all_true(int.even, A0) - then io.write_string("passed\n", !IO) - else io.write_string("failed\n", !IO) + ( if version_array.all_true(int.even, A0) then + io.write_string("passed\n", !IO) + else + io.write_string("failed\n", !IO) ), io.write_string("all_false(int.even, A0): ", !IO), - ( if version_array.all_false(int.even, A0) - then io.write_string("passed\n", !IO) - else io.write_string("failed\n", !IO) + ( if version_array.all_false(int.even, A0) then + io.write_string("passed\n", !IO) + else + io.write_string("failed\n", !IO) ), io.write_string("not all_true(int.odd, A8): ", !IO), - ( if not version_array.all_true(int.odd, A8) - then io.write_string("passed\n", !IO) - else io.write_string("failed\n", !IO) + ( if not version_array.all_true(int.odd, A8) then + io.write_string("passed\n", !IO) + else + io.write_string("failed\n", !IO) ), io.write_string("not all_false(int.even, A8): ", !IO), - ( if not version_array.all_false(int.even, A8) - then io.write_string("passed\n", !IO) - else io.write_string("failed\n", !IO) + ( if not version_array.all_false(int.even, A8) then + io.write_string("passed\n", !IO) + else + io.write_string("failed\n", !IO) ), FromList1 = version_array.from_list([] : list(int)), @@ -144,9 +150,7 @@ main(!IO) :- FromRevList2 = version_array.from_reverse_list([1]), write_array("from_reverse_list([1])", FromRevList2, !IO), FromRevList3 = version_array.from_reverse_list([2, 1]), - write_array("from_reverse_list([2, 1])", FromRevList3, !IO), - - true. + write_array("from_reverse_list([2, 1])", FromRevList3, !IO). :- pred test_exception((pred)::in((pred) is semidet), io::di, io::uo) is cc_multi. @@ -170,9 +174,9 @@ test_exception(Pred, !IO) :- make_a21(I, A0) = A :- X = A0 ^ elem(I), - ( X `mod` 2 = 0 -> + ( if X `mod` 2 = 0 then A = A0 ^ elem(I) := X * 3 - ; + else A = A0 ). diff --git a/tests/hard_coded/version_hash_table_test2.m b/tests/hard_coded/version_hash_table_test2.m index 0b949e40c..ecd13790a 100644 --- a/tests/hard_coded/version_hash_table_test2.m +++ b/tests/hard_coded/version_hash_table_test2.m @@ -53,9 +53,9 @@ main(!IO) :- ), NumOccupants0 = version_hash_table.num_occupants(!.HT), - ( NumOccupants0 = Max -> + ( if NumOccupants0 = Max then true - ; + else error("num_occupants failed") ), @@ -67,16 +67,16 @@ main(!IO) :- ), NumOccupants = version_hash_table.num_occupants(!.HT), - ( NumOccupants = Max - Half -> + ( if NumOccupants = Max - Half then true - ; + else error("num_occupants failed") ), AL = version_hash_table.to_assoc_list(!.HT), - ( list.length(AL) = NumOccupants -> + ( if list.length(AL) = NumOccupants then true - ; + else error("to_assoc_list failed") ), @@ -106,9 +106,9 @@ do_insert(I, !HT) :- do_lookup(I, !HT) :- V = version_hash_table.lookup(!.HT, I), - ( I = V -> + ( if I = V then true - ; + else error("do_lookup failed") ). @@ -117,9 +117,9 @@ do_lookup(I, !HT) :- do_lookup_neg(I, !HT) :- V = version_hash_table.lookup(!.HT, I), - ( -I = V -> + ( if -I = V then true - ; + else error("do_lookup failed") ). diff --git a/tests/hard_coded/write_reg1.m b/tests/hard_coded/write_reg1.m index 7dafd2222..ae1cf71bc 100644 --- a/tests/hard_coded/write_reg1.m +++ b/tests/hard_coded/write_reg1.m @@ -4,20 +4,21 @@ % % Regression test: % -% This test ensures that output from io__write is put on the correct -% output stream. All the functionality of io__write is tested so that +% This test ensures that output from io.write is put on the correct +% output stream. All the functionality of io.write is tested so that % an additional changes (such as adding a printf instead of a % fprintf(current_stream, ...)) should be caught. % % The Mercury compiler of 20 Dec 1996 failed to correctly run this test. % % Author: trd +% :- module write_reg1. :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is cc_multi. +:- pred main(io::di, io::uo) is cc_multi. :- implementation. @@ -28,13 +29,6 @@ :- import_module term. :- import_module univ. -:- pred test_builtins(io__output_stream::in, io__state::di, io__state::uo) - is cc_multi. -:- pred test_discriminated(io__state::di, io__state::uo) is det. -:- pred test_polymorphism(io__state::di, io__state::uo) is det. -:- pred test_other(io__state::di, io__state::uo) is det. -:- pred newline(io__state::di, io__state::uo) is det. - :- type enum ---> one ; two @@ -65,97 +59,107 @@ :- type no_tag ---> qwerty(int). -main --> - io__stderr_stream(StdErr), - io__set_output_stream(StdErr, _StdOut), - test_discriminated, - test_polymorphism, - test_builtins(StdErr), - test_other. +main(!IO) :- + io.stderr_stream(StdErr, !IO), + io.set_output_stream(StdErr, _StdOut, !IO), + test_discriminated(!IO), + test_polymorphism(!IO), + test_builtins(StdErr, !IO), + test_other(!IO). -test_discriminated --> - io__write_string("TESTING DISCRIMINATED UNIONS\n"), +:- pred test_discriminated(io::di, io::uo) is det. + +test_discriminated(!IO) :- + io.write_string("TESTING DISCRIMINATED UNIONS\n", !IO), % test enumerations - io__write(one), newline, - io__write(two), newline, - io__write(three), newline, + io.write(one, !IO), newline(!IO), + io.write(two, !IO), newline(!IO), + io.write(three, !IO), newline(!IO), % test simple tags - io__write(apple([9, 5, 1])), newline, - io__write(banana([three, one, two])), newline, + io.write(apple([9, 5, 1]), !IO), newline(!IO), + io.write(banana([three, one, two]), !IO), newline(!IO), % test complicated tags - io__write(zop(3.3, 2.03)), newline, - io__write(zip(3, 2)), newline, - io__write(zap(3, -2.111)), newline, + io.write(zop(3.3, 2.03), !IO), newline(!IO), + io.write(zip(3, 2), !IO), newline(!IO), + io.write(zap(3, -2.111), !IO), newline(!IO), % test complicated constant - io__write(wombat), newline, - io__write(foo), newline, + io.write(wombat, !IO), newline(!IO), + io.write(foo, !IO), newline(!IO), - newline. + newline(!IO). -test_polymorphism --> - io__write_string("TESTING POLYMORPHISM\n"), - io__write(poly_one([2399.3])), newline, - io__write(poly_two(3)), newline, - io__write(poly_three(3.33, 4, poly_one(9.11))), newline, +:- pred test_polymorphism(io::di, io::uo) is det. - newline. +test_polymorphism(!IO) :- + io.write_string("TESTING POLYMORPHISM\n", !IO), + io.write(poly_one([2399.3]) : poly(list(float), float), !IO), newline(!IO), + io.write(poly_two(3) : poly(int, int), !IO), newline(!IO), + io.write(poly_three(3.33, 4, poly_one(9.11)), !IO), newline(!IO), -test_builtins(StdErr) --> - io__write_string("TESTING BUILTINS\n"), + newline(!IO). + +:- pred test_builtins(io.output_stream::in, io::di, io::uo) is cc_multi. + +test_builtins(StdErr, !IO) :- + io.write_string("TESTING BUILTINS\n", !IO), % test strings - io__write(""), newline, - io__write("Hello, world\n"), newline, - io__write("Foo%sFoo"), newline, - io__write(""""), newline, % interesting - prints """ of course + io.write("", !IO), newline(!IO), + io.write("Hello, world\n", !IO), newline(!IO), + io.write("Foo%sFoo", !IO), newline(!IO), + io.write("""", !IO), newline(!IO), % interesting - prints """ of course % test characters - io__write('a'), newline, - io__write('&'), newline, + io.write('a', !IO), newline(!IO), + io.write('&', !IO), newline(!IO), % test floats - io__write(3.14159), newline, - io__write(11.28324983E-22), newline, - io__write(22.3954899E22), newline, + io.write(3.14159, !IO), newline(!IO), + io.write(11.28324983E-22, !IO), newline(!IO), + io.write(22.3954899E22, !IO), newline(!IO), % test integers - io__write(-65), newline, - io__write(4), newline, + io.write(-65, !IO), newline(!IO), + io.write(4, !IO), newline(!IO), % test univ. - { type_to_univ(["hi! I'm a univ!"], Univ) }, - io__write(Univ), newline, + type_to_univ(["hi! I'm a univ!"], Univ), + io.write(Univ, !IO), newline(!IO), % test predicates - io__write(newline), newline, - io__write(StdErr, include_details_cc, newline), newline, + io.write(newline, !IO), newline(!IO), + io.write(StdErr, include_details_cc, newline, !IO), newline(!IO), - newline. + newline(!IO). % Note: testing abstract types is always going to have results % that are dependent on the implementation. If someone changes % the implementation, the results of this test can change. + % +:- pred test_other(io::di, io::uo) is det. -test_other --> - io__write_string("TESTING OTHER TYPES\n"), - { term__init_var_supply(VarSupply) }, - { term__create_var(Var, VarSupply, NewVarSupply) }, - io__write(Var), newline, - io__write(VarSupply), newline, - io__write(NewVarSupply), newline, +test_other(!IO) :- + io.write_string("TESTING OTHER TYPES\n", !IO), + term.init_var_supply(VarSupply), + term.create_var(Var : var, VarSupply, NewVarSupply), + io.write(Var, !IO), newline(!IO), + io.write(VarSupply, !IO), newline(!IO), + io.write(NewVarSupply, !IO), newline(!IO), % presently, at least, map is an equivalence and an abstract type. - { map__init(Map) }, - io__write(Map), newline, + map.init(Map : map(int, int)), + io.write(Map, !IO), newline(!IO), % a no tag type - io__write(qwerty(4)), newline, + io.write(qwerty(4), !IO), newline(!IO), - newline. + newline(!IO). -newline --> - io__write_char('\n'). +:- pred newline(io::di, io::uo) is det. + +newline(!IO) :- + io.write_char('\n', !IO). diff --git a/tests/hard_coded/write_reg2.m b/tests/hard_coded/write_reg2.m index 6b2c491c3..48063006f 100644 --- a/tests/hard_coded/write_reg2.m +++ b/tests/hard_coded/write_reg2.m @@ -9,20 +9,19 @@ % The Mercury compiler of 12 Dec 2000 failed to correctly run this test. % % Author: trd +% :- module write_reg2. :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. :- import_module pair. :- import_module univ. -main --> - io__write(univ((1 - 2))), - io__nl, - io__write(univ({1, 2, 3})), - io__nl. +main(!IO) :- + io.write_line(univ((1 - 2)), !IO), + io.write_line(univ({1, 2, 3}), !IO).