From 59b11f84cedca3ded6084f0458678dda53fdaa13 Mon Sep 17 00:00:00 2001 From: Zoltan Somogyi Date: Tue, 28 Aug 2018 21:20:59 +1000 Subject: [PATCH] Update the debugger test directory. Replace __ with . as the module qualifier symbol. Replace references to io.state with just io. Replace DCGs with state variables. Replace (C->T;E) syntax for if-then-elses with (if C then T else E) syntax. Replace if-then-elses with switches when possible and where this does not affect what is being tested. Replace separate pred and mode declarations with predmode declarations. Put predicate and function declarations just before the definition of the predicate or function. Delete unneeded module qualifications on predicate and function declarations and definitions. Update .exp files (and if needed, .inp files) for the line number changes that result from the above. For tests that have more than one .exp file and where one of those files is affected by the above, add a section to the source file header that says which .exp file is for what grade, with XXXs for the (as yet) unknown parts. --- tests/debugger/all_solutions.m | 10 +- tests/debugger/breakpoints.a.m | 6 +- tests/debugger/breakpoints.a.testmod.m | 2 +- tests/debugger/breakpoints.b.m | 6 +- tests/debugger/breakpoints.b.testmod.m | 2 +- tests/debugger/breakpoints.exp | 24 +- tests/debugger/breakpoints.m | 74 ++-- tests/debugger/breakpoints.print_list.m | 44 ++- tests/debugger/browse_pretty.m | 12 +- tests/debugger/browser_test.m | 37 +- tests/debugger/chooser_tag_test.m | 12 +- tests/debugger/class_decl.exp | 2 +- tests/debugger/class_decl.m | 191 +++++----- tests/debugger/cmd_quote.m | 6 +- tests/debugger/completion.m | 8 +- tests/debugger/completion.sub1.m | 2 +- tests/debugger/completion.sub2.m | 4 +- tests/debugger/completion.sub2.sub3.m | 2 +- tests/debugger/cond.m | 36 +- tests/debugger/debugger_regs.m | 96 ++--- tests/debugger/deeply_nested_typeinfo.m | 16 +- tests/debugger/dice.exp | 176 ++++----- tests/debugger/dice.m | 30 +- tests/debugger/exception_cmd.m | 12 +- tests/debugger/exception_value.m | 19 +- tests/debugger/exception_vars.m | 14 +- tests/debugger/existential_type_classes.m | 22 +- tests/debugger/exported_eqv_type.m | 10 +- tests/debugger/fib.m | 12 +- tests/debugger/field_names.m | 46 +-- tests/debugger/foreign_type.m | 2 +- tests/debugger/higher_order.m | 36 +- tests/debugger/implied_instance.m | 18 +- tests/debugger/interactive.m | 102 +++--- tests/debugger/interpreter.exp2 | 14 +- tests/debugger/interpreter.m | 423 ++++++++++------------ tests/debugger/io_tab_goto.m | 110 +++--- tests/debugger/label_layout.m | 20 +- tests/debugger/lambda_expr.m | 4 +- tests/debugger/loopcheck.m | 8 +- tests/debugger/lval_desc_array.m | 12 +- tests/debugger/mdb_command_test.m | 4 +- tests/debugger/multi_parameter.exp | 4 +- tests/debugger/multi_parameter.m | 15 +- tests/debugger/mutrec.m | 40 +- tests/debugger/mutrec_higher_order.m | 80 ++-- tests/debugger/no_inline_builtins.m | 8 +- tests/debugger/nondet_stack.m | 74 ++-- tests/debugger/output_term_dep.m | 204 +++++------ tests/debugger/poly_io_retry.m | 2 +- tests/debugger/print_goal.m | 38 +- tests/debugger/print_io_actions.m | 12 +- tests/debugger/print_table.m | 163 +++++---- tests/debugger/queens.exp | 204 +++++------ tests/debugger/queens.inp | 2 +- tests/debugger/queens.m | 77 ++-- tests/debugger/queens_rep.exp | 2 +- tests/debugger/queens_rep.m | 82 ++--- tests/debugger/resume_typeinfos.m | 32 +- tests/debugger/retry.m | 79 ++-- tests/debugger/shallow.exp2 | 10 +- tests/debugger/shallow.m | 71 ++-- tests/debugger/shallow2.m | 14 +- tests/debugger/shell.m | 2 +- tests/debugger/solver_test.m | 26 +- tests/debugger/switch_on_unbounded.m | 8 +- tests/debugger/synth_attr.m | 22 +- tests/debugger/synth_attr_impure.m | 16 +- tests/debugger/tabled_read.m | 16 +- tests/debugger/tabled_read_decl.m | 110 +++--- tests/debugger/tabled_read_unitize.exp | 2 +- tests/debugger/tabled_read_unitize.m | 93 +++-- tests/debugger/tailrec1.m | 4 +- tests/debugger/type_desc_test.m | 28 +- tests/debugger/uci.m | 50 +-- tests/debugger/uci_index.m | 2 +- tests/debugger/user_event.m | 14 +- tests/debugger/user_event_2.m | 2 +- tests/debugger/user_event_shallow.m | 12 +- 79 files changed, 1593 insertions(+), 1713 deletions(-) diff --git a/tests/debugger/all_solutions.m b/tests/debugger/all_solutions.m index e19fdaad2..ddc084c27 100644 --- a/tests/debugger/all_solutions.m +++ b/tests/debugger/all_solutions.m @@ -3,7 +3,7 @@ %---------------------------------------------------------------------------% % % An example program to illustrate the use of all-solutions predicates -% in Mercury. This program just prints out all solutions to the +% in Mercury. This program just prints out all solutions to the % predicate hello/1. % This source file is hereby placed in the public domain. -fjh (the author). @@ -12,14 +12,14 @@ :- 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 solutions. -main --> - { solutions(hello, List) }, - io__write_strings(List). +main(!IO) :- + solutions(hello, List), + io.write_strings(List, !IO). :- pred hello(string::out) is multi. diff --git a/tests/debugger/breakpoints.a.m b/tests/debugger/breakpoints.a.m index 22645e9c7..d5bbd1846 100644 --- a/tests/debugger/breakpoints.a.m +++ b/tests/debugger/breakpoints.a.m @@ -2,12 +2,12 @@ % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -:- module breakpoints__a. +:- module breakpoints.a. :- interface. -:- include_module breakpoints__a__testmod. -:- import_module breakpoints__a__testmod. +:- include_module breakpoints.a.testmod. +:- import_module breakpoints.a.testmod. :- func afunc = int. diff --git a/tests/debugger/breakpoints.a.testmod.m b/tests/debugger/breakpoints.a.testmod.m index 5a9f4dcc6..b6f0352aa 100644 --- a/tests/debugger/breakpoints.a.testmod.m +++ b/tests/debugger/breakpoints.a.testmod.m @@ -2,7 +2,7 @@ % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -:- module breakpoints__a__testmod. +:- module breakpoints.a.testmod. :- interface. diff --git a/tests/debugger/breakpoints.b.m b/tests/debugger/breakpoints.b.m index 3d21c3f87..770e65e10 100644 --- a/tests/debugger/breakpoints.b.m +++ b/tests/debugger/breakpoints.b.m @@ -2,9 +2,9 @@ % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -:- module breakpoints__b. +:- module breakpoints.b. :- interface. -:- include_module breakpoints__b__testmod. -:- import_module breakpoints__b__testmod. +:- include_module breakpoints.b.testmod. +:- import_module breakpoints.b.testmod. diff --git a/tests/debugger/breakpoints.b.testmod.m b/tests/debugger/breakpoints.b.testmod.m index 50d268879..94679cbf9 100644 --- a/tests/debugger/breakpoints.b.testmod.m +++ b/tests/debugger/breakpoints.b.testmod.m @@ -2,7 +2,7 @@ % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -:- module breakpoints__b__testmod. +:- module breakpoints.b.testmod. :- interface. diff --git a/tests/debugger/breakpoints.exp b/tests/debugger/breakpoints.exp index faeec3309..b4e4a89d1 100644 --- a/tests/debugger/breakpoints.exp +++ b/tests/debugger/breakpoints.exp @@ -22,7 +22,7 @@ Ambiguous procedure specification. The matches are: Which do you want to put a breakpoint on (0-1 or *)? 1 0: + stop interface pred breakpoints.data/1-0 (det) mdb> continue - E2: C2 CALL pred breakpoints.data/1-0 (det) breakpoints.m:64 (breakpoints.m:62) + E2: C2 CALL pred breakpoints.data/1-0 (det) breakpoints.m:48 (breakpoints.m:44) mdb> disable 0 0: - stop interface pred breakpoints.data/1-0 (det) mdb> break info @@ -94,7 +94,7 @@ mdb> break_print -v -n -b1 HeadVar__1 HeadVar__2 1: + stop interface pred breakpoints.qperm/2-0 (nondet) HeadVar__1 (verbose, nowarn), HeadVar__2 (verbose, nowarn) mdb> continue - E3: C3 CALL pred breakpoints.qperm/2-0 (nondet) breakpoints.m:70 (breakpoints.m:67) + E3: C3 CALL pred breakpoints.qperm/2-0 (nondet) breakpoints.m:58 (breakpoints.m:53) HeadVar__1 [|] 1-1 @@ -112,13 +112,13 @@ mdb> break_print -p -n -b1 HeadVar__1 HeadVar__2 1: + stop interface pred breakpoints.qperm/2-0 (nondet) HeadVar__1 (pretty, nowarn), HeadVar__2 (pretty, nowarn) mdb> continue - E4: C3 SWTC pred breakpoints.qperm/2-0 (nondet) s2-2; breakpoints.m:71 + E4: C3 SWTC pred breakpoints.qperm/2-0 (nondet) s2-2; breakpoints.m:59 mdb> finish -N - E5: C4 CALL pred breakpoints.qperm/2-0 (nondet) breakpoints.m:70 (breakpoints.m:74) + E5: C4 CALL pred breakpoints.qperm/2-0 (nondet) breakpoints.m:58 (breakpoints.m:62) HeadVar__1 [2, 3, 4, 5] mdb> finish -n - E6: C4 EXIT pred breakpoints.qperm/2-0 (nondet) breakpoints.m:70 (breakpoints.m:74) + E6: C4 EXIT pred breakpoints.qperm/2-0 (nondet) breakpoints.m:58 (breakpoints.m:62) HeadVar__1 [2, 3, 4, 5] HeadVar__2 @@ -132,15 +132,15 @@ mdb> break_print -f -e -n -b1 HeadVar__2 1: + stop interface pred breakpoints.qperm/2-0 (nondet) HeadVar__1 (flat, nowarn), HeadVar__2 (flat, nowarn) mdb> continue - E7: C3 EXIT pred breakpoints.qperm/2-0 (nondet) breakpoints.m:70 (breakpoints.m:67) + E7: C3 EXIT pred breakpoints.qperm/2-0 (nondet) breakpoints.m:58 (breakpoints.m:53) HeadVar__1 [1, 2, 3, 4, 5] HeadVar__2 [1, 2, 3, 4, 5] mdb> continue - E8: C5 CALL pred breakpoints.safe/1-0 (semidet) breakpoints.m:80 (breakpoints.m:68) + E8: C5 CALL pred breakpoints.safe/1-0 (semidet) breakpoints.m:72 (breakpoints.m:54) mdb> finish - E9: C6 CALL pred breakpoints.nodiag/3-0 (semidet) breakpoints.m:85 (breakpoints.m:82) - E10: C6 FAIL pred breakpoints.nodiag/3-0 (semidet) breakpoints.m:85 (breakpoints.m:82) - E11: C5 FAIL pred breakpoints.safe/1-0 (semidet) breakpoints.m:80 (breakpoints.m:68) + E9: C6 CALL pred breakpoints.nodiag/3-0 (semidet) breakpoints.m:79 (breakpoints.m:74) + E10: C6 FAIL pred breakpoints.nodiag/3-0 (semidet) breakpoints.m:79 (breakpoints.m:74) + E11: C5 FAIL pred breakpoints.safe/1-0 (semidet) breakpoints.m:72 (breakpoints.m:54) mdb> delete * 0: E stop interface pred breakpoints.nodiag/3-0 (semidet) 1: E stop interface pred breakpoints.qperm/2-0 (nondet) @@ -162,14 +162,14 @@ mdb> break -i -I3 qperm 0: + stop interface pred breakpoints.qperm/2-0 (nondet) (ignore next 3 interface events) mdb> continue - E12: C7 REDO pred breakpoints.qperm/2-0 (nondet) breakpoints.m:70 (breakpoints.m:74) + E12: C7 REDO pred breakpoints.qperm/2-0 (nondet) breakpoints.m:58 (breakpoints.m:62) mdb> print * HeadVar__1 [4, 5] mdb> ignore -E4 0 0: + stop interface pred breakpoints.qperm/2-0 (nondet) (ignore next 4 call events) mdb> continue - E13: C8 CALL pred breakpoints.qperm/2-0 (nondet) breakpoints.m:70 (breakpoints.m:74) + E13: C8 CALL pred breakpoints.qperm/2-0 (nondet) breakpoints.m:58 (breakpoints.m:62) mdb> print * HeadVar__1 [] mdb> delete * diff --git a/tests/debugger/breakpoints.m b/tests/debugger/breakpoints.m index e027e8bbd..48042151a 100644 --- a/tests/debugger/breakpoints.m +++ b/tests/debugger/breakpoints.m @@ -8,89 +8,83 @@ :- import_module io. -:- pred main(io__state, io__state). +:- pred main(io, io). :- mode main(di, uo) is cc_multi. :- func string / string = string. :- implementation. -:- include_module breakpoints__print_list. -:- include_module breakpoints__a. -:- include_module breakpoints__b. -:- import_module breakpoints__print_list. -:- import_module breakpoints__a. -:- import_module breakpoints__b. -:- import_module breakpoints__a__testmod. -:- import_module breakpoints__b__testmod. +:- include_module breakpoints.print_list. +:- include_module breakpoints.a. +:- include_module breakpoints.b. +:- import_module breakpoints.print_list. +:- import_module breakpoints.a. +:- import_module breakpoints.b. +:- import_module breakpoints.a.testmod. +:- import_module breakpoints.b.testmod. :- import_module list. :- import_module int. :- import_module string. -main --> - ( { queen(data, Out) } -> - print_list(Out), - io__write(test_in_a), - io__nl, - io__write(test_in_b), - io__nl - ; - io__write_string("No solution\n") +main(!IO) :- + ( if queen(data, Out) then + print_list(Out, !IO), + io.write(test_in_a, !IO), + io.nl(!IO), + io.write(test_in_b, !IO), + io.nl(!IO) + else + io.write_string("No solution\n", !IO) ). :- func data = list(int). -:- pred data(list(int)). -:- mode data(out) is det. - -:- pred queen(list(int), list(int)). -:- mode queen(in, out) is nondet. - -:- pred qperm(list(T), list(T)). -:- mode qperm(in, out) is nondet. - -:- pred qdelete(T, list(T), list(T)). -:- mode qdelete(out, in, out) is nondet. - -:- pred safe(list(int)). -:- mode safe(in) is semidet. - -:- pred nodiag(int, int, list(int)). -:- mode nodiag(in, in, in) is semidet. - data = D :- data(D). +:- pred data(list(int)::out) is det. + data([1, 2, 3, 4, 5]). +:- pred queen(list(int)::in, list(int)::out) is nondet. + queen(Data, Out) :- qperm(Data, Out), safe(Out). +:- pred qperm(list(T)::in, list(T)::out) is nondet. + qperm([], []). qperm([X | Y], K) :- qdelete(U, [X | Y], Z), K = [U | V], qperm(Z, V). +:- pred qdelete(T::out, list(T)::in, list(T)::out) is nondet. + qdelete(A, [A | L], L). qdelete(X, [A | Z], [A | R]) :- qdelete(X, Z, R). +:- pred safe(list(int)::in) is semidet. + safe([]). safe([N | L]) :- nodiag(N, 1, L), safe(L). +:- pred nodiag(int::in, int::in, list(int)::in) is semidet. + nodiag(_, _, []). nodiag(B, D, [N | L]) :- NmB = N - B, BmN = B - N, - ( D = NmB -> + ( if D = NmB then fail - ; D = BmN -> + else if D = BmN then fail - ; + else true ), D1 = D + 1, @@ -101,4 +95,4 @@ X / _ = X. :- pred test_in_both(io::di, io::uo) is det. test_in_both(!IO) :- - io__write_string("test_in_both in breakpoints\n", !IO). + io.write_string("test_in_both in breakpoints\n", !IO). diff --git a/tests/debugger/breakpoints.print_list.m b/tests/debugger/breakpoints.print_list.m index 9b6e0c895..e534b80e7 100644 --- a/tests/debugger/breakpoints.print_list.m +++ b/tests/debugger/breakpoints.print_list.m @@ -2,56 +2,54 @@ % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -:- module breakpoints__print_list. +:- module breakpoints.print_list. :- interface. :- import_module list. :- import_module io. -:- pred print_list(list(int), io__state, io__state). +:- pred print_list(list(int), io, io). :- mode print_list(in, di, uo) is det. :- func string / string = string. :- func string - string = string. -:- pred test_only_in_printlist(io__state::di, io__state::uo) is det. +:- pred test_only_in_printlist(io::di, io::uo) is det. -:- pred test_in_both(io__state::di, io__state::uo) is det. +:- pred test_in_both(io::di, io::uo) is det. :- implementation. -print_list(Xs) --> +print_list(Xs, !IO) :- ( - { Xs = [] } - -> - io__write_string("[]\n") + Xs = [], + io.write_string("[]\n", !IO) ; - io__write_string("["), - print_list_2(Xs), - io__write_string("]\n") + Xs = [_ | _], + io.write_string("[", !IO), + print_list_2(Xs, !IO), + io.write_string("]\n", !IO) ). -:- pred print_list_2(list(int), io__state, io__state). -:- mode print_list_2(in, di, uo) is det. +:- pred print_list_2(list(int)::in, io::di, io::uo) is det. -print_list_2([]) --> []. -print_list_2([X | Xs]) --> - io__write_int(X), +print_list_2([], !IO). +print_list_2([X | Xs], !IO) :- + io.write_int(X, !IO), ( - { Xs = [] } - -> - [] + Xs = [] ; - io__write_string(", "), - print_list_2(Xs) + Xs = [_ | _], + io.write_string(", ", !IO), + print_list_2(Xs, !IO) ). Str1 / Str2 = Str1 ++ "/" ++ Str2. Str1 - Str2 = Str1 ++ "-" ++ Str2. test_only_in_printlist(!IO) :- - io__write_string("test_only_in_printlist\n", !IO). + io.write_string("test_only_in_printlist\n", !IO). test_in_both(!IO) :- - io__write_string("test_in_both\n", !IO). + io.write_string("test_in_both\n", !IO). diff --git a/tests/debugger/browse_pretty.m b/tests/debugger/browse_pretty.m index 7a77777e9..d0b0f6dab 100644 --- a/tests/debugger/browse_pretty.m +++ b/tests/debugger/browse_pretty.m @@ -6,19 +6,19 @@ :- 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 list. :- type big ---> big(big, list(int), big) - ; small. + ; small. -main --> - { big_data(Data) }, - io__print(Data), - io__write_string(".\n"). +main(!IO) :- + big_data(Data), + io.print(Data, !IO), + io.write_string(".\n", !IO). :- pred big_data(big::out) is det. diff --git a/tests/debugger/browser_test.m b/tests/debugger/browser_test.m index 3fe661f15..ff6fbc284 100644 --- a/tests/debugger/browser_test.m +++ b/tests/debugger/browser_test.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. @@ -19,19 +19,19 @@ main(!IO) :- % In case we have these files lying around. - io__remove_file("browser_test.save.1", _, !IO), - io__remove_file("browser_test.save.2", _, !IO), + io.remove_file("browser_test.save.1", _, !IO), + io.remove_file("browser_test.save.2", _, !IO), big_data(Data), - io__print(Data, !IO), - io__write_string(".\n", !IO), + io.print(Data, !IO), + io.write_string(".\n", !IO), list_data(List), - io__print(List, !IO), - io__write_string(".\n", !IO), + io.print(List, !IO), + io.write_string(".\n", !IO), print_file("browser_test.save.1", !IO), print_file("browser_test.save.2", !IO), % Clean up after the test. - io__remove_file("browser_test.save.1", _, !IO), - io__remove_file("browser_test.save.2", _, !IO), + io.remove_file("browser_test.save.1", _, !IO), + io.remove_file("browser_test.save.2", _, !IO), a_func(Data) = Data2, write(Data2, !IO), nl(!IO). @@ -92,25 +92,26 @@ list_data(Data) :- :- pred print_file(string::in, io::di, io::uo) is det. print_file(FileName, !IO) :- - io__open_input(FileName, OpenRes, !IO), + io.open_input(FileName, OpenRes, !IO), ( OpenRes = ok(Stream), - io__read_file_as_string(Stream, ReadRes, !IO), + io.read_file_as_string(Stream, ReadRes, !IO), ( ReadRes = ok(Contents), - io__write_string(FileName, !IO), - io__write_string(":\n", !IO), - io__write_string(Contents, !IO), - io__write_string("\n", !IO) + io.write_string(FileName, !IO), + io.write_string(":\n", !IO), + io.write_string(Contents, !IO), + io.write_string("\n", !IO) ; ReadRes = error(_, _), - io__write_string("read failed\n", !IO) + io.write_string("read failed\n", !IO) ) ; OpenRes = error(_), - io__write_string("open failed\n", !IO) + io.write_string("open failed\n", !IO) ). :- func a_func(big) = big. -a_func(_) = Big :- big_data(Big). +a_func(_) = Big :- + big_data(Big). diff --git a/tests/debugger/chooser_tag_test.m b/tests/debugger/chooser_tag_test.m index ba026cdd0..a39c35f06 100644 --- a/tests/debugger/chooser_tag_test.m +++ b/tests/debugger/chooser_tag_test.m @@ -67,9 +67,9 @@ test_wraps(!IO) :- test_wrap_a(A0, !IO) :- wrap_a(A0, X), - ( unwrap_a(X, A1_Prime) -> + ( if unwrap_a(X, A1_Prime) then MaybeA1 = yes(A1_Prime) - ; + else MaybeA1 = no ), io.write_string("test_wrap_a: A0 = ", !IO), @@ -90,9 +90,9 @@ test_wrap_a(A0, !IO) :- test_wrap_b(B0, !IO) :- wrap_b(B0, X), - ( unwrap_b(X, B1_Prime) -> + ( if unwrap_b(X, B1_Prime) then MaybeB1 = yes(B1_Prime) - ; + else MaybeB1 = no ), io.write_string("test_wrap_b: B0 = ", !IO), @@ -113,9 +113,9 @@ test_wrap_b(B0, !IO) :- test_wrap_c(C0, !IO) :- wrap_c(C0, X), - ( unwrap_c(X, C1_Prime) -> + ( if unwrap_c(X, C1_Prime) then MaybeC1 = yes(C1_Prime) - ; + else MaybeC1 = no ), io.write_string("test_wrap_c: C0 = ", !IO), diff --git a/tests/debugger/class_decl.exp b/tests/debugger/class_decl.exp index cfcbbac93..4d77a023c 100644 --- a/tests/debugger/class_decl.exp +++ b/tests/debugger/class_decl.exp @@ -1,4 +1,4 @@ - 1: 1 1 CALL pred class_decl.main/2-0 (det) class_decl.m:25 + 1: 1 1 CALL pred class_decl.main/2-0 (det) class_decl.m:43 mdb> echo on Command echo enabled. mdb> register --quiet diff --git a/tests/debugger/class_decl.m b/tests/debugger/class_decl.m index 13fcaa83c..1e01d7f4c 100644 --- a/tests/debugger/class_decl.m +++ b/tests/debugger/class_decl.m @@ -7,120 +7,129 @@ :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. +%---------------------------------------------------------------------------% + :- typeclass foo(T) where [ - pred foo_method(T::in, io__state::di, io__state::uo) is det + pred foo_method(T::in, io::di, io::uo) is det ]. :- typeclass bar(T, U) where [ - pred bar_method(T::in, U::in, io__state::di, io__state::uo) is det + pred bar_method(T::in, U::in, io::di, io::uo) is det ]. -:- type t1 ---> t1(int). -:- type t2(T) ---> t2a(T) ; t2b(T, T). +:- type t1 + ---> t1(int). -main --> - foo_method("zero"), - foo_method(t1(10)), - foo_method(t2a(20)), - foo_method(t2b(30, 40)), - foo_method(t2b("thirty", "forty")), - bar_method(11, 22), - bar_method("eleven", 22), - bar_method("eleven", "twentytwo"), - bar_method(t1(111), 222), - bar_method(t1(333), t2a(444)), - bar_method(t1(333), t2b(444, 555)), - bar_method(t1(888), t2b("sixsixsix", "sevensevenseven")). +:- type t2(T) + ---> t2a(T) + ; t2b(T, T). :- instance foo(string) where [pred(foo_method/3) is foo_string]. :- instance foo(t1) where [pred(foo_method/3) is foo_t1]. :- instance foo(t2(U)) where [pred(foo_method/3) is foo_t2]. -:- pred foo_string(string::in, io__state::di, io__state::uo) is det. -:- pred foo_t1(t1::in, io__state::di, io__state::uo) is det. -:- pred foo_t2(t2(V)::in, io__state::di, io__state::uo) is det. - -foo_string(S) --> - io__write_string("string: "), - io__write_string(S), - io__nl. - -foo_t1(t1(I)) --> - io__write_string("t1: "), - io__write_int(I), - io__nl. - -foo_t2(t2a(I)) --> - io__write_string("t2a: "), - io__write(I), - io__nl. -foo_t2(t2b(I1, I2)) --> - io__write_string("t2b: "), - io__write(I1), - io__write_string(", "), - io__write(I2), - io__nl. - :- instance bar(int, int) where [pred(bar_method/4) is bar_int_int]. :- instance bar(string, int) where [pred(bar_method/4) is bar_str_int]. :- instance bar(string, string) where [pred(bar_method/4) is bar_str_str]. :- instance bar(t1, int) where [pred(bar_method/4) is bar_t1_int]. :- instance bar(t1, t2(U)) where [pred(bar_method/4) is bar_t1_t2]. -:- pred bar_int_int(int::in, int::in, - io__state::di, io__state::uo) is det. -:- pred bar_str_int(string::in, int::in, - io__state::di, io__state::uo) is det. -:- pred bar_str_str(string::in, string::in, - io__state::di, io__state::uo) is det. -:- pred bar_t1_int(t1::in, int::in, - io__state::di, io__state::uo) is det. -:- pred bar_t1_t2(t1::in, t2(V)::in, - io__state::di, io__state::uo) is det. +%---------------------------------------------------------------------------% -bar_int_int(I1, I2) --> - io__write_string("ii: "), - io__write_int(I1), - io__write_string(", "), - io__write_int(I2), - io__nl. +main(!IO) :- + foo_method("zero", !IO), + foo_method(t1(10), !IO), + foo_method(t2a(20), !IO), + foo_method(t2b(30, 40), !IO), + foo_method(t2b("thirty", "forty"), !IO), + bar_method(11, 22, !IO), + bar_method("eleven", 22, !IO), + bar_method("eleven", "twentytwo", !IO), + bar_method(t1(111), 222, !IO), + bar_method(t1(333), t2a(444), !IO), + bar_method(t1(333), t2b(444, 555), !IO), + bar_method(t1(888), t2b("sixsixsix", "sevensevenseven"), !IO). -bar_str_int(S1, I2) --> - io__write_string("si: "), - io__write_string(S1), - io__write_string(", "), - io__write_int(I2), - io__nl. +:- pred foo_string(string::in, io::di, io::uo) is det. -bar_str_str(S1, S2) --> - io__write_string("ss: "), - io__write_string(S1), - io__write_string(", "), - io__write_string(S2), - io__nl. +foo_string(S, !IO) :- + io.write_string("string: ", !IO), + io.write_string(S, !IO), + io.nl(!IO). -bar_t1_int(t1(I1), I2) --> - io__write_string("t1int: "), - io__write_int(I1), - io__write_string(", "), - io__write_int(I2), - io__nl. +:- pred foo_t1(t1::in, io::di, io::uo) is det. -bar_t1_t2(t1(I1), t2a(I2)) --> - io__write_string("t1t2a: "), - io__write_int(I1), - io__write_string(", "), - io__write(I2), - io__nl. -bar_t1_t2(t1(I1), t2b(I2, I3)) --> - io__write_string("t1t2b: "), - io__write_int(I1), - io__write_string(", "), - io__write(I2), - io__write_string(", "), - io__write(I3), - io__nl. +foo_t1(t1(I), !IO) :- + io.write_string("t1: ", !IO), + io.write_int(I, !IO), + io.nl(!IO). + +:- pred foo_t2(t2(V)::in, io::di, io::uo) is det. + +foo_t2(t2a(I), !IO) :- + io.write_string("t2a: ", !IO), + io.write(I, !IO), + io.nl(!IO). +foo_t2(t2b(I1, I2), !IO) :- + io.write_string("t2b: ", !IO), + io.write(I1, !IO), + io.write_string(", ", !IO), + io.write(I2, !IO), + io.nl(!IO). + +:- pred bar_int_int(int::in, int::in, io::di, io::uo) is det. + +bar_int_int(I1, I2, !IO) :- + io.write_string("ii: ", !IO), + io.write_int(I1, !IO), + io.write_string(", ", !IO), + io.write_int(I2, !IO), + io.nl(!IO). + +:- pred bar_str_int(string::in, int::in, io::di, io::uo) is det. + +bar_str_int(S1, I2, !IO) :- + io.write_string("si: ", !IO), + io.write_string(S1, !IO), + io.write_string(", ", !IO), + io.write_int(I2, !IO), + io.nl(!IO). + +:- pred bar_str_str(string::in, string::in, io::di, io::uo) is det. + +bar_str_str(S1, S2, !IO) :- + io.write_string("ss: ", !IO), + io.write_string(S1, !IO), + io.write_string(", ", !IO), + io.write_string(S2, !IO), + io.nl(!IO). + +:- pred bar_t1_int(t1::in, int::in, io::di, io::uo) is det. + +bar_t1_int(t1(I1), I2, !IO) :- + io.write_string("t1int: ", !IO), + io.write_int(I1, !IO), + io.write_string(", ", !IO), + io.write_int(I2, !IO), + io.nl(!IO). + +:- pred bar_t1_t2(t1::in, t2(V)::in, io::di, io::uo) is det. + +bar_t1_t2(t1(I1), t2a(I2), !IO) :- + io.write_string("t1t2a: ", !IO), + io.write_int(I1, !IO), + io.write_string(", ", !IO), + io.write(I2, !IO), + io.nl(!IO). +bar_t1_t2(t1(I1), t2b(I2, I3), !IO) :- + io.write_string("t1t2b: ", !IO), + io.write_int(I1, !IO), + io.write_string(", ", !IO), + io.write(I2, !IO), + io.write_string(", ", !IO), + io.write(I3, !IO), + io.nl(!IO). diff --git a/tests/debugger/cmd_quote.m b/tests/debugger/cmd_quote.m index 671a039c0..6a600cdbb 100644 --- a/tests/debugger/cmd_quote.m +++ b/tests/debugger/cmd_quote.m @@ -6,10 +6,10 @@ :- interface. :- 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("Hello world!\n"). +main(!IO) :- + io.write_string("Hello world!\n", !IO). diff --git a/tests/debugger/completion.m b/tests/debugger/completion.m index c0d06e630..7756f1ab6 100644 --- a/tests/debugger/completion.m +++ b/tests/debugger/completion.m @@ -8,14 +8,14 @@ :- import_module io. -:- include_module completion__sub1, completion__sub2. +:- include_module completion.sub1, completion.sub2. -:- 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). :- func z = int. z = 0. diff --git a/tests/debugger/completion.sub1.m b/tests/debugger/completion.sub1.m index 5609cc46e..04b72eeb4 100644 --- a/tests/debugger/completion.sub1.m +++ b/tests/debugger/completion.sub1.m @@ -2,7 +2,7 @@ % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -:- module completion__sub1. +:- module completion.sub1. :- interface. diff --git a/tests/debugger/completion.sub2.m b/tests/debugger/completion.sub2.m index f32887444..1cab80e0b 100644 --- a/tests/debugger/completion.sub2.m +++ b/tests/debugger/completion.sub2.m @@ -2,11 +2,11 @@ % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -:- module completion__sub2. +:- module completion.sub2. :- interface. -:- include_module completion__sub2__sub3. +:- include_module completion.sub2.sub3. :- func z2 = int. diff --git a/tests/debugger/completion.sub2.sub3.m b/tests/debugger/completion.sub2.sub3.m index 303892c87..0c8c8db47 100644 --- a/tests/debugger/completion.sub2.sub3.m +++ b/tests/debugger/completion.sub2.sub3.m @@ -2,7 +2,7 @@ % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -:- module completion__sub2__sub3. +:- module completion.sub2.sub3. :- interface. diff --git a/tests/debugger/cond.m b/tests/debugger/cond.m index 1599da5de..e70588144 100644 --- a/tests/debugger/cond.m +++ b/tests/debugger/cond.m @@ -18,7 +18,7 @@ :- type t ---> empty - ; node(t, int, t). + ; node(t, int, t). main(!IO) :- test_maybe(!IO), @@ -39,33 +39,33 @@ test_maybe(!IO) :- p(no, A), p(yes(2), B), p(yes(3), C), - io__write([A, B, C], !IO), - io__nl(!IO). + io.write([A, B, C], !IO), + io.nl(!IO). :- pred test_string(io::di, io::uo) is det. test_string(!IO) :- q("abc", A), - io__write_string(A, !IO), - io__nl(!IO), + io.write_string(A, !IO), + io.nl(!IO), q("def", B), - io__write_string(B, !IO), - io__nl(!IO), + io.write_string(B, !IO), + io.nl(!IO), q("ghi", C), - io__write_string(C, !IO), - io__nl(!IO). + io.write_string(C, !IO), + io.nl(!IO). :- pred test_tree(io::di, io::uo) is det. test_tree(!IO) :- r(1, A), s(A, AA), - io__write(AA, !IO), - io__nl(!IO), + io.write(AA, !IO), + io.nl(!IO), r(2, B), s(B, BB), - io__write(BB, !IO), - io__nl(!IO). + io.write(BB, !IO), + io.nl(!IO). :- pred p(maybe(int)::in, maybe(int)::out) is det. @@ -81,20 +81,20 @@ p(X, Y) :- :- pred q(string::in, string::out) is det. q(X, Y) :- - ( X = "abc" -> + ( if X = "abc" then Y = "xabcx" - ; X = "def" -> + else if X = "def" then Y = "ydefy" - ; + else Y = "else" ). :- pred r(int::in, t::out) is det. r(X, Y) :- - ( X = 0 -> + ( if X = 0 then Y = empty - ; + else r(X - 1, S), Y = node(S, X, S) ). diff --git a/tests/debugger/debugger_regs.m b/tests/debugger/debugger_regs.m index 4a0573569..9dc06e4cb 100644 --- a/tests/debugger/debugger_regs.m +++ b/tests/debugger/debugger_regs.m @@ -13,7 +13,7 @@ :- import_module io. -:- pred main(io__state, io__state). +:- pred main(io, io). :- mode main(di, uo) is det. :- implementation. @@ -21,7 +21,7 @@ :- import_module list. :- import_module int. -main --> +main(!IO) :- % The purpose of list is to force the tracer to call the Mercury % code to print a list of integers, when the input script asks % for the outputs of data to be printed. In the past this was @@ -30,55 +30,55 @@ main --> % are derived from the register contents produced by data, % or from the register contents left there by the code that % prints _List. - { data(_List, + data(_List, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, - D0, D1, D2, D3, D4, D5, D6, D7, D8, D9) }, - io__write_string(A0), - io__write_string(A1), - io__write_string(A2), - io__write_string(A3), - io__write_string(A4), - io__write_string(A5), - io__write_string(A6), - io__write_string(A7), - io__write_string(A8), - io__write_string(A9), - io__write_string("\n"), - io__write_string(B0), - io__write_string(B1), - io__write_string(B2), - io__write_string(B3), - io__write_string(B4), - io__write_string(B5), - io__write_string(B6), - io__write_string(B7), - io__write_string(B8), - io__write_string(B9), - io__write_string("\n"), - io__write_string(C0), - io__write_string(C1), - io__write_string(C2), - io__write_string(C3), - io__write_string(C4), - io__write_string(C5), - io__write_string(C6), - io__write_string(C7), - io__write_string(C8), - io__write_string(C9), - io__write_string("\n"), - io__write_string(D0), - io__write_string(D1), - io__write_string(D2), - io__write_string(D3), - io__write_string(D4), - io__write_string(D5), - io__write_string(D6), - io__write_string(D7), - io__write_string(D8), - io__write_string(D9), - io__write_string("\n"). + D0, D1, D2, D3, D4, D5, D6, D7, D8, D9), + io.write_string(A0, !IO), + io.write_string(A1, !IO), + io.write_string(A2, !IO), + io.write_string(A3, !IO), + io.write_string(A4, !IO), + io.write_string(A5, !IO), + io.write_string(A6, !IO), + io.write_string(A7, !IO), + io.write_string(A8, !IO), + io.write_string(A9, !IO), + io.write_string("\n", !IO), + io.write_string(B0, !IO), + io.write_string(B1, !IO), + io.write_string(B2, !IO), + io.write_string(B3, !IO), + io.write_string(B4, !IO), + io.write_string(B5, !IO), + io.write_string(B6, !IO), + io.write_string(B7, !IO), + io.write_string(B8, !IO), + io.write_string(B9, !IO), + io.write_string("\n", !IO), + io.write_string(C0, !IO), + io.write_string(C1, !IO), + io.write_string(C2, !IO), + io.write_string(C3, !IO), + io.write_string(C4, !IO), + io.write_string(C5, !IO), + io.write_string(C6, !IO), + io.write_string(C7, !IO), + io.write_string(C8, !IO), + io.write_string(C9, !IO), + io.write_string("\n", !IO), + io.write_string(D0, !IO), + io.write_string(D1, !IO), + io.write_string(D2, !IO), + io.write_string(D3, !IO), + io.write_string(D4, !IO), + io.write_string(D5, !IO), + io.write_string(D6, !IO), + io.write_string(D7, !IO), + io.write_string(D8, !IO), + io.write_string(D9, !IO), + io.write_string("\n", !IO). :- pred data(list(int)::out, string::out, string::out, string::out, string::out, string::out, diff --git a/tests/debugger/deeply_nested_typeinfo.m b/tests/debugger/deeply_nested_typeinfo.m index a76ead600..c0bbcc387 100644 --- a/tests/debugger/deeply_nested_typeinfo.m +++ b/tests/debugger/deeply_nested_typeinfo.m @@ -43,7 +43,7 @@ :- instance foo(int). :- instance foo(list(T)) <= foo(T). -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. :- import_module list. @@ -62,18 +62,18 @@ main --> :- pred list_b(list(T)::in) is semidet <= foo(T). list_b(List) :- - list__map((pred(A::in, A::out) is semidet :- b(A)), List, _). + list.map((pred(A::in, A::out) is semidet :- b(A)), List, _). :- pred int_b(int::in) is semidet. int_b(1). -:- pred blah(T, io__state, io__state) <= foo(list(T)). +:- pred blah(T, io, io) <= foo(list(T)). :- mode blah(in, di, uo) is det. -blah(X) --> - ( { b([X]) } -> - io__write_string("true\n") - ; - io__write_string("false\n") +blah(X, !IO) :- + ( if b([X]) then + io.write_string("true\n", !IO) + else + io.write_string("false\n", !IO) ). diff --git a/tests/debugger/dice.exp b/tests/debugger/dice.exp index 11b712ea9..d670303d5 100644 --- a/tests/debugger/dice.exp +++ b/tests/debugger/dice.exp @@ -1,114 +1,114 @@ - E1: C1 CALL pred dice.main/2-0 (det) dice.m:24 + E1: C1 CALL pred dice.main/2-0 (det) dice.m:32 mdb> mdb> Contexts will not be printed. mdb> echo on Command echo enabled. mdb> dice -f dice.fail -p dice.passes -m dice Procedure Path/Port File:Line Pass (3) Fail Suspicion -pred dice.main/2-0 CALL dice.m:24 3 (3) 1 0.25 -pred dice.main/2-0 EXIT dice.m:24 3 (3) 1 0.25 -pred dice.main/2-0 dice.m:27 3 (3) 1 0.25 -pred dice.main/2-0 dice.m:29 3 (3) 1 0.25 -pred dice.merge/3-0 CALL dice.m:71 18 (3) 7 0.28 -pred dice.merge/3-0 EXIT dice.m:71 18 (3) 7 0.28 -pred dice.merge/3-0 dice.m:71 8 (3) 3 0.27 -pred dice.merge/3-0 dice.m:73 8 (3) 3 0.27 -pred dice.merge/3-0 dice.m:72 10 (3) 4 0.29 -pred dice.merge/3-0 dice.m:74 10 (3) 4 0.29 -pred dice.merge/3-0 dice.m:76 10 (3) 4 0.29 +pred dice.main/2-0 CALL dice.m:32 3 (3) 1 0.25 +pred dice.main/2-0 EXIT dice.m:32 3 (3) 1 0.25 +pred dice.main/2-0 dice.m:34 3 (3) 1 0.25 +pred dice.main/2-0 dice.m:35 3 (3) 1 0.25 +pred dice.merge/3-0 CALL dice.m:73 18 (3) 7 0.28 +pred dice.merge/3-0 EXIT dice.m:73 18 (3) 7 0.28 +pred dice.merge/3-0 dice.m:73 8 (3) 3 0.27 +pred dice.merge/3-0 dice.m:75 8 (3) 3 0.27 +pred dice.merge/3-0 dice.m:74 10 (3) 4 0.29 +pred dice.merge/3-0 dice.m:76 10 (3) 4 0.29 +pred dice.merge/3-0 dice.m:77 10 (3) 4 0.29 pred dice.merge/3-0 dice.m:78 10 (3) 3 0.23 pred dice.merge/3-0 dice.m:81 0 (0) 1 1.00 -pred dice.merge_sort/2-0 CALL dice.m:38 3 (3) 1 0.25 -pred dice.merge_sort/2-0 EXIT dice.m:38 3 (3) 1 0.25 -pred dice.msort_n/4-0 CALL dice.m:44 19 (3) 7 0.27 -pred dice.msort_n/4-0 EXIT dice.m:44 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:46 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:61 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:51 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:57 11 (3) 4 0.27 -pred dice.msort_n/4-0 dice.m:54 11 (3) 4 0.27 -pred dice.msort_n/4-0 dice.m:62 8 (3) 3 0.27 +pred dice.merge_sort/2-0 CALL dice.m:44 3 (3) 1 0.25 +pred dice.merge_sort/2-0 EXIT dice.m:44 3 (3) 1 0.25 +pred dice.msort_n/4-0 CALL dice.m:50 19 (3) 7 0.27 +pred dice.msort_n/4-0 EXIT dice.m:50 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:51 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:54 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:54 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:59 11 (3) 4 0.27 +pred dice.msort_n/4-0 dice.m:56 11 (3) 4 0.27 +pred dice.msort_n/4-0 dice.m:64 8 (3) 3 0.27 mdb> fail_trace_counts dice.fail mdb> pass_trace_counts dice.passes mdb> dice -sS -m dice Procedure Path/Port File:Line Pass (3) Fail Suspicion pred dice.merge/3-0 dice.m:81 0 (0) 1 1.00 -pred dice.merge/3-0 dice.m:72 10 (3) 4 0.29 -pred dice.merge/3-0 dice.m:74 10 (3) 4 0.29 -pred dice.merge/3-0 dice.m:76 10 (3) 4 0.29 -pred dice.merge/3-0 CALL dice.m:71 18 (3) 7 0.28 -pred dice.merge/3-0 EXIT dice.m:71 18 (3) 7 0.28 -pred dice.merge/3-0 dice.m:71 8 (3) 3 0.27 -pred dice.merge/3-0 dice.m:73 8 (3) 3 0.27 -pred dice.msort_n/4-0 dice.m:62 8 (3) 3 0.27 -pred dice.msort_n/4-0 CALL dice.m:44 19 (3) 7 0.27 -pred dice.msort_n/4-0 EXIT dice.m:44 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:46 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:61 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:51 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:57 11 (3) 4 0.27 -pred dice.msort_n/4-0 dice.m:54 11 (3) 4 0.27 -pred dice.main/2-0 CALL dice.m:24 3 (3) 1 0.25 -pred dice.main/2-0 EXIT dice.m:24 3 (3) 1 0.25 -pred dice.main/2-0 dice.m:27 3 (3) 1 0.25 -pred dice.main/2-0 dice.m:29 3 (3) 1 0.25 -pred dice.merge_sort/2-0 CALL dice.m:38 3 (3) 1 0.25 -pred dice.merge_sort/2-0 EXIT dice.m:38 3 (3) 1 0.25 +pred dice.merge/3-0 dice.m:74 10 (3) 4 0.29 +pred dice.merge/3-0 dice.m:76 10 (3) 4 0.29 +pred dice.merge/3-0 dice.m:77 10 (3) 4 0.29 +pred dice.merge/3-0 CALL dice.m:73 18 (3) 7 0.28 +pred dice.merge/3-0 EXIT dice.m:73 18 (3) 7 0.28 +pred dice.merge/3-0 dice.m:73 8 (3) 3 0.27 +pred dice.merge/3-0 dice.m:75 8 (3) 3 0.27 +pred dice.msort_n/4-0 dice.m:64 8 (3) 3 0.27 +pred dice.msort_n/4-0 CALL dice.m:50 19 (3) 7 0.27 +pred dice.msort_n/4-0 EXIT dice.m:50 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:51 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:54 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:54 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:59 11 (3) 4 0.27 +pred dice.msort_n/4-0 dice.m:56 11 (3) 4 0.27 +pred dice.main/2-0 CALL dice.m:32 3 (3) 1 0.25 +pred dice.main/2-0 EXIT dice.m:32 3 (3) 1 0.25 +pred dice.main/2-0 dice.m:34 3 (3) 1 0.25 +pred dice.main/2-0 dice.m:35 3 (3) 1 0.25 +pred dice.merge_sort/2-0 CALL dice.m:44 3 (3) 1 0.25 +pred dice.merge_sort/2-0 EXIT dice.m:44 3 (3) 1 0.25 pred dice.merge/3-0 dice.m:78 10 (3) 3 0.23 mdb> dice -sSF -m dice Procedure Path/Port File:Line Pass (3) Fail Suspicion pred dice.merge/3-0 dice.m:81 0 (0) 1 1.00 -pred dice.merge/3-0 dice.m:72 10 (3) 4 0.29 -pred dice.merge/3-0 dice.m:74 10 (3) 4 0.29 -pred dice.merge/3-0 dice.m:76 10 (3) 4 0.29 -pred dice.merge/3-0 CALL dice.m:71 18 (3) 7 0.28 -pred dice.merge/3-0 EXIT dice.m:71 18 (3) 7 0.28 -pred dice.merge/3-0 dice.m:71 8 (3) 3 0.27 -pred dice.merge/3-0 dice.m:73 8 (3) 3 0.27 -pred dice.msort_n/4-0 dice.m:62 8 (3) 3 0.27 -pred dice.msort_n/4-0 CALL dice.m:44 19 (3) 7 0.27 -pred dice.msort_n/4-0 EXIT dice.m:44 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:46 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:61 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:51 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:57 11 (3) 4 0.27 -pred dice.msort_n/4-0 dice.m:54 11 (3) 4 0.27 -pred dice.main/2-0 CALL dice.m:24 3 (3) 1 0.25 -pred dice.main/2-0 EXIT dice.m:24 3 (3) 1 0.25 -pred dice.main/2-0 dice.m:27 3 (3) 1 0.25 -pred dice.main/2-0 dice.m:29 3 (3) 1 0.25 -pred dice.merge_sort/2-0 CALL dice.m:38 3 (3) 1 0.25 -pred dice.merge_sort/2-0 EXIT dice.m:38 3 (3) 1 0.25 +pred dice.merge/3-0 dice.m:74 10 (3) 4 0.29 +pred dice.merge/3-0 dice.m:76 10 (3) 4 0.29 +pred dice.merge/3-0 dice.m:77 10 (3) 4 0.29 +pred dice.merge/3-0 CALL dice.m:73 18 (3) 7 0.28 +pred dice.merge/3-0 EXIT dice.m:73 18 (3) 7 0.28 +pred dice.merge/3-0 dice.m:73 8 (3) 3 0.27 +pred dice.merge/3-0 dice.m:75 8 (3) 3 0.27 +pred dice.msort_n/4-0 dice.m:64 8 (3) 3 0.27 +pred dice.msort_n/4-0 CALL dice.m:50 19 (3) 7 0.27 +pred dice.msort_n/4-0 EXIT dice.m:50 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:51 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:54 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:54 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:59 11 (3) 4 0.27 +pred dice.msort_n/4-0 dice.m:56 11 (3) 4 0.27 +pred dice.main/2-0 CALL dice.m:32 3 (3) 1 0.25 +pred dice.main/2-0 EXIT dice.m:32 3 (3) 1 0.25 +pred dice.main/2-0 dice.m:34 3 (3) 1 0.25 +pred dice.main/2-0 dice.m:35 3 (3) 1 0.25 +pred dice.merge_sort/2-0 CALL dice.m:44 3 (3) 1 0.25 +pred dice.merge_sort/2-0 EXIT dice.m:44 3 (3) 1 0.25 pred dice.merge/3-0 dice.m:78 10 (3) 3 0.23 mdb> dice -n 3 -s P -m dice Procedure Path/Port File:Line Pass (3) Fail Suspicion -pred dice.msort_n/4-0 CALL dice.m:44 19 (3) 7 0.27 -pred dice.msort_n/4-0 EXIT dice.m:44 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:46 19 (3) 7 0.27 +pred dice.msort_n/4-0 CALL dice.m:50 19 (3) 7 0.27 +pred dice.msort_n/4-0 EXIT dice.m:50 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:51 19 (3) 7 0.27 mdb> dice -s Fp -m dice Procedure Path/Port File:Line Pass (3) Fail Suspicion -pred dice.merge/3-0 CALL dice.m:71 18 (3) 7 0.28 -pred dice.merge/3-0 EXIT dice.m:71 18 (3) 7 0.28 -pred dice.msort_n/4-0 CALL dice.m:44 19 (3) 7 0.27 -pred dice.msort_n/4-0 EXIT dice.m:44 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:46 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:61 19 (3) 7 0.27 -pred dice.msort_n/4-0 dice.m:51 19 (3) 7 0.27 -pred dice.merge/3-0 dice.m:72 10 (3) 4 0.29 -pred dice.merge/3-0 dice.m:74 10 (3) 4 0.29 -pred dice.merge/3-0 dice.m:76 10 (3) 4 0.29 -pred dice.msort_n/4-0 dice.m:57 11 (3) 4 0.27 -pred dice.msort_n/4-0 dice.m:54 11 (3) 4 0.27 -pred dice.merge/3-0 dice.m:71 8 (3) 3 0.27 -pred dice.merge/3-0 dice.m:73 8 (3) 3 0.27 -pred dice.msort_n/4-0 dice.m:62 8 (3) 3 0.27 +pred dice.merge/3-0 CALL dice.m:73 18 (3) 7 0.28 +pred dice.merge/3-0 EXIT dice.m:73 18 (3) 7 0.28 +pred dice.msort_n/4-0 CALL dice.m:50 19 (3) 7 0.27 +pred dice.msort_n/4-0 EXIT dice.m:50 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:51 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:54 19 (3) 7 0.27 +pred dice.msort_n/4-0 dice.m:54 19 (3) 7 0.27 +pred dice.merge/3-0 dice.m:74 10 (3) 4 0.29 +pred dice.merge/3-0 dice.m:76 10 (3) 4 0.29 +pred dice.merge/3-0 dice.m:77 10 (3) 4 0.29 +pred dice.msort_n/4-0 dice.m:59 11 (3) 4 0.27 +pred dice.msort_n/4-0 dice.m:56 11 (3) 4 0.27 +pred dice.merge/3-0 dice.m:73 8 (3) 3 0.27 +pred dice.merge/3-0 dice.m:75 8 (3) 3 0.27 +pred dice.msort_n/4-0 dice.m:64 8 (3) 3 0.27 pred dice.merge/3-0 dice.m:78 10 (3) 3 0.23 pred dice.merge/3-0 dice.m:81 0 (0) 1 1.00 -pred dice.main/2-0 CALL dice.m:24 3 (3) 1 0.25 -pred dice.main/2-0 EXIT dice.m:24 3 (3) 1 0.25 -pred dice.main/2-0 dice.m:27 3 (3) 1 0.25 -pred dice.main/2-0 dice.m:29 3 (3) 1 0.25 -pred dice.merge_sort/2-0 CALL dice.m:38 3 (3) 1 0.25 -pred dice.merge_sort/2-0 EXIT dice.m:38 3 (3) 1 0.25 +pred dice.main/2-0 CALL dice.m:32 3 (3) 1 0.25 +pred dice.main/2-0 EXIT dice.m:32 3 (3) 1 0.25 +pred dice.main/2-0 dice.m:34 3 (3) 1 0.25 +pred dice.main/2-0 dice.m:35 3 (3) 1 0.25 +pred dice.merge_sort/2-0 CALL dice.m:44 3 (3) 1 0.25 +pred dice.merge_sort/2-0 EXIT dice.m:44 3 (3) 1 0.25 mdb> dice -sS -n 1 --module dice Procedure Path/Port File:Line Pass (3) Fail Suspicion pred dice.merge/3-0 dice.m:81 0 (0) 1 1.00 diff --git a/tests/debugger/dice.m b/tests/debugger/dice.m index e4382fede..e7da17487 100644 --- a/tests/debugger/dice.m +++ b/tests/debugger/dice.m @@ -5,6 +5,14 @@ % Test the mdb `dice' command. % Buggy merge sort taken from Lee Naish's probabalistic declarative debugging % paper. +% +%---------------------------------------------------------------------------% +% +% The .exp file is for asm_fast.gc bootchecks. +% The .exp2 file is for XXX. +% The .exp3 file is for XXX. +% +%---------------------------------------------------------------------------% :- module dice. @@ -23,13 +31,11 @@ main(!IO) :- io.command_line_arguments(Args, !IO), - ( - list.map(string.to_int, Args, Ints) - -> + ( if list.map(string.to_int, Args, Ints) then merge_sort(Ints, Sorted), io.write(Sorted, !IO), io.nl(!IO) - ; + else io.write_string("usage error\n", !IO) ). @@ -42,14 +48,10 @@ merge_sort(Us, Ss) :- :- pred msort_n(int::in, list(int)::in, list(int)::out, list(int)::out) is det. msort_n(N, Unsorted, SortedPart, Rest) :- - ( - N =< 0 - -> + ( if N =< 0 then SortedPart = [], Rest = Unsorted - ; - N = 1 - -> + else if N = 1 then ( Unsorted = [U | Us], SortedPart = [U], @@ -58,7 +60,7 @@ msort_n(N, Unsorted, SortedPart, Rest) :- Unsorted = [], throw("Unsorted = [] and N = 0") ) - ; + else N1 = N // 2, dice.msort_n(N1, Unsorted, Ss1, Us2), N2 = N - N1, @@ -72,12 +74,10 @@ merge([], [], []). merge([S | Ss], [], [S | Ss]). merge([], [S | Ss], [S | Ss]). merge([A | As], [B | Bs], [C | Cs]) :- - ( - A =< B - -> + ( if A =< B then dice.merge(As, [B | Bs], Cs), C = A - ; + else dice.merge(As, [B | Bs], Cs), % BUG C = B ). diff --git a/tests/debugger/exception_cmd.m b/tests/debugger/exception_cmd.m index 34128ce56..b5c5dbe2e 100644 --- a/tests/debugger/exception_cmd.m +++ b/tests/debugger/exception_cmd.m @@ -7,22 +7,22 @@ :- 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 require. :- import_module int. -main --> - { test(42, X) }, - print(X). +main(!IO) :- + test(42, X), + io.print(X, !IO). :- pred test(int::in, int::out) is det. test(X, Y) :- - ( X > 0 -> + ( if X > 0 then error("oops") - ; + else Y = X + 1 ). diff --git a/tests/debugger/exception_value.m b/tests/debugger/exception_value.m index 14ad9c6e9..adf247b49 100644 --- a/tests/debugger/exception_value.m +++ b/tests/debugger/exception_value.m @@ -1,13 +1,13 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module exception_value. :- 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. @@ -15,13 +15,13 @@ :- import_module list. :- import_module pair. -main --> - { test1(Res1) }, - print(Res1), - io__nl, - { test2(Res2) }, - print(Res2), - io__nl. +main(!IO) :- + test1(Res1), + print(Res1, !IO), + io.nl(!IO), + test2(Res2), + print(Res2, !IO), + io.nl(!IO). :- pred test1(exception_result(int)::out) is cc_multi. test1(Res) :- @@ -40,4 +40,3 @@ p(_) :- q(_) :- throw("q oops" - [1, 2, 3]). - diff --git a/tests/debugger/exception_vars.m b/tests/debugger/exception_vars.m index 62cad9b4e..8900c1699 100644 --- a/tests/debugger/exception_vars.m +++ b/tests/debugger/exception_vars.m @@ -1,28 +1,28 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module exception_vars. :- 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 require. :- import_module int. -main --> - { test(42, X) }, - print(X). +main(!IO) :- + test(42, X), + io.print(X, !IO). :- pred test(int::in, int::out) is det. test(X, Y) :- - ( X > 0 -> + ( if X > 0 then error("oops") - ; + else Y = X + 1 ). diff --git a/tests/debugger/existential_type_classes.m b/tests/debugger/existential_type_classes.m index 52d526bd7..2b38d2cf6 100644 --- a/tests/debugger/existential_type_classes.m +++ b/tests/debugger/existential_type_classes.m @@ -9,7 +9,7 @@ :- interface. :- import_module io. -:- pred main(io__state::di, state::uo) is det. +:- pred main(io::di, state::uo) is det. :- implementation. :- import_module std_util. @@ -50,23 +50,21 @@ int_foo(X, 2*X). :- pred string_foo(string::in, int::out) is det. -string_foo(S, N) :- string__length(S, N). +string_foo(S, N) :- string.length(S, N). -main --> - { +main(!IO) :- do_foo(42, T1), do_foo("blah", T2), do_foo(my_exist_t, T3), do_foo(call_my_exist_t, T4), do_foo(my_univ_value(my_univ(45)), T5), - do_foo(call_my_univ_value(my_univ("something")), T6) - }, - io__write_int(T1), nl, - io__write_int(T2), nl, - io__write_int(T3), nl, - io__write_int(T4), nl, - io__write_int(T5), nl, - io__write_int(T6), nl. + do_foo(call_my_univ_value(my_univ("something")), T6), + io.write_int(T1, !IO), io.nl(!IO), + io.write_int(T2, !IO), io.nl(!IO), + io.write_int(T3, !IO), io.nl(!IO), + io.write_int(T4, !IO), io.nl(!IO), + io.write_int(T5, !IO), io.nl(!IO), + io.write_int(T6, !IO), io.nl(!IO). :- pred do_foo(T::in, int::out) is det <= fooable(T). diff --git a/tests/debugger/exported_eqv_type.m b/tests/debugger/exported_eqv_type.m index 7d59bebd5..8457ec06f 100644 --- a/tests/debugger/exported_eqv_type.m +++ b/tests/debugger/exported_eqv_type.m @@ -22,12 +22,12 @@ main(!IO) :- X = p(2, 55), Y = p(3, "a"), - io__write(X, !IO), - io__nl(!IO), - io__write(Y, !IO), - io__nl(!IO). + io.write(X, !IO), + io.nl(!IO), + io.write(Y, !IO), + io.nl(!IO). :- func p(int, bug(T)) = bug(list(T)). p(Num, Item) = Dups :- - list__duplicate(Num, Item, Dups). + list.duplicate(Num, Item, Dups). diff --git a/tests/debugger/fib.m b/tests/debugger/fib.m index 3593a75cb..194d85c96 100644 --- a/tests/debugger/fib.m +++ b/tests/debugger/fib.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module fib. :- interface. @@ -25,7 +25,7 @@ main(!IO) :- perform_trial(N, !IO) :- trial(N, _Time, _MTime), - io__write_string("got same results\n", !IO). + io.write_string("got same results\n", !IO). :- pred trial(int::in, int::out, int::out) is cc_multi. @@ -37,9 +37,9 @@ trial(N, Time, MTime) :- :- pred fib(int::in, int::out) is det. fib(N, F) :- - ( N < 2 -> + ( if N < 2 then F = 1 - ; + else fib(N - 1, F1), fib(N - 2, F2), F = F1 + F2 @@ -49,9 +49,9 @@ fib(N, F) :- :- pragma memo(mfib/2, [allow_reset]). mfib(N, F) :- - ( N < 2 -> + ( if N < 2 then F = 1 - ; + else mfib(N - 1, F1), mfib(N - 2, F2), F = F1 + F2 diff --git a/tests/debugger/field_names.m b/tests/debugger/field_names.m index a74b11aa2..6f12633c9 100644 --- a/tests/debugger/field_names.m +++ b/tests/debugger/field_names.m @@ -1,13 +1,13 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module field_names. :- interface. :- import_module io. -:- pred main(io__state::di, state::uo) is det. +:- pred main(io.state::di, state::uo) is det. :- implementation. @@ -65,27 +65,27 @@ :- type dummy ---> dummy. -main --> - { make_t1f1(41, 42, 43, 44, T1F1) }, - { make_t1f2(51, 52, 53, T1F2) }, - { make_t2(0.6, 61, T1F1, T1F2, T2) }, - { make_t3(T1F2, 72, T1F1, T3) }, - { make_t4(T2, T4) }, - { make_t5(T1F1, T5) }, - { make_t6(0.9, T6) }, - { make_t7(0.9, 77, T7) }, - { make_t8(T8) }, - { make_dummy(Dummy) }, - io__write(T1F1), nl, - io__write(T1F2), nl, - io__write(T2), nl, - io__write(T3), nl, - io__write(T4), nl, - io__write(T5), nl, - io__write(T6), nl, - io__write(T7), nl, - io__write(T8), nl, - io__write(Dummy), nl. +main(!IO) :- + make_t1f1(41, 42, 43, 44, T1F1), + make_t1f2(51, 52, 53, T1F2), + make_t2(0.6, 61, T1F1, T1F2, T2), + make_t3(T1F2, 72, T1F1, T3), + make_t4(T2, T4), + make_t5(T1F1, T5), + make_t6(0.9, T6), + make_t7(0.9, 77, T7), + make_t8(T8), + make_dummy(Dummy), + io.write_line(T1F1, !IO), + io.write_line(T1F2, !IO), + io.write_line(T2, !IO), + io.write_line(T3, !IO), + io.write_line(T4, !IO), + io.write_line(T5, !IO), + io.write_line(T6, !IO), + io.write_line(T7, !IO), + io.write_line(T8, !IO), + io.write_line(Dummy, !IO). :- pred make_t1f1(int::in, int::in, int::in, int::in, t1::out) is det. make_t1f1(A, B, C, D, t1f1(A, B, C, D)). diff --git a/tests/debugger/foreign_type.m b/tests/debugger/foreign_type.m index e6b238ace..5b98c7705 100644 --- a/tests/debugger/foreign_type.m +++ b/tests/debugger/foreign_type.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module foreign_type. :- interface. diff --git a/tests/debugger/higher_order.m b/tests/debugger/higher_order.m index f6a4c0c45..86b7b5a04 100644 --- a/tests/debugger/higher_order.m +++ b/tests/debugger/higher_order.m @@ -1,13 +1,13 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module higher_order. :- interface. :- import_module io. -:- pred main(io__state::di, state::uo) is det. +:- pred main(io::di, state::uo) is det. :- implementation. @@ -15,23 +15,23 @@ :- import_module float. :- import_module list. -main --> - { IntIn = [1, 2, 3, 4, 5] }, - { FloatIn = [1.0, 2.0, 3.0, 4.0, 5.0] }, - { IntListIn = [[1, 2], [3, 4, 5]] }, - { StringListIn = [["one", "two"], ["three", "four", "five"]] }, +main(!IO) :- + IntIn = [1, 2, 3, 4, 5], + FloatIn = [1.0, 2.0, 3.0, 4.0, 5.0], + IntListIn = [[1, 2], [3, 4, 5]], + StringListIn = [["one", "two"], ["three", "four", "five"]], - { domap(float_add2(3.0), FloatIn, FloatAdd2Out) }, - { domap(float_op3(4.0, 5.0), FloatIn, FloatOp3Out) }, - { domap(int__max(3), IntIn, IntMaxOut) }, - { domap(do_append([6]), IntListIn, IntAppendOut) }, - { domap(do_append(["a"]), StringListIn, StringAppendOut) }, + domap(float_add2(3.0), FloatIn, FloatAdd2Out), + domap(float_op3(4.0, 5.0), FloatIn, FloatOp3Out), + domap(int.max(3), IntIn, IntMaxOut), + domap(do_append([6]), IntListIn, IntAppendOut), + domap(do_append(["a"]), StringListIn, StringAppendOut), - io__write(FloatAdd2Out), nl, - io__write(FloatOp3Out), nl, - io__write(IntMaxOut), nl, - io__write(IntAppendOut), nl, - io__write(StringAppendOut), nl. + io.write_line(FloatAdd2Out, !IO), + io.write_line(FloatOp3Out, !IO), + io.write_line(IntMaxOut, !IO), + io.write_line(IntAppendOut, !IO), + io.write_line(StringAppendOut, !IO). :- pred domap(pred(X, Y), list(X), list(Y)). :- mode domap(pred(in, out) is det, in, out) is det. @@ -52,4 +52,4 @@ float_op3(A, B, C, A + B * C). :- pred do_append(list(T)::in, list(T)::in, list(T)::out) is det. do_append(A, B, C) :- - list__append(A, B, C). + list.append(A, B, C). diff --git a/tests/debugger/implied_instance.m b/tests/debugger/implied_instance.m index 321004a2d..dc41a06e1 100644 --- a/tests/debugger/implied_instance.m +++ b/tests/debugger/implied_instance.m @@ -1,12 +1,12 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module implied_instance. :- interface. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- import_module io. @@ -27,13 +27,13 @@ pred(p/2) is sum_int_list ]. -main --> - { p(2, SumA) }, - { p([42, 24, 1, 2, 3], SumB) }, - io__write_int(SumA), - io__write_string("\n"), - io__write_int(SumB), - io__write_string("\n"). +main(!IO) :- + p(2, SumA), + p([42, 24, 1, 2, 3], SumB), + io.write_int(SumA, !IO), + io.write_string("\n", !IO), + io.write_int(SumB, !IO), + io.write_string("\n", !IO). :- pred copy_int(int, int). :- mode copy_int(in, out) is det. diff --git a/tests/debugger/interactive.m b/tests/debugger/interactive.m index 3bbefdb35..05ed5005a 100644 --- a/tests/debugger/interactive.m +++ b/tests/debugger/interactive.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module interactive. :- interface. @@ -9,39 +9,26 @@ :- import_module io. :- import_module list. -:- pred main(io__state, io__state). -:- mode main(di, uo) is cc_multi. +:- pred main(io::di, io::uo) is cc_multi. % exported for use with interactive queries in the debugger -:- pred queen(list(int), list(int)). -:- mode queen(in, out) is nondet. +:- pred queen(list(int)::in, list(int)::out) is nondet. % exported for use with interactive queries in the debugger -:- pred qperm(list(T), list(T)). -:- mode qperm(in, out) is nondet. +:- pred qperm(list(T)::in, list(T)::out) is nondet. :- implementation. :- import_module int. -main --> - ( { data(Data), queen(Data, Out) } -> - print_list(Out) - ; - io__write_string("No solution\n") +main(!IO) :- + ( if data(Data), queen(Data, Out) then + print_list(Out, !IO) + else + io.write_string("No solution\n", !IO) ). -:- pred data(list(int)). -:- mode data(out) is det. - -:- pred qdelete(T, list(T), list(T)). -:- mode qdelete(out, in, out) is nondet. - -:- pred safe(list(int)). -:- mode safe(in) is semidet. - -:- pred nodiag(int, int, list(int)). -:- mode nodiag(in, in, in) is semidet. +:- pred data(list(int)::out) is det. data([1, 2, 3, 4, 5]). @@ -55,54 +42,57 @@ qperm([X | Y], K) :- K = [U | V], qperm(Z, V). +:- pred qdelete(T::out, list(T)::in, list(T)::out) is nondet. + qdelete(A, [A | L], L). qdelete(X, [A | Z], [A | R]) :- qdelete(X, Z, R). +:- pred nodiag(int::in, int::in, list(int)::in) is semidet. + +nodiag(_, _, []). +nodiag(B, D, [N | L]) :- + NmB is N - B, + BmN is B - N, + ( if D = NmB then + fail + else if D = BmN then + fail + else + true + ), + D1 is D + 1, + nodiag(B, D1, L). + +:- pred safe(list(int)::in) is semidet. + safe([]). safe([N | L]) :- nodiag(N, 1, L), safe(L). -nodiag(_, _, []). -nodiag(B, D, [N | L]) :- - NmB is N - B, - BmN is B - N, - ( D = NmB -> - fail - ; D = BmN -> - fail - ; - true - ), - D1 is D + 1, - nodiag(B, D1, L). +:- pred print_list(list(int)::in, io::di, io::uo) is det. -:- pred print_list(list(int), io__state, io__state). -:- mode print_list(in, di, uo) is det. - -print_list(Xs) --> +print_list(Xs, !IO) :- ( - { Xs = [] } - -> - io__write_string("[]\n") + Xs = [], + io.write_string("[]\n", !IO) ; - io__write_string("["), - print_list_2(Xs), - io__write_string("]\n") + Xs = [_ | _], + io.write_string("[", !IO), + print_list_2(Xs, !IO), + io.write_string("]\n", !IO) ). -:- pred print_list_2(list(int), io__state, io__state). -:- mode print_list_2(in, di, uo) is det. +:- pred print_list_2(list(int)::in, io::di, io::uo) is det. -print_list_2([]) --> []. -print_list_2([X | Xs]) --> - io__write_int(X), +print_list_2([], !IO). +print_list_2([X | Xs], !IO) :- + io.write_int(X, !IO), ( - { Xs = [] } - -> - [] + Xs = [] ; - io__write_string(", "), - print_list_2(Xs) + Xs = [_ | _], + io.write_string(", ", !IO), + print_list_2(Xs, !IO) ). diff --git a/tests/debugger/interpreter.exp2 b/tests/debugger/interpreter.exp2 index db9eeeb27..b0934fde2 100644 --- a/tests/debugger/interpreter.exp2 +++ b/tests/debugger/interpreter.exp2 @@ -1,4 +1,4 @@ - E1: C1 CALL pred interpreter.main/2-0 (det) interpreter.m:43 + E1: C1 CALL pred interpreter.main/2-0 (det) interpreter.m:48 mdb> echo on Command echo enabled. mdb> context none @@ -28,16 +28,16 @@ mdb> delete 0 mdb> finish E4: C3 EXIT pred interpreter.database_assert_clause/4-0 (det) mdb> print * - Database (arg 1) [] - VarSet (arg 2) varset(var_supply(0), empty, empty) - Term (arg 3) functor(atom(":-"), [functor(atom/1, [|]/2, context/2)], context("interpreter.m", 24)) + VarSet (arg 1) varset(var_supply(0), empty, empty) + Term (arg 2) functor(atom(":-"), [functor(atom/1, [|]/2, context/2)], context("interpreter.m", 29)) + Database (arg 3) [] HeadVar__4 [clause(varset(var_supply/1, empty, empty), functor(atom/1, [|]/2, context/2), functor(atom/1, [], context/2))] mdb> finish -a This command is a no-op from this port. mdb> print * - Database (arg 1) [] - VarSet (arg 2) varset(var_supply(0), empty, empty) - Term (arg 3) functor(atom(":-"), [functor(atom/1, [|]/2, context/2)], context("interpreter.m", 24)) + VarSet (arg 1) varset(var_supply(0), empty, empty) + Term (arg 2) functor(atom(":-"), [functor(atom/1, [|]/2, context/2)], context("interpreter.m", 29)) + Database (arg 3) [] HeadVar__4 [clause(varset(var_supply/1, empty, empty), functor(atom/1, [|]/2, context/2), functor(atom/1, [], context/2))] mdb> E5: C4 CALL pred interpreter.consult_until_eof/4-0 (det) diff --git a/tests/debugger/interpreter.m b/tests/debugger/interpreter.m index 4e7103207..2c630b547 100644 --- a/tests/debugger/interpreter.m +++ b/tests/debugger/interpreter.m @@ -17,7 +17,12 @@ % For a more efficient version (using backtrackable destructive update), % see extras/trailed_update/samples/interpreter.m. % -% This source file is hereby placed in the public domain. -fjh (the author). +% This source file is hereby placed in the public domain. -fjh (the author). +% +%---------------------------------------------------------------------------% +% +% The .exp file is for XXX. +% The .exp2 file is for asm_fast.gc bootchecks. % %---------------------------------------------------------------------------% @@ -25,7 +30,7 @@ :- interface. :- import_module io. -:- pred main(io__state, io__state). +:- pred main(io, io). :- mode main(di, uo) is det. %---------------------------------------------------------------------------% @@ -40,153 +45,145 @@ :- import_module term_io. :- import_module varset. -main --> - io__write_string("Pure Prolog Interpreter.\n\n"), - io__command_line_arguments(Args), - ( { Args = [] } -> - io__stderr_stream(StdErr), - io__write_string(StdErr, "Usage: interpreter filename ...\n"), - io__set_exit_status(1) +main(!IO) :- + io.write_string("Pure Prolog Interpreter.\n\n", !IO), + io.command_line_arguments(Args, !IO), + ( + Args = [], + io.stderr_stream(StdErr, !IO), + io.write_string(StdErr, "Usage: interpreter filename ...\n", !IO), + io.set_exit_status(1, !IO) ; - { database_init(Database0) }, - consult_list(Args, Database0, Database), - main_loop(Database) + Args = [_ | _], + database_init(Database0), + consult_list(Args, Database0, Database, !IO), + main_loop(Database, !IO) ). -:- pred main_loop(database, io__state, io__state). -:- mode main_loop(in, di, uo) is det. +:- pred main_loop(database::in, io::di, io::uo) is det. -main_loop(Database) --> - io__write_string("?- "), - term_io__read_term(ReadTerm), - main_loop_2(ReadTerm, Database). +main_loop(Database, !IO) :- + io.write_string("?- ", !IO), + term_io.read_term(ReadTerm, !IO), + main_loop_2(ReadTerm, Database, !IO). -:- pred main_loop_2(read_term, database, io__state, io__state). -:- mode main_loop_2(in, in, di, uo) is det. +:- pred main_loop_2(read_term::in, database::in, io::di, io::uo) is det. -main_loop_2(eof, _Database) --> []. -main_loop_2(error(ErrorMessage, LineNumber), Database) --> - io__write_string("Error reading term at line "), - io__write_int(LineNumber), - io__write_string(" of standard input: "), - io__write_string(ErrorMessage), - io__write_string("\n"), - main_loop(Database). -main_loop_2(term(VarSet0, Goal), Database) --> +main_loop_2(eof, _Database, !IO). +main_loop_2(error(ErrorMessage, LineNumber), Database, !IO) :- + io.write_string("Error reading term at line ", !IO), + io.write_int(LineNumber, !IO), + io.write_string(" of standard input: ", !IO), + io.write_string(ErrorMessage, !IO), + io.write_string("\n", !IO), + main_loop(Database, !IO). +main_loop_2(term(VarSet0, Goal), Database, !IO) :- %%% It would be a good idea to add some special commands %%% with side-effects (such as `consult' and `listing'); %%% these could be identified and processed here. - { solutions(solve(Database, Goal, VarSet0), Solutions) }, - write_solutions(Solutions, Goal), - main_loop(Database). + solutions(solve(Database, Goal, VarSet0), Solutions), + write_solutions(Solutions, Goal, !IO), + main_loop(Database, !IO). -:- pred write_solutions(list(varset), term, io__state, io__state). -:- mode write_solutions(in, in, di, uo) is det. +:- pred write_solutions(list(varset)::in, term::in, io::di, io::uo) is det. -write_solutions(Solutions, Goal) --> - ( { Solutions = [] } -> - io__write_string("No.\n") +write_solutions(Solutions, Goal, !IO) :- + ( + Solutions = [], + io.write_string("No.\n", !IO) ; - write_solutions_2(Solutions, Goal), - io__write_string("Yes.\n") + Solutions = [_ | _], + write_solutions_2(Solutions, Goal, !IO), + io.write_string("Yes.\n", !IO) ). -:- pred write_solutions_2(list(varset), term, io__state, io__state). -:- mode write_solutions_2(in, in, di, uo) is det. +:- pred write_solutions_2(list(varset)::in, term::in, io::di, io::uo) is det. -write_solutions_2([], _) --> []. -write_solutions_2([VarSet | VarSets], Goal) --> - term_io__write_term_nl(VarSet, Goal), - write_solutions_2(VarSets, Goal). +write_solutions_2([], _, !IO). +write_solutions_2([VarSet | VarSets], Goal, !IO) :- + term_io.write_term_nl(VarSet, Goal, !IO), + write_solutions_2(VarSets, Goal, !IO). %---------------------------------------------------------------------------% -:- pred consult_list(list(string), database, database, io__state, io__state). -:- mode consult_list(in, in, out, di, uo) is det. +:- pred consult_list(list(string)::in, database::in, database::out, + io::di, io::uo) is det. -consult_list([], Database, Database) --> []. -consult_list([File | Files], Database0, Database) --> - consult(File, Database0, Database1), - consult_list(Files, Database1, Database). +consult_list([], !Database, !IO). +consult_list([File | Files], !Database, !IO) :- + consult(File, !Database, !IO), + consult_list(Files, !Database, !IO). -:- pred consult(string, database, database, io__state, io__state). -:- mode consult(in, in, out, di, uo) is det. +:- pred consult(string::in, database::in, database::out, + io::di, io::uo) is det. -consult(File, Database0, Database) --> - io__write_string("Consulting file `"), - io__write_string(File), - io__write_string("'...\n"), - io__see(File, Result), - ( { Result = ok } -> - consult_until_eof(Database0, Database), - io__seen - ; - io__write_string("Error opening file `"), - io__write_string(File), - io__write_string("' for input.\n"), - { Database = Database0 } +consult(File, Database0, Database, !IO) :- + io.write_string("Consulting file `", !IO), + io.write_string(File, !IO), + io.write_string("'...\n", !IO), + io.see(File, Result, !IO), + ( if Result = ok then + consult_until_eof(Database0, Database, !IO), + io.seen(!IO) + else + io.write_string("Error opening file `", !IO), + io.write_string(File, !IO), + io.write_string("' for input.\n", !IO), + Database = Database0 ). -:- pred consult_until_eof(database, database, io__state, io__state). -:- mode consult_until_eof(in, out, di, uo) is det. +:- pred consult_until_eof(database::in, database::out, io::di, io::uo) is det. -consult_until_eof(Database0, Database) --> - term_io__read_term(ReadTerm), - consult_until_eof_2(ReadTerm, Database0, Database). +consult_until_eof(!Database, !IO) :- + term_io.read_term(ReadTerm, !IO), + consult_until_eof_2(ReadTerm, !Database, !IO). -:- pred consult_until_eof_2(read_term, database, database, - io__state, io__state). -:- mode consult_until_eof_2(in, in, out, di, uo) is det. +:- pred consult_until_eof_2(read_term::in, database::in, database::out, + io::di, io::uo) is det. -consult_until_eof_2(eof, Database, Database) --> []. +consult_until_eof_2(eof, !Database, !IO). +consult_until_eof_2(error(ErrorMessage, LineNumber), !Database, !IO) :- + io.write_string("Error reading term at line ", !IO), + io.write_int(LineNumber, !IO), + io.write_string(" of standard input: ", !IO), + io.write_string(ErrorMessage, !IO), + io.write_string("\n", !IO), + consult_until_eof(!Database, !IO). -consult_until_eof_2(error(ErrorMessage, LineNumber), Database0, Database) --> - io__write_string("Error reading term at line "), - io__write_int(LineNumber), - io__write_string(" of standard input: "), - io__write_string(ErrorMessage), - io__write_string("\n"), - consult_until_eof(Database0, Database). - -consult_until_eof_2(term(VarSet, Term), Database0, Database) --> - { database_assert_clause(Database0, VarSet, Term, Database1) }, - consult_until_eof(Database1, Database). +consult_until_eof_2(term(VarSet, Term), !Database, !IO) :- + database_assert_clause(VarSet, Term, !Database), + consult_until_eof(!Database, !IO). %---------------------------------------------------------------------------% % Solve takes a database of rules and facts, a goal to be solved, % and a varset (which includes a supply of fresh vars, a substitution, -% and names for [some subset of] the variables). It updates -% the varset, producing a new substitution and perhaps introducing -% some new vars, and returns the result. +% and names for [some subset of] the variables). It updates the varset, +% producing a new substitution and perhaps introducing some new vars, +% and returns the result. % Goals are stored just as terms. -% (It might be more efficient to parse them -% before storing them in the database. Currently we do -% this parsing work every time we interpret a clause.) +% (It might be more efficient to parse them before storing them +% in the database. Currently we do this parsing work every time +% we interpret a clause.) -:- pred solve(database, term, varset, varset). -:- mode solve(in, in, in, out) is nondet. +:- pred solve(database::in, term::in, varset::in, varset::out) is nondet. -solve(_Database, term__functor(term__atom("true"), [], _)) --> []. - -solve(Database, term__functor(term__atom(", "), [A, B], _)) --> - solve(Database, A), - solve(Database, B). - -solve(Database, term__functor(term__atom(";"), [A, B], _)) --> - solve(Database, A) - ; - solve(Database, B). - -solve(_Database, term__functor(term__atom("="), [A, B], _)) --> - unify(A, B). - -solve(Database, Goal) --> - { database_lookup_clause(Database, Goal, ClauseVarSet, Head0, Body0) }, - rename_apart(ClauseVarSet, [Head0, Body0], [Head, Body]), - unify(Goal, Head), - solve(Database, Body). +solve(_Database, term.functor(term.atom("true"), [], _), !VarSet). +solve(Database, term.functor(term.atom(", "), [A, B], _), !VarSet) :- + solve(Database, A, !VarSet), + solve(Database, B, !VarSet). +solve(Database, term.functor(term.atom(";"), [A, B], _), !VarSet) :- + ( solve(Database, A, !VarSet) + ; solve(Database, B, !VarSet) + ). +solve(_Database, term.functor(term.atom("="), [A, B], _), !VarSet) :- + unify(A, B, !VarSet). +solve(Database, Goal, !VarSet) :- + database_lookup_clause(Database, Goal, ClauseVarSet, Head0, Body0), + rename_apart(ClauseVarSet, [Head0, Body0], [Head, Body], !VarSet), + unify(Goal, Head, !VarSet), + solve(Database, Body, !VarSet). %---------------------------------------------------------------------------% @@ -194,7 +191,7 @@ solve(Database, Goal) --> :- mode rename_apart(in, in, out, in, out) is det. rename_apart(NewVarSet, Terms0, Terms, VarSet0, VarSet) :- - varset__merge(VarSet0, NewVarSet, Terms0, VarSet, Terms). + varset.merge(VarSet0, NewVarSet, Terms0, VarSet, Terms). %---------------------------------------------------------------------------% @@ -203,114 +200,94 @@ rename_apart(NewVarSet, Terms0, Terms, VarSet0, VarSet) :- % using the substitutions that are contained in the `varset', % so we can't use those versions. -:- pred unify(term, term, varset, varset). -:- mode unify(in, in, in, out) is semidet. +:- pred unify(term::in, term::in, varset::in, varset::out) is semidet. -unify(term__variable(X, _), term__variable(Y, _), VarSet0, VarSet) :- - ( - varset__search_var(VarSet0, X, BindingOfX) - -> - ( - varset__search_var(VarSet0, Y, BindingOfY) - -> - % both X and Y already have bindings - just - % unify the terms they are bound to +unify(term.variable(X, _), term.variable(Y, _), VarSet0, VarSet) :- + ( if varset.search_var(VarSet0, X, BindingOfX) then + ( if varset.search_var(VarSet0, Y, BindingOfY) then + % Both X and Y already have bindings - + % just unify the terms they are bound to. unify(BindingOfX, BindingOfY, VarSet0, VarSet) - ; - % Y is a variable which hasn't been bound yet - apply_rec_substitution(BindingOfX, VarSet0, - SubstBindingOfX), - ( SubstBindingOfX = term__variable(Y, _) -> + else + % Y is a variable which hasn't been bound yet. + apply_rec_substitution(BindingOfX, VarSet0, SubstBindingOfX), + ( if SubstBindingOfX = term.variable(Y, _) then VarSet = VarSet0 - ; - \+ occurs(SubstBindingOfX, Y, VarSet0), - varset__bind_var(Y, SubstBindingOfX, + else + not occurs(SubstBindingOfX, Y, VarSet0), + varset.bind_var(Y, SubstBindingOfX, VarSet0, VarSet) + ) + ) + else + ( if varset.search_var(VarSet0, Y, BindingOfY2) then + % X is a variable which hasn't been bound yet. + apply_rec_substitution(BindingOfY2, VarSet0, SubstBindingOfY2), + ( if SubstBindingOfY2 = term.variable(X, _) then + VarSet = VarSet0 + else + not occurs(SubstBindingOfY2, X, VarSet0), + varset.bind_var(X, SubstBindingOfY2, VarSet0, VarSet) + ) + else + % Both X and Y are unbound variables - bind one to the other. + ( if X = Y then + VarSet = VarSet0 + else + varset.bind_var(X, term.variable(Y, context_init), VarSet0, VarSet) ) ) - ; - ( - varset__search_var(VarSet0, Y, BindingOfY2) - -> - % X is a variable which hasn't been bound yet - apply_rec_substitution(BindingOfY2, VarSet0, - SubstBindingOfY2), - ( SubstBindingOfY2 = term__variable(X, _) -> - VarSet = VarSet0 - ; - \+ occurs(SubstBindingOfY2, X, VarSet0), - varset__bind_var(X, SubstBindingOfY2, - VarSet0, VarSet) - ) - ; - % both X and Y are unbound variables - - % bind one to the other - ( X = Y -> - VarSet = VarSet0 - ; - varset__bind_var(X, - term.variable(Y, context_init), VarSet0, VarSet) - ) - ) ). - -unify(term__variable(X, _), term__functor(F, As, C), VarSet0, VarSet) :- - ( - varset__search_var(VarSet0, X, BindingOfX) - -> - unify(BindingOfX, term__functor(F, As, C), VarSet0, +unify(term.variable(X, _), term.functor(F, As, C), VarSet0, VarSet) :- + ( if varset.search_var(VarSet0, X, BindingOfX) then + unify(BindingOfX, term.functor(F, As, C), VarSet0, VarSet) - ; - \+ occurs_list(As, X, VarSet0), - varset__bind_var(X, term__functor(F, As, C), VarSet0, VarSet) + else + not occurs_list(As, X, VarSet0), + varset.bind_var(X, term.functor(F, As, C), VarSet0, VarSet) ). - -unify(term__functor(F, As, C), term__variable(X, _), VarSet0, VarSet) :- - ( - varset__search_var(VarSet0, X, BindingOfX) - -> - unify(term__functor(F, As, C), BindingOfX, VarSet0, - VarSet) - ; - \+ occurs_list(As, X, VarSet0), - varset__bind_var(X, term__functor(F, As, C), VarSet0, VarSet) +unify(term.functor(F, As, C), term.variable(X, _), VarSet0, VarSet) :- + ( if varset.search_var(VarSet0, X, BindingOfX) then + unify(term.functor(F, As, C), BindingOfX, VarSet0, VarSet) + else + not occurs_list(As, X, VarSet0), + varset.bind_var(X, term.functor(F, As, C), VarSet0, VarSet) ). +unify(term.functor(F, AsX, _), term.functor(F, AsY, _), !VarSet) :- + unify_list(AsX, AsY, !VarSet). -unify(term__functor(F, AsX, _), term__functor(F, AsY, _)) --> - unify_list(AsX, AsY). +:- pred unify_list(list(term)::in, list(term)::in, varset::in, varset::out) + is semidet. -:- pred unify_list(list(term), list(term), varset, varset). -:- mode unify_list(in, in, in, out) is semidet. - -unify_list([], []) --> []. -unify_list([X | Xs], [Y | Ys]) --> - unify(X, Y), - unify_list(Xs, Ys). +unify_list([], [], !VarSet). +unify_list([X | Xs], [Y | Ys], !VarSet) :- + unify(X, Y, !VarSet), + unify_list(Xs, Ys, !VarSet). %---------------------------------------------------------------------------% % occurs(Term, Var, Subst) succeeds if Term contains Var, - % perhaps indirectly via the substitution. (The variable must + % perhaps indirectly via the substitution. (The variable must % not be mapped by the substitution.) -:- pred occurs(term, var, varset). -:- mode occurs(in, in, in) is semidet. +:- pred occurs(term::in, var::in, varset::in) is semidet. -occurs(term__variable(X, _), Y, VarSet) :- - X = Y +occurs(term.variable(X, _), Y, VarSet) :- + ( + X = Y ; - varset__search_var(VarSet, X, BindingOfX), - occurs(BindingOfX, Y, VarSet). -occurs(term__functor(_F, As, _), Y, VarSet) :- + varset.search_var(VarSet, X, BindingOfX), + occurs(BindingOfX, Y, VarSet) + ). +occurs(term.functor(_F, As, _), Y, VarSet) :- occurs_list(As, Y, VarSet). -:- pred occurs_list(list(term), var, varset). -:- mode occurs_list(in, in, in) is semidet. +:- pred occurs_list(list(term)::in, var::in, varset::in) is semidet. occurs_list([Term | Terms], Y, VarSet) :- - occurs(Term, Y, VarSet) - ; - occurs_list(Terms, Y, VarSet). + ( occurs(Term, Y, VarSet) + ; occurs_list(Terms, Y, VarSet) + ). %---------------------------------------------------------------------------% @@ -319,28 +296,24 @@ occurs_list([Term | Terms], Y, VarSet) :- % Recursively apply substitution to Term0 until no more substitions % can be applied, and then return the result in Term. % -:- pred apply_rec_substitution(term, varset, term). -:- mode apply_rec_substitution(in, in, out) is det. +:- pred apply_rec_substitution(term::in, varset::in, term::out) is det. -apply_rec_substitution(term__variable(Var, _), VarSet, Term) :- - ( - varset__search_var(VarSet, Var, Replacement) - -> +apply_rec_substitution(term.variable(Var, _), VarSet, Term) :- + ( if varset.search_var(VarSet, Var, Replacement) then % Recursively apply the substitution to the replacement. apply_rec_substitution(Replacement, VarSet, Term) - ; - Term = term__variable(Var, context_init) + else + Term = term.variable(Var, context_init) ). -apply_rec_substitution(term__functor(Name, Args0, Context), VarSet, - term__functor(Name, Args, Context)) :- +apply_rec_substitution(term.functor(Name, Args0, Context), VarSet, + term.functor(Name, Args, Context)) :- apply_rec_substitution_to_list(Args0, VarSet, Args). -:- pred apply_rec_substitution_to_list(list(term), varset, list(term)). -:- mode apply_rec_substitution_to_list(in, in, out) is det. +:- pred apply_rec_substitution_to_list(list(term)::in, varset::in, + list(term)::out) is det. apply_rec_substitution_to_list([], _VarSet, []). -apply_rec_substitution_to_list([Term0 | Terms0], VarSet, - [Term | Terms]) :- +apply_rec_substitution_to_list([Term0 | Terms0], VarSet, [Term | Terms]) :- apply_rec_substitution(Term0, VarSet, Term), apply_rec_substitution_to_list(Terms0, VarSet, Terms). @@ -351,32 +324,32 @@ apply_rec_substitution_to_list([Term0 | Terms0], VarSet, % and subindex on the name/arity of the first argument.) :- type database == list(clause). -:- type clause ---> clause(varset, term, term). +:- type clause + ---> clause(varset, term, term). -:- pred database_init(database). -:- mode database_init(out) is det. +:- pred database_init(database::out) is det. database_init([]). -:- pred database_assert_clause(database, varset, term, database). -:- mode database_assert_clause(in, in, in, out) is det. +:- pred database_assert_clause(varset::in, term::in, + database::in, database::out) is det. -database_assert_clause(Database, VarSet, Term, [Clause | Database]) :- - ( Term = term__functor(term__atom(":-"), [H, B], _) -> +database_assert_clause(VarSet, Term, Database, [Clause | Database]) :- + ( if Term = term.functor(term.atom(":-"), [H, B], _) then Head = H, Body = B - ; + else Head = Term, - term__context_init(Context), - Body = term__functor(term__atom("true"), [], Context) + term.context_init(Context), + Body = term.functor(term.atom("true"), [], Context) ), Clause = clause(VarSet, Head, Body). -:- pred database_lookup_clause(database, term, varset, term, term). -:- mode database_lookup_clause(in, in, out, out, out) is nondet. +:- pred database_lookup_clause(database::in, term::in, + varset::out, term::out, term::out) is nondet. database_lookup_clause(Database, _Goal, VarSet, Head, Body) :- - list__member(Clause, Database), + list.member(Clause, Database), Clause = clause(VarSet, Head, Body). %---------------------------------------------------------------------------% diff --git a/tests/debugger/io_tab_goto.m b/tests/debugger/io_tab_goto.m index 2a9493a40..03aeeaf8c 100644 --- a/tests/debugger/io_tab_goto.m +++ b/tests/debugger/io_tab_goto.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module io_tab_goto. :- interface. @@ -19,10 +19,10 @@ main(!IO) :- goto(!IO), io_tab_goto.open_input("io_tab_goto.data", Res, Stream, !IO), - ( Res = 0 -> + ( if Res = 0 then io_tab_goto.part_1(Stream, !IO), io_tab_goto.part_2(Stream, !IO) - ; + else io.write_string("could not open io_tab_goto.data\n", !IO) ). @@ -30,8 +30,10 @@ main(!IO) :- :- pragma no_inline(goto/2). -:- pragma foreign_proc(c, goto(IO0::di, IO::uo), - [tabled_for_io, promise_pure], " +:- pragma foreign_proc(c, + goto(IO0::di, IO::uo), + [tabled_for_io, promise_pure], +" printf(""should see this printf\\n""); goto label; printf(""should never see this printf\\n""); @@ -39,62 +41,57 @@ label: IO = IO0; "). -:- pred io_tab_goto.part_1(c_pointer::in, io.state::di, io.state::uo) is det. +:- pred io_tab_goto.part_1(c_pointer::in, io::di, io::uo) is det. -io_tab_goto.part_1(Stream) --> - io_tab_goto.test(Stream, 0, A), - io_tab_goto.write_int(A), - io_tab_goto.poly_test(Stream, ['a', 'b', 'c'], 0, B), - io_tab_goto.write_int(B). +io_tab_goto.part_1(Stream, !IO) :- + io_tab_goto.test(Stream, 0, A, !IO), + io_tab_goto.write_int(A, !IO), + io_tab_goto.poly_test(Stream, ['a', 'b', 'c'], 0, B, !IO), + io_tab_goto.write_int(B, !IO). -:- pred io_tab_goto.part_2(c_pointer::in, io.state::di, io.state::uo) - is det. +:- pred io_tab_goto.part_2(c_pointer::in, io::di, io::uo) is det. -io_tab_goto.part_2(Stream) --> - io_tab_goto.test(Stream, 0, A), - io_tab_goto.write_int(A). +io_tab_goto.part_2(Stream, !IO) :- + io_tab_goto.test(Stream, 0, A, !IO), + io_tab_goto.write_int(A, !IO). -:- pred io_tab_goto.test(c_pointer::in, int::in, int::out, - io.state::di, io.state::uo) is det. +:- pred test(c_pointer::in, int::in, int::out, io::di, io::uo) is det. -io_tab_goto.test(Stream, SoFar, N) --> - io_tab_goto.read_char_code(Stream, CharCode), - ( - { char.to_int(Char, CharCode) }, - { char.is_digit(Char) }, - { char.digit_to_int(Char, CharInt) } - -> - io_tab_goto.test(Stream, SoFar * 10 + CharInt, N) - ; - { N = SoFar } +test(Stream, SoFar, N, !IO) :- + io_tab_goto.read_char_code(Stream, CharCode, !IO), + ( if + char.to_int(Char, CharCode), + char.is_digit(Char), + char.digit_to_int(Char, CharInt) + then + io_tab_goto.test(Stream, SoFar * 10 + CharInt, N, !IO) + else + N = SoFar ). -:- pred io_tab_goto.poly_test(c_pointer::in, T::in, int::in, int::out, - io.state::di, io.state::uo) is det. +:- pred poly_test(c_pointer::in, T::in, int::in, int::out, + io::di, io::uo) is det. -io_tab_goto.poly_test(Stream, Unused, SoFar, N) --> - io_tab_goto.poly_read_char_code(Stream, Unused, CharCode), - ( - { char.to_int(Char, CharCode) }, - { char.is_digit(Char) }, - { char.digit_to_int(Char, CharInt) } - -> - io_tab_goto.poly_test(Stream, Unused, - SoFar * 10 + CharInt, N) - ; - { N = SoFar } +poly_test(Stream, Unused, SoFar, N, !IO) :- + io_tab_goto.poly_read_char_code(Stream, Unused, CharCode, !IO), + ( if + char.to_int(Char, CharCode), + char.is_digit(Char), + char.digit_to_int(Char, CharInt) + then + io_tab_goto.poly_test(Stream, Unused, SoFar * 10 + CharInt, N, !IO) + else + N = SoFar ). :- pragma foreign_decl("C", "#include "). :- pred io_tab_goto.open_input(string::in, int::out, c_pointer::out, - io.state::di, io.state::uo) is det. - + io::di, io::uo) is det. :- pragma no_inline(io_tab_goto.open_input/5). :- pragma foreign_proc("C", - io_tab_goto.open_input(FileName::in, Res::out, Stream::out, - IO0::di, IO::uo), + open_input(FileName::in, Res::out, Stream::out, IO0::di, IO::uo), [will_not_call_mercury, promise_pure, tabled_for_io], " Stream = (MR_Word) fopen((const char *) FileName, ""r""); @@ -104,14 +101,12 @@ end1: IO = IO0; "). -:- pred io_tab_goto.read_char_code(c_pointer::in, int::out, - io.state::di, io.state::uo) is det. - +:- pred read_char_code(c_pointer::in, int::out, + io::di, io::uo) is det. :- pragma no_inline(io_tab_goto.read_char_code/4). :- pragma foreign_proc("C", - io_tab_goto.read_char_code(Stream::in, CharCode::out, - IO0::di, IO::uo), + read_char_code(Stream::in, CharCode::out, IO0::di, IO::uo), [will_not_call_mercury, promise_pure, tabled_for_io], " CharCode = getc((FILE *) Stream); @@ -120,14 +115,13 @@ end2: IO = IO0; "). -:- pred io_tab_goto.poly_read_char_code(c_pointer::in, T::in, int::out, - io.state::di, io.state::uo) is det. - +:- pred poly_read_char_code(c_pointer::in, T::in, int::out, + io::di, io::uo) is det. :- pragma no_inline(io_tab_goto.poly_read_char_code/5). :- pragma foreign_proc("C", - io_tab_goto.poly_read_char_code(Stream::in, Unused::in, - CharCode::out, IO0::di, IO::uo), + poly_read_char_code(Stream::in, Unused::in, CharCode::out, + IO0::di, IO::uo), [will_not_call_mercury, promise_pure, tabled_for_io], " /* ignore Unused */ @@ -137,13 +131,11 @@ end3: IO = IO0; "). -:- pred io_tab_goto.write_int(int::in, io.state::di, io.state::uo) - is det. - +:- pred write_int(int::in, io::di, io::uo) is det. :- pragma no_inline(io_tab_goto.write_int/3). :- pragma foreign_proc("C", - io_tab_goto.write_int(N::in, IO0::di, IO::uo), + write_int(N::in, IO0::di, IO::uo), [will_not_call_mercury, promise_pure], "{ printf(""%d\\n"", (int) N); diff --git a/tests/debugger/label_layout.m b/tests/debugger/label_layout.m index 5087d332d..97e706ddf 100644 --- a/tests/debugger/label_layout.m +++ b/tests/debugger/label_layout.m @@ -5,22 +5,22 @@ :- module label_layout. :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. -main --> - ( - { +main(!IO) :- + ( if + ( a(1, X) ; a(2, X) - }, - { X = 0 } - -> - io__write_string("yes\n") - ; - io__write_string("no\n") + ), + X = 0 + then + io.write_string("yes\n", !IO) + else + io.write_string("no\n", !IO) ). :- pred a(int::in, int::out) is det. diff --git a/tests/debugger/lambda_expr.m b/tests/debugger/lambda_expr.m index af14c2f59..0117b4a70 100644 --- a/tests/debugger/lambda_expr.m +++ b/tests/debugger/lambda_expr.m @@ -21,5 +21,5 @@ main(!IO) :- P = (pred(X::in, Y::out) is det :- Y = X + 1), P(1, Z), - io__write_int(Z, !IO), - io__nl(!IO). + io.write_int(Z, !IO), + io.nl(!IO). diff --git a/tests/debugger/loopcheck.m b/tests/debugger/loopcheck.m index 97772c128..f83037063 100644 --- a/tests/debugger/loopcheck.m +++ b/tests/debugger/loopcheck.m @@ -10,13 +10,13 @@ :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. -main --> - { loop(10) }, - io__write_string("Hello, world\n"). +main(!IO) :- + loop(10) , + io.write_string("Hello, world\n", !IO). :- pragma loop_check(loop/1). :- pred loop(int::in) is det. diff --git a/tests/debugger/lval_desc_array.m b/tests/debugger/lval_desc_array.m index 9e9915935..13ca92e98 100644 --- a/tests/debugger/lval_desc_array.m +++ b/tests/debugger/lval_desc_array.m @@ -12,17 +12,17 @@ :- 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. -main --> - { A0 = 0 }, - { perform_increments(A0, A) }, - io__write_int(A), - io__write_string("\n"). +main(!IO) :- + A0 = 0, + perform_increments(A0, A), + io.write_int(A, !IO), + io.write_string("\n", !IO). :- pred perform_increments(int::in, int::out) is det. diff --git a/tests/debugger/mdb_command_test.m b/tests/debugger/mdb_command_test.m index b9f25f095..3b4fd6b4d 100644 --- a/tests/debugger/mdb_command_test.m +++ b/tests/debugger/mdb_command_test.m @@ -1,14 +1,14 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module mdb_command_test. :- interface. :- import_module io. -:- pred main(io__state, io__state). +:- pred main(io, io). :- mode main(di, uo) is cc_multi. :- implementation. diff --git a/tests/debugger/multi_parameter.exp b/tests/debugger/multi_parameter.exp index 9cdbe5ceb..8e7d8a2ad 100644 --- a/tests/debugger/multi_parameter.exp +++ b/tests/debugger/multi_parameter.exp @@ -10,7 +10,7 @@ mdb> print * X (arg 1) 'z' mdb> 3: 3 3 CALL pred multi_parameter.a/2-0 (det) - multi_parameter.m:18 (from multi_parameter.m:35) + multi_parameter.m:18 (from multi_parameter.m:36) mdb> print * HeadVar__1 'z' mdb> @@ -26,7 +26,7 @@ mdb> print * HeadVar__2 122 mdb> 6: 3 3 EXIT pred multi_parameter.a/2-0 (det) - multi_parameter.m:18 (from multi_parameter.m:35) + multi_parameter.m:18 (from multi_parameter.m:36) mdb> print * HeadVar__1 'z' HeadVar__2 122 diff --git a/tests/debugger/multi_parameter.m b/tests/debugger/multi_parameter.m index 0c5b059d0..489601a83 100644 --- a/tests/debugger/multi_parameter.m +++ b/tests/debugger/multi_parameter.m @@ -8,7 +8,7 @@ :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. @@ -20,16 +20,17 @@ ]. :- instance m(char, int) where [ - pred(a/2) is char__to_int + pred(a/2) is char.to_int ]. -main --> - { foo('z', X) }, - io__write_int(X), - io__nl. +main(!IO) :- + foo('z', X) , + io.write_int(X, !IO), + io.nl(!IO). :- pred foo(A, B) <= m(A, B). :- mode foo(in, out) is det. :- pragma no_inline(foo/2). -foo(X, Y) :- a(X, Y). +foo(X, Y) :- + a(X, Y). diff --git a/tests/debugger/mutrec.m b/tests/debugger/mutrec.m index 0661d0c70..a3474385d 100644 --- a/tests/debugger/mutrec.m +++ b/tests/debugger/mutrec.m @@ -76,9 +76,9 @@ p1([Step | Steps], A, R) :- p1(Steps, B, R) ; Step = mut(N), - ( N = 2 -> + ( if N = 2 then p2(Steps, B, R) - ; + else p3(Steps, B, R) ) ; @@ -96,9 +96,9 @@ p2([Step | Steps], A, R) :- p2(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then p1(Steps, B, R) - ; + else p3(Steps, B, R) ) ; @@ -116,9 +116,9 @@ p3([Step | Steps], A, R) :- p3(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then p1(Steps, B, R) - ; + else p2(Steps, B, R) ) ; @@ -138,9 +138,9 @@ q1([Step | Steps], A, R) :- q1(Steps, B, R) ; Step = mut(N), - ( N = 2 -> + ( if N = 2 then q2(Steps, B, R) - ; + else q3(Steps, B, R) ) ; @@ -158,9 +158,9 @@ q2([Step | Steps], A, R) :- q2(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then q1(Steps, B, R) - ; + else q3(Steps, B, R) ) ; @@ -178,9 +178,9 @@ q3([Step | Steps], A, R) :- q3(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then q1(Steps, B, R) - ; + else q2(Steps, B, R) ) ; @@ -218,9 +218,9 @@ r1([Step | Steps], A, R) :- r1(Steps, B, R) ; Step = mut(N), - ( N = 2 -> + ( if N = 2 then r2(Steps, B, R) - ; + else r3(Steps, B, R) ) ; @@ -238,9 +238,9 @@ r2([Step | Steps], A, R) :- r2(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then r1(Steps, B, R) - ; + else r3(Steps, B, R) ) ; @@ -258,9 +258,9 @@ r3([Step | Steps], A, R) :- r3(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then r1(Steps, B, R) - ; + else r2(Steps, B, R) ) ; @@ -274,9 +274,9 @@ r3([Step | Steps], A, R) :- s(N, A, R) :- B = ["s" | A], - ( N > 0 -> + ( if N > 0 then s(N-1, B, R) - ; + else R = B ). diff --git a/tests/debugger/mutrec_higher_order.m b/tests/debugger/mutrec_higher_order.m index eef8314bf..74d0f7bc0 100644 --- a/tests/debugger/mutrec_higher_order.m +++ b/tests/debugger/mutrec_higher_order.m @@ -72,9 +72,9 @@ write_comma_strings([Str | Strs], !IO) :- list(step)::in, int::in, list(string)::in, list(string)::out) is det. repeat_steps(P, Steps, N, A, R) :- - ( N =< 0 -> + ( if N =< 0 then R = A - ; + else P(Steps, A, B), repeat_steps(P, Steps, N-1, B, R) ). @@ -91,18 +91,18 @@ p1([Step | Steps], A, R) :- p1(Steps, B, R) ; Step = mut(N), - ( N = 2 -> + ( if N = 2 then p2(Steps, B, R) - ; + else p3(Steps, B, R) ) ; Step = rep(N), - ( N = 1 -> + ( if N = 1 then repeat_steps(q1, Steps, 1, A, R) - ; N = 2 -> + else if N = 2 then repeat_steps(q2, Steps, 2, A, R) - ; + else repeat_steps(q3, Steps, 3, A, R) ) ; @@ -120,18 +120,18 @@ p2([Step | Steps], A, R) :- p2(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then p1(Steps, B, R) - ; + else p3(Steps, B, R) ) ; Step = rep(N), - ( N = 1 -> + ( if N = 1 then repeat_steps(q1, Steps, 1, A, R) - ; N = 2 -> + else if N = 2 then repeat_steps(q2, Steps, 2, A, R) - ; + else repeat_steps(q3, Steps, 3, A, R) ) ; @@ -149,18 +149,18 @@ p3([Step | Steps], A, R) :- p3(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then p1(Steps, B, R) - ; + else p2(Steps, B, R) ) ; Step = rep(N), - ( N = 1 -> + ( if N = 1 then repeat_steps(q1, Steps, 1, A, R) - ; N = 2 -> + else if N = 2 then repeat_steps(q2, Steps, 2, A, R) - ; + else repeat_steps(q3, Steps, 3, A, R) ) ; @@ -180,18 +180,18 @@ q1([Step | Steps], A, R) :- q1(Steps, B, R) ; Step = mut(N), - ( N = 2 -> + ( if N = 2 then q2(Steps, B, R) - ; + else q3(Steps, B, R) ) ; Step = rep(N), - ( N = 1 -> + ( if N = 1 then repeat_steps(r1, Steps, 1, A, R) - ; N = 2 -> + else if N = 2 then repeat_steps(r2, Steps, 2, A, R) - ; + else repeat_steps(r3, Steps, 3, A, R) ) ; @@ -209,18 +209,18 @@ q2([Step | Steps], A, R) :- q2(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then q1(Steps, B, R) - ; + else q3(Steps, B, R) ) ; Step = rep(N), - ( N = 1 -> + ( if N = 1 then repeat_steps(r1, Steps, 1, A, R) - ; N = 2 -> + else if N = 2 then repeat_steps(r2, Steps, 2, A, R) - ; + else repeat_steps(r3, Steps, 3, A, R) ) ; @@ -238,18 +238,18 @@ q3([Step | Steps], A, R) :- q3(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then q1(Steps, B, R) - ; + else q2(Steps, B, R) ) ; Step = rep(N), - ( N = 1 -> + ( if N = 1 then repeat_steps(r1, Steps, 1, A, R) - ; N = 2 -> + else if N = 2 then repeat_steps(r2, Steps, 2, A, R) - ; + else repeat_steps(r3, Steps, 3, A, R) ) ; @@ -287,9 +287,9 @@ r1([Step | Steps], A, R) :- r1(Steps, B, R) ; Step = mut(N), - ( N = 2 -> + ( if N = 2 then r2(Steps, B, R) - ; + else r3(Steps, B, R) ) ; @@ -310,9 +310,9 @@ r2([Step | Steps], A, R) :- r2(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then r1(Steps, B, R) - ; + else r3(Steps, B, R) ) ; @@ -333,9 +333,9 @@ r3([Step | Steps], A, R) :- r3(Steps, B, R) ; Step = mut(N), - ( N = 1 -> + ( if N = 1 then r1(Steps, B, R) - ; + else r2(Steps, B, R) ) ; @@ -352,9 +352,9 @@ r3([Step | Steps], A, R) :- s(N, A, R) :- B = ["s" | A], - ( N > 0 -> + ( if N > 0 then s(N-1, B, R) - ; + else R = B ). diff --git a/tests/debugger/no_inline_builtins.m b/tests/debugger/no_inline_builtins.m index f504b646a..80cf55937 100644 --- a/tests/debugger/no_inline_builtins.m +++ b/tests/debugger/no_inline_builtins.m @@ -6,12 +6,12 @@ :- 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. -main --> - io__write_int(40 + 2), - io__nl. +main(!IO) :- + io.write_int(40 + 2, !IO), + io.nl(!IO). diff --git a/tests/debugger/nondet_stack.m b/tests/debugger/nondet_stack.m index b5f219b45..7fd84a7fd 100644 --- a/tests/debugger/nondet_stack.m +++ b/tests/debugger/nondet_stack.m @@ -10,28 +10,25 @@ :- import_module io. -:- pred main(io__state, io__state). -:- mode main(di, uo) is cc_multi. +:- pred main(io::di, io::uo) is cc_multi. :- implementation. :- import_module int. :- import_module list. -main --> - ( { data(Data), queen(Data, Out), test(Out, _) } -> - print_list(Out) - ; - io__write_string("No solution\n") +main(!IO) :- + ( if data(Data), queen(Data, Out), test(Out, _) then + print_list(Out, !IO) + else + io.write_string("No solution\n", !IO) ). -:- pred data(list(int)). -:- mode data(out) is det. +:- pred data(list(int)::out) is det. data([1, 2, 3, 4, 5]). -:- pred test(list(int), int). -:- mode test(in, out) is nondet. +:- pred test(list(int)::in, int::out) is nondet. test([H | T], X) :- ( @@ -43,15 +40,13 @@ test([H | T], X) :- ), T = [5 | _]. -:- pred queen(list(int), list(int)). -:- mode queen(in, out) is nondet. +:- pred queen(list(int)::in, list(int)::out) is nondet. queen(Data, Out) :- qperm(Data, Out), safe(Out). -:- pred qperm(list(T), list(T)). -:- mode qperm(in, out) is nondet. +:- pred qperm(list(T)::in, list(T)::out) is nondet. qperm([], []). qperm([X | Y], K) :- @@ -59,63 +54,58 @@ qperm([X | Y], K) :- K = [U | V], qperm(Z, V). -:- pred qdelete(T, list(T), list(T)). -:- mode qdelete(out, in, out) is nondet. +:- pred qdelete(T::out, list(T)::in, list(T)::out) is nondet. qdelete(A, [A | L], L). qdelete(X, [A | Z], [A | R]) :- qdelete(X, Z, R). -:- pred safe(list(int)). -:- mode safe(in) is semidet. +:- pred safe(list(int)::in) is semidet. safe([]). safe([N | L]) :- nodiag(N, 1, L), safe(L). -:- pred nodiag(int, int, list(int)). -:- mode nodiag(in, in, in) is semidet. +:- pred nodiag(int::in, int::in, list(int)::in) is semidet. nodiag(_, _, []). nodiag(B, D, [N | L]) :- NmB = N - B, BmN = B - N, - ( D = NmB -> + ( if D = NmB then fail - ; D = BmN -> + else if D = BmN then fail - ; + else true ), D1 = D + 1, nodiag(B, D1, L). -:- pred print_list(list(int), io__state, io__state). -:- mode print_list(in, di, uo) is det. +:- pred print_list(list(int)::in, io::di, io::uo) is det. -print_list(Xs) --> +print_list(Xs, !IO) :- ( - { Xs = [] } - -> - io__write_string("[]\n") + Xs = [], + io.write_string("[]\n", !IO) ; - io__write_string("["), - print_list_2(Xs), - io__write_string("]\n") + Xs = [_ | _], + io.write_string("[", !IO), + print_list_2(Xs, !IO), + io.write_string("]\n", !IO) ). -:- pred print_list_2(list(int), io__state, io__state). +:- pred print_list_2(list(int), io, io). :- mode print_list_2(in, di, uo) is det. -print_list_2([]) --> []. -print_list_2([X | Xs]) --> - io__write_int(X), +print_list_2([], !IO). +print_list_2([X | Xs], !IO) :- + io.write_int(X, !IO), ( - { Xs = [] } - -> - [] + Xs = [] ; - io__write_string(", "), - print_list_2(Xs) + Xs = [_ | _], + io.write_string(", ", !IO), + print_list_2(Xs, !IO) ). diff --git a/tests/debugger/output_term_dep.m b/tests/debugger/output_term_dep.m index 2ebec341e..9c1322e62 100644 --- a/tests/debugger/output_term_dep.m +++ b/tests/debugger/output_term_dep.m @@ -5,168 +5,148 @@ :- module output_term_dep. :- 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 list. -main --> +main(!IO) :- % Test cases which track an output subterm. - test1, % basic det conjunction - test2, % construction unification - test3, % if-then-else - test4, % switch and disjunction - test5. % negation + test1(!IO), % basic det conjunction + test2(!IO), % construction unification + test3(!IO), % if-then-else + test4(!IO), % switch and disjunction + test5(!IO). % negation %---------------------------------------------------------------------------% -:- pred test1(io__state::di, io__state::uo) is det. -test1 --> - { p(A, B, C) }, - io__write_int(A), - io__nl, - io__write_int(B), - io__nl, - io__write_int(C), - io__nl. +:- pred test1(io::di, io::uo) is det. -:- pred p(int, int, int). -:- mode p(out, out, out) is det. +test1(!IO) :- + p(A, B, C) , + io.write_int(A, !IO), + io.nl(!IO), + io.write_int(B, !IO), + io.nl(!IO), + io.write_int(C, !IO), + io.nl(!IO). + +:- pred p(int::out, int::out, int::out) is det. p(A, B, C) :- % tracking subterm B pa(A), pb(B), pc(C). -:- pred pa(int). -:- mode pa(out) is det. +:- pred pa(int::out) is det. pa(5). -:- pred pb(int). -:- mode pb(out) is det. +:- pred pb(int::out) is det. pb(8). -:- pred pc(int). -:- mode pc(out) is det. +:- pred pc(int::out) is det. pc(13). %---------------------------------------------------------------------------% -:- pred test2(io__state::di, io__state::uo) is det. -test2 --> - { q(X) }, - io__write(X), - io__nl. +:- pred test2(io::di, io::uo) is det. -:- pred q(list(list(int))). -:- mode q(out) is det. +test2(!IO) :- + q(X), + io.write_line(X, !IO). + +:- pred q(list(list(int))::out) is det. q([A, B, C]) :- % tracking subterm B qa(A), qb(B), qc(C). -:- pred qa(list(int)). -:- mode qa(out) is det. +:- pred qa(list(int)::out) is det. qa([1, 2, 3]). -:- pred qb(list(int)). -:- mode qb(out) is det. +:- pred qb(list(int)::out) is det. qb([]). -:- pred qc(list(int)). -:- mode qc(out) is det. +:- pred qc(list(int)::out) is det. qc([99]). %---------------------------------------------------------------------------% -:- pred test3(io__state::di, io__state::uo) is det. -test3 --> - { r(1, W) }, - io__write(W), - io__nl, - { r(2, X) }, - io__write(X), - io__nl, - { r(3, Y) }, - io__write(Y), - io__nl, - { r(4, Z) }, - io__write(Z), - io__nl. +:- pred test3(io::di, io::uo) is det. -:- pred r(int, int). -:- mode r(in, out) is det. +test3(!IO) :- + r(1, W), + io.write_line(W, !IO), + r(2, X), + io.write_line(X, !IO), + r(3, Y), + io.write_line(Y, !IO), + r(4, Z), + io.write_line(Z, !IO). + +:- pred r(int::in, int::out) is det. r(N, P) :- - ( - N = 1 - -> + ( if N = 1 then P = 999 - ; - ra(N) - -> - ( - rb(N) - -> + else if ra(N) then + ( if rb(N) then rc(P) - ; + else P = 43 ) - ; + else rd(P) ). -:- pred ra(int). -:- mode ra(in) is semidet. +:- pred ra(int::in) is semidet. ra(2). ra(3). -:- pred rb(int). -:- mode rb(in) is semidet. +:- pred rb(int::in) is semidet. rb(3). -:- pred rc(int). -:- mode rc(out) is det. +:- pred rc(int::out) is det. rc(57). -:- pred rd(int). -:- mode rd(out) is det. +:- pred rd(int::out) is det. rd(-1). %---------------------------------------------------------------------------% -:- pred test4(io__state::di, io__state::uo) is det. -test4 --> - ( - { s(1, _, X) }, - { sd(X) } - -> - io__write_string("yes\n") - ; - io__write_string("no\n") +:- pred test4(io::di, io::uo) is det. + +test4(!IO) :- + ( if + s(1, _, X), + sd(X) + then + io.write_string("yes\n", !IO) + else + io.write_string("no\n", !IO) ), - ( - { s(2, _, Y) }, - { sd(Y) } - -> - io__write_string("yes\n") - ; - io__write_string("no\n") + ( if + s(2, _, Y), + sd(Y) + then + io.write_string("yes\n", !IO) + else + io.write_string("no\n", !IO) ). -:- pred s(int, int, int). -:- mode s(in, out, out) is nondet. +:- pred s(int::in, int::out, int::out) is nondet. s(1, J, K) :- ( @@ -188,59 +168,49 @@ s(2, J, K) :- sc(K) ). -:- pred sa(int). -:- mode sa(out) is det. +:- pred sa(int::out) is det. sa(7). -:- pred sb(int). -:- mode sb(out) is det. +:- pred sb(int::out) is det. sb(38). -:- pred sc(int). -:- mode sc(out) is det. +:- pred sc(int::out) is det. sc(155). -:- pred sd(int). -:- mode sd(in) is semidet. +:- pred sd(int::in) is semidet. sd(-3). %---------------------------------------------------------------------------% -:- pred test5(io__state::di, io__state::uo) is det. -test5 --> - ( - { t(1, K) } - -> - io__write_int(K), - io__nl - ; - io__write_string("no\n") +:- pred test5(io::di, io::uo) is det. +test5(!IO) :- + ( if t(1, K) then + io.write_int(K, !IO), + io.nl(!IO) + else + io.write_string("no\n", !IO) ). -:- pred t(int, int). -:- mode t(in, out) is semidet. +:- pred t(int::in, int::out) is semidet. t(J, K) :- - \+ ta(J), + not ta(J), tb(K), - \+ tc(K). + not tc(K). -:- pred ta(int). -:- mode ta(in) is semidet. +:- pred ta(int::in) is semidet. ta(0). -:- pred tb(int). -:- mode tb(out) is det. +:- pred tb(int::out) is det. tb(77). -:- pred tc(int). -:- mode tc(in) is semidet. +:- pred tc(int::in) is semidet. tc(-654). diff --git a/tests/debugger/poly_io_retry.m b/tests/debugger/poly_io_retry.m index 01d1d1ff9..e3f5363b8 100644 --- a/tests/debugger/poly_io_retry.m +++ b/tests/debugger/poly_io_retry.m @@ -33,7 +33,7 @@ polycall(P, !S) :- P(!S). array_update(!A) :- !:A = !.A ^ elem(0) := 1. -:- pred poly_io_retry.write_int(int::in, io__state::di, io__state::uo) +:- pred poly_io_retry.write_int(int::in, io::di, io::uo) is det. :- pragma foreign_proc("C", diff --git a/tests/debugger/print_goal.m b/tests/debugger/print_goal.m index 5cc87787d..264ebe842 100644 --- a/tests/debugger/print_goal.m +++ b/tests/debugger/print_goal.m @@ -1,12 +1,12 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module print_goal. :- interface. :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. @@ -17,20 +17,20 @@ ---> big(big, int, big) ; small. -main --> - { big_data(Data) }, - io__print(Data), - io__write_string(".\n"), - print_goal(yes, 100, 101, _, Y, 102, Z), - io__print(Y), - io__write_string(".\n"), - io__print(Z), - io__write_string(".\n"), - print_goal(no, 100, 101, _, Y2, 102, Z2), - io__print(Y2), - io__write_string(".\n"), - io__print(Z2), - io__write_string(".\n"). +main(!IO) :- + big_data(Data), + io.print(Data, !IO), + io.write_string(".\n", !IO), + print_goal(yes, 100, 101, _, Y, 102, Z, !IO), + io.print(Y, !IO), + io.write_string(".\n", !IO), + io.print(Z, !IO), + io.write_string(".\n", !IO), + print_goal(no, 100, 101, _, Y2, 102, Z2, !IO), + io.print(Y2, !IO), + io.write_string(".\n", !IO), + io.print(Z2, !IO), + io.write_string(".\n", !IO). :- pred big_data(big::out) is det. @@ -62,7 +62,7 @@ big_data(Data) :- ). :- pred print_goal(bool::in, int::in, int::in, int::out, int::out, int::in, - int::out, io__state::di, io__state::uo) is det. + int::out, io::di, io::uo) is det. -print_goal(yes, _W, X, X + 1, X + 2, Y, Y + 1) --> []. -print_goal(no, _W, X, X + 2, X + 3, Y, Y + 2) --> []. +print_goal(yes, _W, X, X + 1, X + 2, Y, Y + 1, !IO). +print_goal(no, _W, X, X + 2, X + 3, Y, Y + 2, !IO). diff --git a/tests/debugger/print_io_actions.m b/tests/debugger/print_io_actions.m index 64ead09e3..683865974 100644 --- a/tests/debugger/print_io_actions.m +++ b/tests/debugger/print_io_actions.m @@ -22,13 +22,13 @@ main(!IO) :- fake_open_input("print_io_actions.data", Res, Stream, !IO), - ( Res = 0 -> + ( if Res = 0 then fake_read_n_chars(Stream, 40, CharList1, !IO), fake_read_n_chars(Stream, 40, CharList2, !IO), Str = string.from_char_list(CharList1 ++ CharList2), io.write_string(Str, !IO), io.nl(!IO) - ; + else io.write_string("could not open print_io_actions.data\n", !IO) ). @@ -36,13 +36,13 @@ main(!IO) :- io::di, io::uo) is det. fake_read_n_chars(Stream, N, Chars, !IO) :- - ( N =< 0 -> + ( if N =< 0 then Chars = [] - ; + else fake_read_char_code(Stream, CharCode, !IO), - ( CharCode = -1 -> + ( if CharCode = -1 then Chars = [] - ; + else Char = char.det_from_int(CharCode), fake_read_n_chars(Stream, N - 1, TailChars, !IO), Chars = [Char | TailChars] diff --git a/tests/debugger/print_table.m b/tests/debugger/print_table.m index 7575a55bf..b00a8683b 100644 --- a/tests/debugger/print_table.m +++ b/tests/debugger/print_table.m @@ -8,7 +8,7 @@ :- import_module io. -:- pred main(io.state::di, io.state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. @@ -19,83 +19,83 @@ :- import_module solutions. :- import_module string. -main --> - { p(5, 5, P55) }, - { p(4, 3, P43) }, - { p(2, 2, P22) }, - { p(1, 0, P10) }, - { q(3, 2, Q32) -> +main(!IO) :- + p(5, 5, P55), + p(4, 3, P43), + p(2, 2, P22), + p(1, 0, P10), + ( if q(3, 2, Q32) then MaybeQ32 = yes(Q32) - ; + else MaybeQ32 = no - }, - { q(4, 2, Q42) -> + ), + ( if q(4, 2, Q42) then MaybeQ42 = yes(Q42) - ; + else MaybeQ42 = no - }, - { r(3, R3) }, - { s(3.5, 1, "abc", 1, SA, TA) }, - { s(3.5, 2, "abc", 2, SB, TB) }, - { s(3.5, 2, "xyz", 3, SC, TC) }, - { s(3.5, 2, "xyz", 4, SD, TD) }, - { s(9.2, 2, "def", 5, SE, TE) }, - { solutions(t(1, 2), T12) }, - { solutions(t(2, 2), T22) }, - { tdone }, - { solutions(u(1, 2, 2), U12) }, - { solutions(u(2, 2, 2), U22) }, - { udone }, - io.write_int(P55), - io.nl, - io.write_int(P43), - io.nl, - io.write_int(P22), - io.nl, - io.write_int(P10), - io.nl, - io.write(MaybeQ32), - io.nl, - io.write(MaybeQ42), - io.nl, - io.write_int(R3), - io.nl, - io.write_string(SA), - io.write_string(" "), - io.write_float(TA), - io.nl, - io.write_string(SB), - io.write_string(" "), - io.write_float(TB), - io.nl, - io.write_string(SC), - io.write_string(" "), - io.write_float(TC), - io.nl, - io.write_string(SD), - io.write_string(" "), - io.write_float(TD), - io.nl, - io.write_string(SE), - io.write_string(" "), - io.write_float(TE), - io.nl, - io.write(T12), - io.nl, - io.write(T22), - io.nl, - io.write(U12), - io.nl, - io.write(U22), - io.nl. + ), + r(3, R3), + s(3.5, 1, "abc", 1, SA, TA), + s(3.5, 2, "abc", 2, SB, TB), + s(3.5, 2, "xyz", 3, SC, TC), + s(3.5, 2, "xyz", 4, SD, TD), + s(9.2, 2, "def", 5, SE, TE), + solutions(t(1, 2), T12), + solutions(t(2, 2), T22), + tdone, + solutions(u(1, 2, 2), U12), + solutions(u(2, 2, 2), U22), + udone, + io.write_int(P55, !IO), + io.nl(!IO), + io.write_int(P43, !IO), + io.nl(!IO), + io.write_int(P22, !IO), + io.nl(!IO), + io.write_int(P10, !IO), + io.nl(!IO), + io.write(MaybeQ32, !IO), + io.nl(!IO), + io.write(MaybeQ42, !IO), + io.nl(!IO), + io.write_int(R3, !IO), + io.nl(!IO), + io.write_string(SA, !IO), + io.write_string(" ", !IO), + io.write_float(TA, !IO), + io.nl(!IO), + io.write_string(SB, !IO), + io.write_string(" ", !IO), + io.write_float(TB, !IO), + io.nl(!IO), + io.write_string(SC, !IO), + io.write_string(" ", !IO), + io.write_float(TC, !IO), + io.nl(!IO), + io.write_string(SD, !IO), + io.write_string(" ", !IO), + io.write_float(TD, !IO), + io.nl(!IO), + io.write_string(SE, !IO), + io.write_string(" ", !IO), + io.write_float(TE, !IO), + io.nl(!IO), + io.write(T12, !IO), + io.nl(!IO), + io.write(T22, !IO), + io.nl(!IO), + io.write(U12, !IO), + io.nl(!IO), + io.write(U22, !IO), + io.nl(!IO). :- pred p(int::in, int::in, int::out) is det. :- pragma memo(p/3). p(A, B, S) :- - ( B = 0 -> + ( if B = 0 then S = 0 - ; + else p(A, B - 1, S0), S = A * B + S0 ). @@ -104,11 +104,11 @@ p(A, B, S) :- :- pragma memo(q/3). q(A, B, S) :- - ( B = 0 -> + ( if B = 0 then S = 0 - ; A = 4 * B -> + else if A = 4 * B then fail - ; + else q(A, B - 1, S0), S = A * B + S0 ). @@ -117,9 +117,9 @@ q(A, B, S) :- :- pragma memo(r/2). r(A, S) :- - ( A = 0 -> + ( if A = 0 then S = 0 - ; + else r(A - 1, S0), S = A + S0 ). @@ -129,24 +129,23 @@ r(A, S) :- :- pragma memo(s/6). s(A, B, C, D, S, T) :- - string__format("%3.1f", [f(A)], AS), - string__int_to_string(B, BS), - string__append_list(["[", AS, C, BS, "]"], S0), - S = from_char_list(list__condense( - list__duplicate(D, to_char_list(S0)))), + string.format("%3.1f", [f(A)], AS), + string.int_to_string(B, BS), + string.append_list(["[", AS, C, BS, "]"], S0), + S = from_char_list(list.condense(list.duplicate(D, to_char_list(S0)))), T = A + float(D). :- pred t(int::in, int::in, int::out) is nondet. :- pragma memo(t/3). t(A, B, C) :- - ( A = 1 -> + ( if A = 1 then ( C = (A * 100) + (B * 10) ; C = (B * 100) + (A * 10) ) - ; + else fail ). @@ -158,13 +157,13 @@ tdone. :- pragma memo(u/4, [specified([value, value, promise_implied, output])]). u(A, B, Bcopy, C) :- - ( A = 1 -> + ( if A = 1 then ( C = (A * 100) + (B * 10) ; C = (Bcopy * 100) + (A * 10) ) - ; + else fail ). diff --git a/tests/debugger/queens.exp b/tests/debugger/queens.exp index ad5bfe7b3..6bb91c48d 100644 --- a/tests/debugger/queens.exp +++ b/tests/debugger/queens.exp @@ -1,4 +1,4 @@ - E1: C1 CALL pred queens.main/2-0 (cc_multi) queens.m:19 + E1: C1 CALL pred queens.main/2-0 (cc_multi) queens.m:23 mdb> echo on Command echo enabled. mdb> register --quiet @@ -9,21 +9,21 @@ mdb: there are no live variables. mdb> b data 0: + stop interface pred queens.data/1-0 (det) mdb> continue - E2: C2 CALL pred queens.data/1-0 (det) queens.m:29 (queens.m:20) + E2: C2 CALL pred queens.data/1-0 (det) queens.m:32 (queens.m:24) mdb> delete 0 0: E stop interface pred queens.data/1-0 (det) mdb> print * mdb: there are no live variables. mdb> - E3: C2 EXIT pred queens.data/1-0 (det) queens.m:29 (queens.m:20) + E3: C2 EXIT pred queens.data/1-0 (det) queens.m:32 (queens.m:24) mdb> print * HeadVar__1 [1, 2, 3, 4, 5] mdb> - E4: C3 CALL pred queens.queen/2-0 (nondet) queens.m:34 (queens.m:20) + E4: C3 CALL pred queens.queen/2-0 (nondet) queens.m:36 (queens.m:24) mdb> print * Data (arg 1) [1, 2, 3, 4, 5] mdb> - E5: C4 CALL pred queens.qperm/2-0 (nondet) queens.m:41 (queens.m:35) + E5: C4 CALL pred queens.qperm/2-0 (nondet) queens.m:42 (queens.m:37) mdb> print * HeadVar__1 [1, 2, 3, 4, 5] mdb> print_optionals on @@ -34,11 +34,11 @@ mdb> print_optionals off mdb> print * HeadVar__1 [1, 2, 3, 4, 5] mdb> - E6: C4 SWTC pred queens.qperm/2-0 (nondet) s2-2; queens.m:42 + E6: C4 SWTC pred queens.qperm/2-0 (nondet) s2-2; queens.m:43 mdb> print * HeadVar__1 [1, 2, 3, 4, 5] mdb> - E7: C5 CALL pred queens.qdelete/3-0 (nondet) queens.m:50 (queens.m:43) + E7: C5 CALL pred queens.qdelete/3-0 (nondet) queens.m:50 (queens.m:44) mdb> print * HeadVar__2 [1, 2, 3, 4, 5] mdb> @@ -47,43 +47,43 @@ mdb> print * HeadVar__2 [1, 2, 3, 4, 5] mdb> level 1 Ancestor level set to 1: - 1 pred queens.qperm/2-0 (nondet) queens.m:43 + 1 pred queens.qperm/2-0 (nondet) queens.m:44 mdb> level -d 1 Ancestor level set to 1: - 1 E5 C4 3 pred queens.qperm/2-0 (nondet) queens.m:43 + 1 E5 C4 3 pred queens.qperm/2-0 (nondet) queens.m:44 mdb> context nextline Contexts will be printed on the next line. mdb> level 1 Ancestor level set to 1: 1 pred queens.qperm/2-0 (nondet) - queens.m:43 + queens.m:44 mdb> level -d 1 Ancestor level set to 1: 1 E5 C4 3 pred queens.qperm/2-0 (nondet) - queens.m:43 + queens.m:44 mdb> context prevline Contexts will be printed on the previous line. mdb> level 1 Ancestor level set to 1: - 1 queens.m:43 + 1 queens.m:44 pred queens.qperm/2-0 (nondet) mdb> level -d 1 Ancestor level set to 1: - 1 E5 C4 3 queens.m:43 + 1 E5 C4 3 queens.m:44 pred queens.qperm/2-0 (nondet) mdb> print * HeadVar__1 [1, 2, 3, 4, 5] L [1, 2, 3, 4, 5] mdb> up 1 Ancestor level set to 2: - 2 queens.m:35 + 2 queens.m:37 pred queens.queen/2-0 (nondet) mdb> vars 1 Data (arg 1) mdb> print * Data (arg 1) [1, 2, 3, 4, 5] mdb> - E9: C5 EXIT queens.m:50 (from queens.m:43) + E9: C5 EXIT queens.m:50 (from queens.m:44) pred queens.qdelete/3-0 (nondet) mdb> print HeadVar__1 HeadVar__1 1 @@ -129,17 +129,17 @@ There are 5 diffs, showing diff 5: mdb> diff $y $z^2 There are no diffs. mdb> - E10: C6 CALL queens.m:41 (from queens.m:45) + E10: C6 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> print * HeadVar__1 [2, 3, 4, 5] mdb> - E11: C6 SWTC queens.m:42 + E11: C6 SWTC queens.m:43 pred queens.qperm/2-0 (nondet) s2-2; mdb> print * HeadVar__1 [2, 3, 4, 5] mdb> - E12: C7 CALL queens.m:50 (from queens.m:43) + E12: C7 CALL queens.m:50 (from queens.m:44) pred queens.qdelete/3-0 (nondet) mdb> print * HeadVar__2 [2, 3, 4, 5] @@ -149,84 +149,84 @@ mdb> mdb> print * HeadVar__2 [2, 3, 4, 5] mdb> - E14: C7 EXIT queens.m:50 (from queens.m:43) + E14: C7 EXIT queens.m:50 (from queens.m:44) pred queens.qdelete/3-0 (nondet) mdb> print * HeadVar__1 2 HeadVar__2 [2, 3, 4, 5] HeadVar__3 [3, 4, 5] mdb> - E15: C8 CALL queens.m:41 (from queens.m:45) + E15: C8 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> goto -a 21 - E16: C8 SWTC queens.m:42 + E16: C8 SWTC queens.m:43 pred queens.qperm/2-0 (nondet) s2-2; - E17: C9 CALL queens.m:50 (from queens.m:43) + E17: C9 CALL queens.m:50 (from queens.m:44) pred queens.qdelete/3-0 (nondet) E18: C9 DISJ queens.m:50 pred queens.qdelete/3-0 (nondet) c2;d1; - E19: C9 EXIT queens.m:50 (from queens.m:43) + E19: C9 EXIT queens.m:50 (from queens.m:44) pred queens.qdelete/3-0 (nondet) - E20: C10 CALL queens.m:41 (from queens.m:45) + E20: C10 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> stack - 0 4* pred queens.qperm/2-0 (nondet) (queens.m:41 and others) - 4 pred queens.queen/2-0 (nondet) (queens.m:35) - 5 pred queens.main/2-0 (cc_multi) (queens.m:20) + 0 4* pred queens.qperm/2-0 (nondet) (queens.m:42 and others) + 4 pred queens.queen/2-0 (nondet) (queens.m:37) + 5 pred queens.main/2-0 (cc_multi) (queens.m:24) mdb> stack -d - 0 E20 C10 6 pred queens.qperm/2-0 (nondet) (queens.m:41) (empty) - 1 E15 C8 5 pred queens.qperm/2-0 (nondet) (queens.m:45) s2-2;c3; - 2 E10 C6 4 pred queens.qperm/2-0 (nondet) (queens.m:45) s2-2;c3; - 3 E5 C4 3 pred queens.qperm/2-0 (nondet) (queens.m:45) s2-2;c3; - 4 E4 C3 2 pred queens.queen/2-0 (nondet) (queens.m:35) c2; - 5 E1 C1 1 pred queens.main/2-0 (cc_multi) (queens.m:20) ?;c2;q!; + 0 E20 C10 6 pred queens.qperm/2-0 (nondet) (queens.m:42) (empty) + 1 E15 C8 5 pred queens.qperm/2-0 (nondet) (queens.m:46) s2-2;c3; + 2 E10 C6 4 pred queens.qperm/2-0 (nondet) (queens.m:46) s2-2;c3; + 3 E5 C4 3 pred queens.qperm/2-0 (nondet) (queens.m:46) s2-2;c3; + 4 E4 C3 2 pred queens.queen/2-0 (nondet) (queens.m:37) c2; + 5 E1 C1 1 pred queens.main/2-0 (cc_multi) (queens.m:24) ?;c2;q!; mdb> stack 3 - 0 4* pred queens.qperm/2-0 (nondet) (queens.m:41 and others) - 4 pred queens.queen/2-0 (nondet) (queens.m:35) - 5 pred queens.main/2-0 (cc_multi) (queens.m:20) + 0 4* pred queens.qperm/2-0 (nondet) (queens.m:42 and others) + 4 pred queens.queen/2-0 (nondet) (queens.m:37) + 5 pred queens.main/2-0 (cc_multi) (queens.m:24) mdb> stack -d 3 - 0 E20 C10 6 pred queens.qperm/2-0 (nondet) (queens.m:41) (empty) - 1 E15 C8 5 pred queens.qperm/2-0 (nondet) (queens.m:45) s2-2;c3; - 2 E10 C6 4 pred queens.qperm/2-0 (nondet) (queens.m:45) s2-2;c3; + 0 E20 C10 6 pred queens.qperm/2-0 (nondet) (queens.m:42) (empty) + 1 E15 C8 5 pred queens.qperm/2-0 (nondet) (queens.m:46) s2-2;c3; + 2 E10 C6 4 pred queens.qperm/2-0 (nondet) (queens.m:46) s2-2;c3; mdb> print * HeadVar__1 [4, 5] mdb> - E21: C10 SWTC queens.m:42 + E21: C10 SWTC queens.m:43 pred queens.qperm/2-0 (nondet) s2-2; mdb> retry - E20: C10 CALL queens.m:41 (from queens.m:45) + E20: C10 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> print * HeadVar__1 [4, 5] mdb> finish -a - E21: C10 SWTC queens.m:42 + E21: C10 SWTC queens.m:43 pred queens.qperm/2-0 (nondet) s2-2; - E22: C11 CALL queens.m:50 (from queens.m:43) + E22: C11 CALL queens.m:50 (from queens.m:44) pred queens.qdelete/3-0 (nondet) E23: C11 DISJ queens.m:50 pred queens.qdelete/3-0 (nondet) c2;d1; - E24: C11 EXIT queens.m:50 (from queens.m:43) + E24: C11 EXIT queens.m:50 (from queens.m:44) pred queens.qdelete/3-0 (nondet) - E25: C12 CALL queens.m:41 (from queens.m:45) + E25: C12 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E26: C12 SWTC queens.m:42 + E26: C12 SWTC queens.m:43 pred queens.qperm/2-0 (nondet) s2-2; - E27: C13 CALL queens.m:50 (from queens.m:43) + E27: C13 CALL queens.m:50 (from queens.m:44) pred queens.qdelete/3-0 (nondet) E28: C13 DISJ queens.m:50 pred queens.qdelete/3-0 (nondet) c2;d1; - E29: C13 EXIT queens.m:50 (from queens.m:43) + E29: C13 EXIT queens.m:50 (from queens.m:44) pred queens.qdelete/3-0 (nondet) - E30: C14 CALL queens.m:41 (from queens.m:45) + E30: C14 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E31: C14 SWTC queens.m:41 + E31: C14 SWTC queens.m:42 pred queens.qperm/2-0 (nondet) s1-2; - E32: C14 EXIT queens.m:41 (from queens.m:45) + E32: C14 EXIT queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E33: C12 EXIT queens.m:41 (from queens.m:45) + E33: C12 EXIT queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E34: C10 EXIT queens.m:41 (from queens.m:45) + E34: C10 EXIT queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> register --quiet mdb> break print_list @@ -237,43 +237,43 @@ mdb> break_print HeadVar__2^2 1: + stop interface pred queens.qdelete/3-0 (nondet) HeadVar__2^2 (flat) mdb> continue -a - E35: C8 EXIT queens.m:41 (from queens.m:45) + E35: C8 EXIT queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E36: C6 EXIT queens.m:41 (from queens.m:45) + E36: C6 EXIT queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E37: C4 EXIT queens.m:41 (from queens.m:35) + E37: C4 EXIT queens.m:42 (from queens.m:37) pred queens.qperm/2-0 (nondet) - E38: C15 CALL queens.m:57 (from queens.m:36) + E38: C15 CALL queens.m:56 (from queens.m:38) pred queens.safe/1-0 (semidet) - E39: C15 SWTC queens.m:58 + E39: C15 SWTC queens.m:57 pred queens.safe/1-0 (semidet) s2-2; - E40: C16 CALL queens.m:65 (from queens.m:59) + E40: C16 CALL queens.m:63 (from queens.m:58) pred queens.nodiag/3-0 (semidet) - E41: C16 SWTC queens.m:66 + E41: C16 SWTC queens.m:64 pred queens.nodiag/3-0 (semidet) s2-2; - E42: C16 COND queens.m:69 + E42: C16 COND queens.m:67 pred queens.nodiag/3-0 (semidet) s2-2;c4;?; - E43: C16 THEN queens.m:70 + E43: C16 THEN queens.m:68 pred queens.nodiag/3-0 (semidet) s2-2;c4;t; - E44: C16 FAIL queens.m:65 (from queens.m:59) + E44: C16 FAIL queens.m:63 (from queens.m:58) pred queens.nodiag/3-0 (semidet) - E45: C15 FAIL queens.m:57 (from queens.m:36) + E45: C15 FAIL queens.m:56 (from queens.m:38) pred queens.safe/1-0 (semidet) - E46: C4 REDO queens.m:41 (from queens.m:35) + E46: C4 REDO queens.m:42 (from queens.m:37) pred queens.qperm/2-0 (nondet) - E47: C6 REDO queens.m:41 (from queens.m:45) + E47: C6 REDO queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E48: C8 REDO queens.m:41 (from queens.m:45) + E48: C8 REDO queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E49: C10 REDO queens.m:41 (from queens.m:45) + E49: C10 REDO queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E50: C12 REDO queens.m:41 (from queens.m:45) + E50: C12 REDO queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E51: C14 REDO queens.m:41 (from queens.m:45) + E51: C14 REDO queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E52: C14 FAIL queens.m:41 (from queens.m:45) + E52: C14 FAIL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E53: C13 REDO queens.m:50 (from queens.m:43) + E53: C13 REDO queens.m:50 (from queens.m:44) pred queens.qdelete/3-0 (nondet) HeadVar__2^2 [] mdb> break info @@ -292,86 +292,86 @@ mdb: the path 2 does not exist in variable HeadVar__2. E56: C17 FAIL queens.m:50 (from queens.m:52) pred queens.qdelete/3-0 (nondet) mdb: the path 2 does not exist in variable HeadVar__2. - E57: C13 FAIL queens.m:50 (from queens.m:43) + E57: C13 FAIL queens.m:50 (from queens.m:44) pred queens.qdelete/3-0 (nondet) HeadVar__2^2 [] - E58: C12 FAIL queens.m:41 (from queens.m:45) + E58: C12 FAIL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> disable 1 1: - stop interface pred queens.qdelete/3-0 (nondet) mdb> retry 4 - E5: C4 CALL queens.m:41 (from queens.m:35) + E5: C4 CALL queens.m:42 (from queens.m:37) pred queens.qperm/2-0 (nondet) -mdb> break 45 - 2: + stop linenumber queens.m:45 +mdb> break 46 + 2: + stop linenumber queens.m:46 mdb> continue -n - E10: C6 CALL queens.m:41 (from queens.m:45) + E10: C6 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> continue -n - E15: C8 CALL queens.m:41 (from queens.m:45) + E15: C8 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> continue -n - E20: C10 CALL queens.m:41 (from queens.m:45) + E20: C10 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> continue -n - E25: C12 CALL queens.m:41 (from queens.m:45) + E25: C12 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> continue -n - E30: C14 CALL queens.m:41 (from queens.m:45) + E30: C14 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> continue -n - E32: C14 EXIT queens.m:41 (from queens.m:45) + E32: C14 EXIT queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> return - E33: C12 EXIT queens.m:41 (from queens.m:45) + E33: C12 EXIT queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E34: C10 EXIT queens.m:41 (from queens.m:45) + E34: C10 EXIT queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E35: C8 EXIT queens.m:41 (from queens.m:45) + E35: C8 EXIT queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E36: C6 EXIT queens.m:41 (from queens.m:45) + E36: C6 EXIT queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E38: C15 CALL queens.m:57 (from queens.m:36) + E38: C15 CALL queens.m:56 (from queens.m:38) pred queens.safe/1-0 (semidet) mdb> continue -n - E47: C6 REDO queens.m:41 (from queens.m:45) + E47: C6 REDO queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> continue -n - E48: C8 REDO queens.m:41 (from queens.m:45) + E48: C8 REDO queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> forward - E49: C10 REDO queens.m:41 (from queens.m:45) + E49: C10 REDO queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E50: C12 REDO queens.m:41 (from queens.m:45) + E50: C12 REDO queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E51: C14 REDO queens.m:41 (from queens.m:45) + E51: C14 REDO queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) - E52: C14 FAIL queens.m:41 (from queens.m:45) + E52: C14 FAIL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) E54: C13 DISJ queens.m:51 pred queens.qdelete/3-0 (nondet) c2;d2; mdb> continue -n - E58: C12 FAIL queens.m:41 (from queens.m:45) + E58: C12 FAIL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> continue -n - E59: C18 CALL queens.m:41 (from queens.m:45) + E59: C18 CALL queens.m:42 (from queens.m:46) pred queens.qperm/2-0 (nondet) mdb> delete * 0: E stop interface pred queens.print_list/3-0 (det) 1: D stop interface pred queens.qdelete/3-0 (nondet) - 2: E stop linenumber queens.m:45 + 2: E stop linenumber queens.m:46 mdb> break main SWTC There is no SWTC port in pred queens.main/2-0 (cc_multi). mdb> break main EXIT 0: + stop specific pred queens.main/2-0 (cc_multi) EXIT mdb> continue -n [1, 3, 5, 2, 4] - E60: C1 EXIT queens.m:19 + E60: C1 EXIT queens.m:23 pred queens.main/2-0 (cc_multi) mdb> retry Retry across I/O operations is not always safe. Are you sure you want to do it? yes - E1: C1 CALL queens.m:19 + E1: C1 CALL queens.m:23 pred queens.main/2-0 (cc_multi) mdb> delete 0 0: E stop specific pred queens.main/2-0 (cc_multi) EXIT @@ -390,14 +390,14 @@ mdb> condition HeadVar__1 = [1,2, 5, 4, 3 ] 0: + stop interface pred queens.safe/1-0 (semidet) HeadVar__1 = [1, 2, 5, 4, 3] mdb> continue - E61: C19 CALL queens.m:57 (from queens.m:36) + E61: C19 CALL queens.m:56 (from queens.m:38) pred queens.safe/1-0 (semidet) mdb> print safe([1, 2, 5, 4, 3]) mdb> retry 2 Retry across I/O operations is not always safe. Are you sure you want to do it? yes - E1: C1 CALL queens.m:19 + E1: C1 CALL queens.m:23 pred queens.main/2-0 (cc_multi) mdb> disable 0 0: - stop interface pred queens.safe/1-0 (semidet) @@ -410,7 +410,7 @@ Ambiguous port specification. The matches are: Which do you want to put a breakpoint on (0-1 or *)? 1 1: + stop specific pred queens.nodiag/3-0 (semidet) SWTC s2-2; mdb> continue - E41: C16 SWTC queens.m:66 + E41: C16 SWTC queens.m:64 pred queens.nodiag/3-0 (semidet) s2-2; mdb> print * B (arg 1) 1 diff --git a/tests/debugger/queens.inp b/tests/debugger/queens.inp index a80d457fd..d3b923b0b 100644 --- a/tests/debugger/queens.inp +++ b/tests/debugger/queens.inp @@ -83,7 +83,7 @@ enable * step -aS 5 disable 1 retry 4 -break 45 +break 46 continue -n continue -n continue -n diff --git a/tests/debugger/queens.m b/tests/debugger/queens.m index e917a7087..ae3a40922 100644 --- a/tests/debugger/queens.m +++ b/tests/debugger/queens.m @@ -1,6 +1,11 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% +% +% The .exp file is for asm_fast.gc bootchecks. +% The .exp2 file is for XXX. +% +%---------------------------------------------------------------------------% :- module queens. @@ -8,35 +13,31 @@ :- import_module io. -:- pred main(io__state, io__state). -:- mode main(di, uo) is cc_multi. +:- pred main(io::di, io::uo) is cc_multi. :- implementation. :- import_module int. :- import_module list. -main --> - ( { data(Data), queen(Data, Out) } -> - print_list(Out) - ; - io__write_string("No solution\n") +main(!IO) :- + ( if data(Data), queen(Data, Out) then + print_list(Out, !IO) + else + io.write_string("No solution\n", !IO) ). -:- pred data(list(int)). -:- mode data(out) is det. +:- pred data(list(int)::out) is det. data([1, 2, 3, 4, 5]). -:- pred queen(list(int), list(int)). -:- mode queen(in, out) is nondet. +:- pred queen(list(int)::in, list(int)::out) is nondet. queen(Data, Out) :- qperm(Data, Out), safe(Out). -:- pred qperm(list(T), list(T)). -:- mode qperm(in, out) is nondet. +:- pred qperm(list(T)::in, list(T)::out) is nondet. qperm([], []). qperm(L, K) :- @@ -44,63 +45,57 @@ qperm(L, K) :- K = [U | V], qperm(Z, V). -:- pred qdelete(T, list(T), list(T)). -:- mode qdelete(out, in, out) is nondet. +:- pred qdelete(T::out, list(T)::in, list(T)::out) is nondet. qdelete(A, [A | L], L). qdelete(X, [A | Z], [A | R]) :- qdelete(X, Z, R). -:- pred safe(list(int)). -:- mode safe(in) is semidet. +:- pred safe(list(int)::in) is semidet. safe([]). safe([N | L]) :- nodiag(N, 1, L), safe(L). -:- pred nodiag(int, int, list(int)). -:- mode nodiag(in, in, in) is semidet. +:- pred nodiag(int::in, int::in, list(int)::in) is semidet. nodiag(_, _, []). nodiag(B, D, [N | L]) :- NmB = N - B, BmN = B - N, - ( D = NmB -> + ( if D = NmB then fail - ; D = BmN -> + else if D = BmN then fail - ; + else true ), D1 = D + 1, nodiag(B, D1, L). -:- pred print_list(list(int), io__state, io__state). -:- mode print_list(in, di, uo) is det. +:- pred print_list(list(int)::in, io::di, io::uo) is det. -print_list(Xs) --> +print_list(Xs, !IO) :- ( - { Xs = [] } - -> - io__write_string("[]\n") + Xs = [], + io.write_string("[]\n", !IO) ; - io__write_string("["), - print_list_2(Xs), - io__write_string("]\n") + Xs = [_ | _], + io.write_string("[", !IO), + print_list_2(Xs, !IO), + io.write_string("]\n", !IO) ). -:- pred print_list_2(list(int), io__state, io__state). -:- mode print_list_2(in, di, uo) is det. +:- pred print_list_2(list(int)::in, io::di, io::uo) is det. -print_list_2([]) --> []. -print_list_2([X | Xs]) --> - io__write_int(X), +print_list_2([], !IO). +print_list_2([X | Xs], !IO) :- + io.write_int(X, !IO), ( - { Xs = [] } - -> - [] + Xs = [] ; - io__write_string(", "), - print_list_2(Xs) + Xs = [_ | _], + io.write_string(", ", !IO), + print_list_2(Xs, !IO) ). diff --git a/tests/debugger/queens_rep.exp b/tests/debugger/queens_rep.exp index fed18dc13..cf9279713 100644 --- a/tests/debugger/queens_rep.exp +++ b/tests/debugger/queens_rep.exp @@ -1,4 +1,4 @@ - 1: 1 1 CALL pred queens_rep.main/2-0 (cc_multi) queens_rep.m:19 + 1: 1 1 CALL pred queens_rep.main/2-0 (cc_multi) queens_rep.m:18 mdb> echo on Command echo enabled. mdb> context none diff --git a/tests/debugger/queens_rep.m b/tests/debugger/queens_rep.m index fa6aa53a0..49c8e63f5 100644 --- a/tests/debugger/queens_rep.m +++ b/tests/debugger/queens_rep.m @@ -8,99 +8,89 @@ :- import_module io. -:- pred main(io__state, io__state). -:- mode main(di, uo) is cc_multi. +:- pred main(io::di, io::uo) is cc_multi. :- implementation. :- import_module int. :- import_module list. -main --> - ( { data(Data), queen(Data, Out) } -> - print_list(Out) - ; - io__write_string("No solution\n") +main(!IO) :- + ( if data(Data), queen(Data, Out) then + print_list(Out, !IO) + else + io.write_string("No solution\n", !IO) ). -:- pred data(list(int)). -:- mode data(out) is det. - -:- pred queen(list(int), list(int)). -:- mode queen(in, out) is nondet. - -:- pred qperm(list(T), list(T)). -:- mode qperm(in, out) is nondet. - -:- pred qdelete(T, list(T), list(T)). -:- mode qdelete(out, in, out) is nondet. - -:- pred safe(list(int)). -:- mode safe(in) is semidet. - -:- pred nodiag(int, int, list(int)). -:- mode nodiag(in, in, in) is semidet. +:- pred data(list(int)::out) is det. data([1, 2, 3, 4, 5]). +:- pred queen(list(int)::in, list(int)::out) is nondet. + queen(Data, Out) :- qperm(Data, Out), safe(Out). +:- pred qperm(list(T)::in, list(T)::out) is nondet. + qperm([], []). qperm(L, K) :- L = [_ | _], qdelete(U, L, Z), K = [U | V], qperm(Z, V). +:- pred qdelete(T::out, list(T)::in, list(T)::out) is nondet. + qdelete(A, [A | L], L). qdelete(X, [A | Z], [A | R]) :- qdelete(X, Z, R). +:- pred safe(list(int)::in) is semidet. + safe([]). safe([N | L]) :- nodiag(N, 1, L), safe(L). +:- pred nodiag(int::in, int::in, list(int)::in) is semidet. + nodiag(_, _, []). nodiag(B, D, [N | L]) :- NmB = N - B, BmN = B - N, - ( D = NmB -> + ( if D = NmB then fail - ; D = BmN -> + else if D = BmN then fail - ; + else true ), D1 = D + 1, nodiag(B, D1, L). -:- pred print_list(list(int), io__state, io__state). -:- mode print_list(in, di, uo) is det. +:- pred print_list(list(int)::in, io::di, io::uo) is det. -print_list(Xs) --> +print_list(Xs, !IO) :- ( - { Xs = [] } - -> - io__write_string("[]\n") + Xs = [], + io.write_string("[]\n", !IO) ; - io__write_string("["), - print_list_2(Xs), - io__write_string("]\n") + Xs = [_ | _], + io.write_string("[", !IO), + print_list_2(Xs, !IO), + io.write_string("]\n", !IO) ). -:- pred print_list_2(list(int), io__state, io__state). -:- mode print_list_2(in, di, uo) is det. +:- pred print_list_2(list(int)::in, io::di, io::uo) is det. -print_list_2([]) --> []. -print_list_2([X | Xs]) --> - io__write_int(X), +print_list_2([], !IO). +print_list_2([X | Xs], !IO) :- + io.write_int(X, !IO), ( - { Xs = [] } - -> - [] + Xs = [] ; - io__write_string(", "), - print_list_2(Xs) + Xs = [_ | _], + io.write_string(", ", !IO), + print_list_2(Xs, !IO) ). diff --git a/tests/debugger/resume_typeinfos.m b/tests/debugger/resume_typeinfos.m index ba458b4b3..c9cef03fd 100644 --- a/tests/debugger/resume_typeinfos.m +++ b/tests/debugger/resume_typeinfos.m @@ -24,7 +24,7 @@ :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. %---------------------------------------------------------------------------% @@ -33,12 +33,12 @@ :- import_module int. :- import_module list. -main --> - ( { test([1, 2], Result) } -> - io__write_int(Result), - io__write_string("\n") - ; - io__write_string("no solution.\n") +main(!IO) :- + ( if test([1, 2], Result) then + io.write_int(Result, !IO), + io.write_string("\n", !IO) + else + io.write_string("no solution.\n", !IO) ). :- some [U] pred introduce_new_typeinfo(list(T)::in, list(U)::out) is det. @@ -50,18 +50,16 @@ introduce_new_typeinfo(_, ["fortytwo"]). test(TestList, Result) :- introduce_new_typeinfo(TestList, NewList), - ( - list__length(TestList, Length), + ( if + list.length(TestList, Length), Length > 5 - -> + then Result = 10 - ; - % The code here does not need the typeinfo for the - % elements of NewList, but typeinfo liveness requires - % this typeinfo to be in the resume point established - % for the condition, since the debugger may need it to - % print the value of NewList at the else event. - + else + % The code here does not need the typeinfo for the elements of NewList, + % but typeinfo liveness requires this typeinfo to be in the resume + % point established for the condition, since the debugger may need it + % to print the value of NewList at the else event. NewList = [], Result = 42 ). diff --git a/tests/debugger/retry.m b/tests/debugger/retry.m index adfde418d..52be452e5 100644 --- a/tests/debugger/retry.m +++ b/tests/debugger/retry.m @@ -20,7 +20,7 @@ :- import_module io. -:- pred main(io__state::di, io__state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. @@ -28,23 +28,22 @@ :- import_module list. :- import_module solutions. -main --> - { - det_without_cut(1, A), - det_with_cut(2, B), - det_with_cut(3, C), - solutions(nondet(4), Ds), - solutions(nondet(5), Es) - }, - output(A), - output(B), - output(C), - outputs(Ds), - outputs(Es), - { fib(15, F) }, - output(F), - { solutions(t(1, 2), T12) }, - outputs(T12). +main(!IO) :- + det_without_cut(1, A), + det_with_cut(2, B), + det_with_cut(3, C), + solutions(nondet(4), Ds), + solutions(nondet(5), Es), + + output(A, !IO), + output(B, !IO), + output(C, !IO), + outputs(Ds, !IO), + outputs(Es, !IO), + fib(15, F), + output(F, !IO), + solutions(t(1, 2), T12), + outputs(T12, !IO). %---------------------------------------------------------------------------% @@ -67,9 +66,9 @@ det_without_cut_2(X, X). :- pred det_with_cut(int::in, int::out) is det. det_with_cut(X0, X) :- - ( det_with_cut_1(X0, _) -> + ( if det_with_cut_1(X0, _) then X = X0 * 2 - ; + else X = X0 * 3 ). @@ -94,9 +93,9 @@ det_with_cut_2(X, X). nondet(X0, X) :- nondet_1(X0, X1), nondet_2(X1, X2), - ( X2 < 75 -> + ( if X2 < 75 then X = X2 - ; + else X = 2 * X2 ). @@ -120,9 +119,9 @@ nondet_2(X, X). :- pragma memo(fib/2). fib(N, F) :- - ( N < 2 -> + ( if N < 2 then F = 1 - ; + else fib(N - 1, F1), fib(N - 2, F2), F = F1 + F2 @@ -133,13 +132,13 @@ fib(N, F) :- t(A, B, C) :- marker("t", A, B, Zero), - ( A = 1 -> + ( if A = 1 then ( C = Zero + (A * 100) + (B * 10) ; C = Zero + (B * 100) + (A * 10) ) - ; + else fail ). @@ -155,22 +154,22 @@ t(A, B, C) :- %---------------------------------------------------------------------------% -:- pred output(int::in, io__state::di, io__state::uo) is det. +:- pred output(int::in, io::di, io::uo) is det. -output(X) --> - io__write_int(X), - io__write_string("\n"). +output(X, !IO) :- + io.write_int(X, !IO), + io.write_string("\n", !IO). -:- pred outputs(list(int)::in, io__state::di, io__state::uo) is det. +:- pred outputs(list(int)::in, io::di, io::uo) is det. -outputs(Xs) --> - outputs1(Xs), - io__write_string("\n"). +outputs(Xs, !IO) :- + outputs1(Xs, !IO), + io.write_string("\n", !IO). -:- pred outputs1(list(int)::in, io__state::di, io__state::uo) is det. +:- pred outputs1(list(int)::in, io::di, io::uo) is det. -outputs1([]) --> []. -outputs1([X | Xs]) --> - io__write_int(X), - io__write_string(" "), - outputs1(Xs). +outputs1([], !IO). +outputs1([X | Xs], !IO) :- + io.write_int(X, !IO), + io.write_string(" ", !IO), + outputs1(Xs, !IO). diff --git a/tests/debugger/shallow.exp2 b/tests/debugger/shallow.exp2 index 7aa63ba95..1a9d4a3fb 100644 --- a/tests/debugger/shallow.exp2 +++ b/tests/debugger/shallow.exp2 @@ -1,4 +1,4 @@ - 1: 1 1 CALL pred shallow.main/2-0 (cc_multi) shallow.m:20 + 1: 1 1 CALL pred shallow.main/2-0 (cc_multi) shallow.m:24 mdb> echo on Command echo enabled. mdb> context before @@ -6,12 +6,12 @@ Contexts will be printed before, on the same line. mdb> context Contexts are printed before, on the same line. mdb> step - 2: 2 2 CALL shallow2.m:18 (shallow.m:43) pred shallow2.safe/1-0 (semidet) + 2: 2 2 CALL shallow2.m:17 (shallow.m:39) pred shallow2.safe/1-0 (semidet) mdb> print * HeadVar__1 [1, 2, 3, 4, 5] mdb> stack - 0 pred shallow2.safe/1-0 (semidet) (shallow2.m:18) - 1 pred shallow.queen/2-0 (nondet) (shallow.m:43) - 2 pred shallow.main/2-0 (cc_multi) (shallow.m:21) + 0 pred shallow2.safe/1-0 (semidet) (shallow2.m:17) + 1 pred shallow.queen/2-0 (nondet) (shallow.m:39) + 2 pred shallow.main/2-0 (cc_multi) (shallow.m:25) mdb> c -S [1, 3, 5, 2, 4] diff --git a/tests/debugger/shallow.m b/tests/debugger/shallow.m index ed6f0b04c..84699a7a7 100644 --- a/tests/debugger/shallow.m +++ b/tests/debugger/shallow.m @@ -1,6 +1,11 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% +% +% The .exp file is for XXX. +% The .exp2 file is for asm_fast.gc bootchecks. +% +%---------------------------------------------------------------------------% :- module shallow. @@ -8,8 +13,7 @@ :- import_module io. -:- pred main(io__state, io__state). -:- mode main(di, uo) is cc_multi. +:- pred main(io::di, io::uo) is cc_multi. :- implementation. @@ -17,66 +21,59 @@ :- import_module int. :- import_module shallow2. -main --> - ( { data(Data), queen(Data, Out) } -> - print_list(Out) - ; - io__write_string("No solution\n") +main(!IO) :- + ( if data(Data), queen(Data, Out) then + print_list(Out, !IO) + else + io.write_string("No solution\n", !IO) ). -:- pred data(list(int)). -:- mode data(out) is det. - -:- pred queen(list(int), list(int)). -:- mode queen(in, out) is nondet. - -:- pred qperm(list(T), list(T)). -:- mode qperm(in, out) is nondet. - -:- pred qdelete(T, list(T), list(T)). -:- mode qdelete(out, in, out) is nondet. +:- pred data(list(int)::out) is det. data([1, 2, 3, 4, 5]). +:- pred queen(list(int)::in, list(int)::out) is nondet. + queen(Data, Out) :- qperm(Data, Out), safe(Out). +:- pred qperm(list(T)::in, list(T)::out) is nondet. + qperm([], []). qperm([X | Y], K) :- qdelete(U, [X | Y], Z), K = [U | V], qperm(Z, V). +:- pred qdelete(T::out, list(T)::in, list(T)::out) is nondet. + qdelete(A, [A | L], L). qdelete(X, [A | Z], [A | R]) :- qdelete(X, Z, R). -:- pred print_list(list(int), io__state, io__state). -:- mode print_list(in, di, uo) is det. +:- pred print_list(list(int)::in, io::di, io::uo) is det. -print_list(Xs) --> +print_list(Xs, !IO) :- ( - { Xs = [] } - -> - io__write_string("[]\n") + Xs = [], + io.write_string("[]\n", !IO) ; - io__write_string("["), - print_list_2(Xs), - io__write_string("]\n") + Xs = [_ | _], + io.write_string("[", !IO), + print_list_2(Xs, !IO), + io.write_string("]\n", !IO) ). -:- pred print_list_2(list(int), io__state, io__state). -:- mode print_list_2(in, di, uo) is det. +:- pred print_list_2(list(int)::in, io::di, io::uo) is det. -print_list_2([]) --> []. -print_list_2([X | Xs]) --> - io__write_int(X), +print_list_2([], !IO). +print_list_2([X | Xs], !IO) :- + io.write_int(X, !IO), ( - { Xs = [] } - -> - [] + Xs = [] ; - io__write_string(", "), - print_list_2(Xs) + Xs = [_ | _], + io.write_string(", ", !IO), + print_list_2(Xs, !IO) ). diff --git a/tests/debugger/shallow2.m b/tests/debugger/shallow2.m index f4bdb662b..18676494f 100644 --- a/tests/debugger/shallow2.m +++ b/tests/debugger/shallow2.m @@ -1,15 +1,14 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module shallow2. :- interface. :- import_module list. -:- pred safe(list(int)). -:- mode safe(in) is semidet. +:- pred safe(list(int)::in) is semidet. :- implementation. @@ -20,18 +19,17 @@ safe([N | L]) :- nodiag(N, 1, L), safe(L). -:- pred nodiag(int, int, list(int)). -:- mode nodiag(in, in, in) is semidet. +:- pred nodiag(int::in, int::in, list(int)::in) is semidet. nodiag(_, _, []). nodiag(B, D, [N | L]) :- NmB = N - B, BmN = B - N, - ( D = NmB -> + ( if D = NmB then fail - ; D = BmN -> + else if D = BmN then fail - ; + else true ), D1 = D + 1, diff --git a/tests/debugger/shell.m b/tests/debugger/shell.m index 5165f21b0..5d9aa249f 100644 --- a/tests/debugger/shell.m +++ b/tests/debugger/shell.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module shell. :- interface. diff --git a/tests/debugger/solver_test.m b/tests/debugger/solver_test.m index 8204a494d..18ba6b5ea 100644 --- a/tests/debugger/solver_test.m +++ b/tests/debugger/solver_test.m @@ -20,7 +20,8 @@ % initialization predicate. :- solver type foo - where representation is int, + where + representation is int, initialisation is init_foo, ground is ground, any is ground. @@ -31,9 +32,9 @@ :- import_module list. :- import_module bool. -main --> - { test_any_free_unify([], Result1) }, - io__print(Result1), io__nl. +main(!IO) :- + test_any_free_unify([], Result1), + io.print(Result1, !IO), io.nl(!IO). :- pred init_foo(foo::out(any)) is det. :- pragma promise_pure(init_foo/1). @@ -44,18 +45,17 @@ init_foo(X) :- :- pred test_any_free_unify(list(foo), bool). :- mode test_any_free_unify(in(list_skel(any)), out) is det. -% In the unification in the condition of the if-then-else, the variable -% List has an inst which includes `any' components. Normally, we can't -% check whether `any' has become further instantiated over a goal so we -% do not allow it in a negated context. However, in this case, the -% `any' component is unified with `free' so we know that it cannot have -% become further instantiated. Therefore we should allow the -% unification in the condition. +% In the unification in the condition of the if-then-else, the variable List +% has an inst which includes `any' components. Normally, we can't check +% whether `any' has become further instantiated over a goal so we do not allow +% it in a negated context. However, in this case, the `any' component +% is unified with `free' so we know that it cannot have become further +% instantiated. Therefore we should allow the unification in the condition. test_any_free_unify(List, Result) :- promise_pure - ( List = [_ | _] -> + ( if List = [_ | _] then Result = no - ; + else Result = yes ). diff --git a/tests/debugger/switch_on_unbounded.m b/tests/debugger/switch_on_unbounded.m index fbc05c9cc..ae9895368 100644 --- a/tests/debugger/switch_on_unbounded.m +++ b/tests/debugger/switch_on_unbounded.m @@ -19,16 +19,16 @@ :- import_module list. main(!IO) :- - ( edge(2, Two) -> + ( if edge(2, Two) then io.write_int(Two, !IO), io.nl(!IO) - ; + else io.write_string("edge(2, _) has no solution\n", !IO) ), - ( edge_str("2", TwoStr) -> + ( if edge_str("2", TwoStr) then io.write_string(TwoStr, !IO), io.nl(!IO) - ; + else io.write_string("edge_str(2, _) has no solution\n", !IO) ). diff --git a/tests/debugger/synth_attr.m b/tests/debugger/synth_attr.m index 1c9bede96..d8b849268 100644 --- a/tests/debugger/synth_attr.m +++ b/tests/debugger/synth_attr.m @@ -20,9 +20,9 @@ main(!IO) :- data(Data), - ( queen(Data, Out) -> + ( if queen(Data, Out) then print_list(Out, !IO) - ; + else io.write_string("No solution\n", !IO) ). @@ -41,9 +41,9 @@ queen(Data, Out) :- testlen(Min, L) = N :- list.length(L, N0), - ( N0 >= Min -> + ( if N0 >= Min then N = N0 - ; + else error("testlen: N < Min") ). @@ -75,15 +75,13 @@ nodiag(_, _, []). nodiag(B, D, [N | L]) :- NmB = N - B, BmN = B - N, - ( D = NmB -> - event nodiag_fail("N - B", B, N, list.length, list.sort, - [N | L]), + ( if D = NmB then + event nodiag_fail("N - B", B, N, list.length, list.sort, [N | L]), fail - ; D = BmN -> - event nodiag_fail("B - N", B, N, list.length, list.sort, - [N | L]), + else if D = BmN then + event nodiag_fail("B - N", B, N, list.length, list.sort, [N | L]), fail - ; + else true ), D1 = D + 1, @@ -111,6 +109,6 @@ print_list_2([X | Xs], !IO) :- Xs = [] ; Xs = [_ | _], - io__write_string(", ", !IO), + io.write_string(", ", !IO), print_list_2(Xs, !IO) ). diff --git a/tests/debugger/synth_attr_impure.m b/tests/debugger/synth_attr_impure.m index 8811eb131..673acf7e5 100644 --- a/tests/debugger/synth_attr_impure.m +++ b/tests/debugger/synth_attr_impure.m @@ -27,9 +27,9 @@ main(!IO) :- data(Data), - ( queen(Data, Out) -> + ( if queen(Data, Out) then print_list(Out, !IO) - ; + else io.write_string("No solution\n", !IO) ). @@ -67,9 +67,9 @@ int safe_counter = 0; testlen(Min, L) = N :- list.length(L, N0), - ( N0 >= Min -> + ( if N0 >= Min then N = N0 - ; + else error("testlen: N < Min") ). @@ -101,15 +101,15 @@ nodiag(_, _, []). nodiag(B, D, [N | L]) :- NmB = N - B, BmN = B - N, - ( D = NmB -> + ( if D = NmB then event nodiag_fail("N - B", B, N, list.length, list.sort, [N | L]), fail - ; D = BmN -> + else if D = BmN then event nodiag_fail("B - N", B, N, list.length, list.sort, [N | L]), fail - ; + else true ), D1 = D + 1, @@ -137,6 +137,6 @@ print_list_2([X | Xs], !IO) :- Xs = [] ; Xs = [_ | _], - io__write_string(", ", !IO), + io.write_string(", ", !IO), print_list_2(Xs, !IO) ). diff --git a/tests/debugger/tabled_read.m b/tests/debugger/tabled_read.m index 4adbb60a9..0e3795516 100644 --- a/tests/debugger/tabled_read.m +++ b/tests/debugger/tabled_read.m @@ -19,10 +19,10 @@ main(!IO) :- tabled_read.open_input("tabled_read.data", Res, Stream, !IO), - ( Res = 0 -> + ( if Res = 0 then tabled_read.part_1(Stream, !IO), tabled_read.part_2(Stream, !IO) - ; + else io.write_string("could not open tabled_read.data\n", !IO) ). @@ -45,13 +45,13 @@ tabled_read.part_2(Stream, !IO) :- tabled_read.test(Stream, SoFar, N, !IO) :- tabled_read.read_char_code(Stream, CharCode, !IO), - ( + ( if char.to_int(Char, CharCode), char.is_digit(Char), char.digit_to_int(Char, CharInt) - -> + then tabled_read.test(Stream, SoFar * 10 + CharInt, N, !IO) - ; + else N = SoFar ). @@ -60,13 +60,13 @@ tabled_read.test(Stream, SoFar, N, !IO) :- tabled_read.poly_test(Stream, Unused, SoFar, N, !IO) :- tabled_read.poly_read_char_code(Stream, Unused, CharCode, !IO), - ( + ( if char.to_int(Char, CharCode), char.is_digit(Char), char.digit_to_int(Char, CharInt) - -> + then tabled_read.poly_test(Stream, Unused, SoFar * 10 + CharInt, N, !IO) - ; + else N = SoFar ). diff --git a/tests/debugger/tabled_read_decl.m b/tests/debugger/tabled_read_decl.m index 0e6e6c5cd..3f3260570 100644 --- a/tests/debugger/tabled_read_decl.m +++ b/tests/debugger/tabled_read_decl.m @@ -11,7 +11,7 @@ :- import_module io. -:- pred main(io__state, io__state). +:- pred main(io, io). :- mode main(di, uo) is det. :- implementation. @@ -20,68 +20,67 @@ :- import_module int. :- import_module list. -main --> - tabled_read_decl__open_input("tabled_read_decl.data", Res, Stream), - ( { Res = 0 } -> - tabled_read_decl__part_1(Stream), - tabled_read_decl__part_2(Stream) - ; - io__write_string("could not open tabled_read.data\n") +main(!IO) :- + tabled_read_decl.open_input("tabled_read_decl.data", Res, Stream, !IO), + ( if Res = 0 then + tabled_read_decl.part_1(Stream, !IO), + tabled_read_decl.part_2(Stream, !IO) + else + io.write_string("could not open tabled_read.data\n", !IO) ). -:- pred tabled_read_decl__part_1(c_pointer::in, io::di, io::uo) is det. +:- pred tabled_read_decl.part_1(c_pointer::in, io::di, io::uo) is det. -tabled_read_decl__part_1(Stream) --> - tabled_read_decl__test(Stream, 0, A), - tabled_read_decl__write_int(A), - tabled_read_decl__poly_test(Stream, ['a', 'b', 'c'], 0, B), - tabled_read_decl__write_int(B). +tabled_read_decl.part_1(Stream, !IO) :- + tabled_read_decl.test(Stream, 0, A, !IO), + tabled_read_decl.write_int(A, !IO), + tabled_read_decl.poly_test(Stream, ['a', 'b', 'c'], 0, B, !IO), + tabled_read_decl.write_int(B, !IO). -:- pred tabled_read_decl__part_2(c_pointer::in, io::di, io::uo) is det. +:- pred tabled_read_decl.part_2(c_pointer::in, io::di, io::uo) is det. -tabled_read_decl__part_2(Stream) --> - tabled_read_decl__test(Stream, 0, A), - tabled_read_decl__write_int(A). +tabled_read_decl.part_2(Stream, !IO) :- + tabled_read_decl.test(Stream, 0, A, !IO), + tabled_read_decl.write_int(A, !IO). -:- pred tabled_read_decl__test(c_pointer::in, int::in, int::out, - io__state::di, io__state::uo) is det. - -tabled_read_decl__test(Stream, SoFar, N) --> - tabled_read_decl__read_char_code(Stream, CharCode), - ( - { char__to_int(Char, CharCode) }, - { char__is_digit(Char) }, - { char__digit_to_int(Char, CharInt) } - -> - tabled_read_decl__test(Stream, SoFar * 10 + CharInt, N) - ; - { N = SoFar } - ). - -:- pred tabled_read_decl__poly_test(c_pointer::in, T::in, int::in, int::out, +:- pred tabled_read_decl.test(c_pointer::in, int::in, int::out, io::di, io::uo) is det. -tabled_read_decl__poly_test(Stream, Unused, SoFar, N) --> - tabled_read_decl__poly_read_char_code(Stream, Unused, CharCode), - ( - { char__to_int(Char, CharCode) }, - { char__is_digit(Char) }, - { char__digit_to_int(Char, CharInt) } - -> - tabled_read_decl__poly_test(Stream, Unused, - SoFar * 10 + CharInt, N) - ; - { N = SoFar } +tabled_read_decl.test(Stream, SoFar, N, !IO) :- + tabled_read_decl.read_char_code(Stream, CharCode, !IO), + ( if + char.to_int(Char, CharCode), + char.is_digit(Char), + char.decimal_digit_to_int(Char, CharInt) + then + tabled_read_decl.test(Stream, SoFar * 10 + CharInt, N, !IO) + else + N = SoFar + ). + +:- pred tabled_read_decl.poly_test(c_pointer::in, T::in, int::in, int::out, + io::di, io::uo) is det. + +tabled_read_decl.poly_test(Stream, Unused, SoFar, N, !IO) :- + tabled_read_decl.poly_read_char_code(Stream, Unused, CharCode, !IO), + ( if + char.to_int(Char, CharCode), + char.is_digit(Char), + char.decimal_digit_to_int(Char, CharInt) + then + tabled_read_decl.poly_test(Stream, Unused, SoFar * 10 + CharInt, + N, !IO) + else + N = SoFar ). :- pragma foreign_decl("C", "#include "). -:- pred tabled_read_decl__open_input(string::in, int::out, c_pointer::out, +:- pred open_input(string::in, int::out, c_pointer::out, io::di, io::uo) is det. :- pragma foreign_proc("C", - tabled_read_decl__open_input(FileName::in, Res::out, Stream::out, - IO0::di, IO::uo), + open_input(FileName::in, Res::out, Stream::out, IO0::di, IO::uo), [will_not_call_mercury, promise_pure, tabled_for_io], " Stream = (MR_Word) fopen((const char *) FileName, ""r""); @@ -89,24 +88,23 @@ tabled_read_decl__poly_test(Stream, Unused, SoFar, N) --> IO = IO0; "). -:- pred tabled_read_decl__read_char_code(c_pointer::in, int::out, +:- pred read_char_code(c_pointer::in, int::out, io::di, io::uo) is det. :- pragma foreign_proc("C", - tabled_read_decl__read_char_code(Stream::in, CharCode::out, - IO0::di, IO::uo), + read_char_code(Stream::in, CharCode::out, IO0::di, IO::uo), [will_not_call_mercury, promise_pure, tabled_for_io], " CharCode = getc((FILE *) Stream); IO = IO0; "). -:- pred tabled_read_decl__poly_read_char_code(c_pointer::in, T::in, int::out, +:- pred poly_read_char_code(c_pointer::in, T::in, int::out, io::di, io::uo) is det. :- pragma foreign_proc("C", - tabled_read_decl__poly_read_char_code(Stream::in, Unused::in, - CharCode::out, IO0::di, IO::uo), + poly_read_char_code(Stream::in, Unused::in, CharCode::out, + IO0::di, IO::uo), [will_not_call_mercury, promise_pure, tabled_for_io], " /* ignore Unused */ @@ -114,10 +112,10 @@ tabled_read_decl__poly_test(Stream, Unused, SoFar, N) --> IO = IO0; "). -:- pred tabled_read_decl__write_int(int::in, io::di, io::uo) is det. +:- pred write_int(int::in, io::di, io::uo) is det. :- pragma foreign_proc("C", - tabled_read_decl__write_int(N::in, IO0::di, IO::uo), + write_int(N::in, IO0::di, IO::uo), [will_not_call_mercury, promise_pure], "{ printf(""%d\\n"", (int) N); diff --git a/tests/debugger/tabled_read_unitize.exp b/tests/debugger/tabled_read_unitize.exp index c1b606d7f..e25515169 100644 --- a/tests/debugger/tabled_read_unitize.exp +++ b/tests/debugger/tabled_read_unitize.exp @@ -1,4 +1,4 @@ - E1: C1 CALL pred tabled_read_unitize.main/2-0 (det) tabled_read_unitize.m:23 + E1: C1 CALL pred tabled_read_unitize.main/2-0 (det) tabled_read_unitize.m:22 mdb> echo on Command echo enabled. mdb> register --quiet diff --git a/tests/debugger/tabled_read_unitize.m b/tests/debugger/tabled_read_unitize.m index 361dba74b..09a6d68fd 100644 --- a/tests/debugger/tabled_read_unitize.m +++ b/tests/debugger/tabled_read_unitize.m @@ -11,8 +11,7 @@ :- import_module io. -:- pred main(io__state, io__state). -:- mode main(di, uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. @@ -20,50 +19,47 @@ :- import_module char. :- import_module int. -main --> - tabled_read_unitize__open_input("tabled_read_unitize.data", Res, - Stream), - ( { Res = 0 } -> - tabled_read_unitize__read_num(Stream, A), - tabled_read_unitize__unitize(Stream, B), - tabled_read_unitize__read_num(Stream, C), - tabled_read_unitize__write_int(A), - tabled_read_unitize__write_int(B), - tabled_read_unitize__write_int(C) - ; - io__write_string("could not open tabled_read_unitize.data\n") +main(!IO) :- + tabled_read_unitize.open_input("tabled_read_unitize.data", Res, Stream, + !IO), + ( if Res = 0 then + tabled_read_unitize.read_num(Stream, A, !IO), + tabled_read_unitize.unitize(Stream, B, !IO), + tabled_read_unitize.read_num(Stream, C, !IO), + tabled_read_unitize.write_int(A, !IO), + tabled_read_unitize.write_int(B, !IO), + tabled_read_unitize.write_int(C, !IO) + else + io.write_string("could not open tabled_read_unitize.data\n", !IO) ). -:- pragma foreign_export("C", tabled_read_unitize__read_num(in, out, di, uo), +:- pragma foreign_export("C", tabled_read_unitize.read_num(in, out, di, uo), "MT_read_num"). -:- pred tabled_read_unitize__read_num(c_pointer::in, int::out, - io__state::di, io__state::uo) is det. +:- pred read_num(c_pointer::in, int::out, io::di, io::uo) is det. -tabled_read_unitize__read_num(Stream, Num) --> - tabled_read_unitize__read_num_2(Stream, 0, Num). +read_num(Stream, Num, !IO) :- + tabled_read_unitize.read_num_2(Stream, 0, Num, !IO). -:- pred tabled_read_unitize__read_num_2(c_pointer::in, int::in, int::out, - io__state::di, io__state::uo) is det. +:- pred read_num_2(c_pointer::in, int::in, int::out, io::di, io::uo) is det. -tabled_read_unitize__read_num_2(Stream, SoFar, N) --> - tabled_read_unitize__read_char_code(Stream, CharCode), - ( - { char__to_int(Char, CharCode) }, - { char__is_digit(Char) }, - { char__digit_to_int(Char, CharInt) } - -> - tabled_read_unitize__read_num_2(Stream, SoFar * 10 + CharInt, - N) - ; - { N = SoFar } +read_num_2(Stream, SoFar, N, !IO) :- + tabled_read_unitize.read_char_code(Stream, CharCode, !IO), + ( if + char.to_int(Char, CharCode), + char.is_digit(Char), + char.decimal_digit_to_int(Char, CharInt) + then + tabled_read_unitize.read_num_2(Stream, SoFar * 10 + CharInt, N, !IO) + else + N = SoFar ). -:- pred tabled_read_unitize__unitize(c_pointer::in, int::out, - io__state::di, io__state::uo) is det. +:- pred tabled_read_unitize.unitize(c_pointer::in, int::out, + io::di, io::uo) is det. :- pragma foreign_proc("C", - tabled_read_unitize__unitize(Stream::in, N::out, _IO0::di, _IO::uo), + tabled_read_unitize.unitize(Stream::in, N::out, _IO0::di, _IO::uo), [may_call_mercury, promise_pure, tabled_for_io_unitize, % This needs to be declared as thread safe, otherwise it deadlocks % in `.par' grades, since it acquires the global lock and then @@ -80,12 +76,11 @@ tabled_read_unitize__read_num_2(Stream, SoFar, N) --> :- pragma foreign_decl("C", "#include "). -:- pred tabled_read_unitize__open_input(string::in, int::out, c_pointer::out, - io__state::di, io__state::uo) is det. +:- pred open_input(string::in, int::out, c_pointer::out, + io::di, io::uo) is det. :- pragma foreign_proc("C", - tabled_read_unitize__open_input(FileName::in, Res::out, Stream::out, - IO0::di, IO::uo), + open_input(FileName::in, Res::out, Stream::out, IO0::di, IO::uo), [will_not_call_mercury, promise_pure, tabled_for_io], " Stream = (MR_Word) fopen((const char *) FileName, ""r""); @@ -93,24 +88,23 @@ tabled_read_unitize__read_num_2(Stream, SoFar, N) --> IO = IO0; "). -:- pred tabled_read_unitize__read_char_code(c_pointer::in, int::out, - io__state::di, io__state::uo) is det. +:- pred tabled_read_unitize.read_char_code(c_pointer::in, int::out, + io::di, io::uo) is det. :- pragma foreign_proc("C", - tabled_read_unitize__read_char_code(Stream::in, CharCode::out, - IO0::di, IO::uo), + read_char_code(Stream::in, CharCode::out, IO0::di, IO::uo), [will_not_call_mercury, promise_pure, tabled_for_io], " CharCode = getc((FILE *) Stream); IO = IO0; "). -:- pred tabled_read_unitize__poly_read_char_code(c_pointer::in, T::in, int::out, - io__state::di, io__state::uo) is det. +:- pred poly_read_char_code(c_pointer::in, T::in, int::out, + io::di, io::uo) is det. :- pragma foreign_proc("C", - tabled_read_unitize__poly_read_char_code(Stream::in, Unused::in, - CharCode::out, IO0::di, IO::uo), + poly_read_char_code(Stream::in, Unused::in, CharCode::out, + IO0::di, IO::uo), [will_not_call_mercury, promise_pure, tabled_for_io], " /* ignore Unused */ @@ -118,11 +112,10 @@ tabled_read_unitize__read_num_2(Stream, SoFar, N) --> IO = IO0; "). -:- pred tabled_read_unitize__write_int(int::in, io__state::di, io__state::uo) - is det. +:- pred write_int(int::in, io::di, io::uo) is det. :- pragma foreign_proc("C", - tabled_read_unitize__write_int(N::in, IO0::di, IO::uo), + write_int(N::in, IO0::di, IO::uo), [will_not_call_mercury, promise_pure], "{ printf(""%d\\n"", (int) N); diff --git a/tests/debugger/tailrec1.m b/tests/debugger/tailrec1.m index 8c901fb38..c7ae50023 100644 --- a/tests/debugger/tailrec1.m +++ b/tests/debugger/tailrec1.m @@ -37,9 +37,9 @@ main(!IO) :- tailrec1_read_strings(Stream, !Words, !IO) :- tailrec1_read_line(Stream, Word, !IO), - ( Word = "" -> + ( if Word = "" then true - ; + else !:Words = [Word | !.Words], tailrec1_read_strings(Stream, !Words, !IO) ). diff --git a/tests/debugger/type_desc_test.m b/tests/debugger/type_desc_test.m index 7136ab63e..a898b1f5b 100644 --- a/tests/debugger/type_desc_test.m +++ b/tests/debugger/type_desc_test.m @@ -16,28 +16,28 @@ :- interface. :- import_module io. -:- pred main(io__state::di, state::uo) is det. +:- pred main(io::di, io::uo) is det. :- implementation. :- import_module list. :- import_module type_desc. -main --> - test([1, 2]), - test(["one", "two", "three"]). +main(!IO) :- + test([1, 2], !IO), + test(["one", "two", "three"], !IO). -:- pred test(T::in, io__state::di, io__state::uo) is det. +:- pred test(T::in, io::di, io::uo) is det. -test(Val) --> - { TypeDesc = get_type_desc(Val) }, - io__write_string("type_desc: "), - io__write(TypeDesc), - io__nl, - { TypeCtorDesc = get_type_ctor_desc(TypeDesc) }, - io__write_string("type_ctor_desc: "), - io__write(TypeCtorDesc), - io__nl. +test(Val, !IO) :- + TypeDesc = get_type_desc(Val), + io.write_string("type_desc: ", !IO), + io.write(TypeDesc, !IO), + io.nl(!IO), + TypeCtorDesc = get_type_ctor_desc(TypeDesc), + io.write_string("type_ctor_desc: ", !IO), + io.write(TypeCtorDesc, !IO), + io.nl(!IO). :- func get_type_desc(T) = type_desc. diff --git a/tests/debugger/uci.m b/tests/debugger/uci.m index bcdcfd640..f6058fb20 100644 --- a/tests/debugger/uci.m +++ b/tests/debugger/uci.m @@ -21,66 +21,66 @@ main(!IO) :- test([], RevResults), - list__reverse(RevResults, Results), - string__append_list(Results, ResultString), - io__write_string(ResultString, !IO). + list.reverse(RevResults, Results), + string.append_list(Results, ResultString), + io.write_string(ResultString, !IO). :- pred test(list(string)::in, list(string)::out) is det. test(!Res) :- - ( compare((<), ma0, mb0) -> + ( if compare((<), ma0, mb0) then add_res("0 lt\n", !Res) - ; + else add_res("0 ge\n", !Res) ), - ( compare((<), mb1, ma1) -> + ( if compare((<), mb1, ma1) then add_res("1 lt\n", !Res) - ; + else add_res("1 ge\n", !Res) ), - ( compare((<), ma2, ma2) -> + ( if compare((<), ma2, ma2) then add_res("2 lt\n", !Res) - ; + else add_res("2 ge\n", !Res) ), - ( compare((<), mb3, ma3) -> + ( if compare((<), mb3, ma3) then add_res("3 lt\n", !Res) - ; + else add_res("3 ge\n", !Res) ), - ( compare((<), ma4, mb4) -> + ( if compare((<), ma4, mb4) then add_res("4 lt\n", !Res) - ; + else add_res("4 ge\n", !Res) ), - ( unify(ma0, mb0) -> + ( if unify(ma0, mb0) then add_res("0 eq\n", !Res) - ; + else add_res("0 ne\n", !Res) ), - ( unify(ma1, ma1) -> + ( if unify(ma1, ma1) then add_res("1 eq\n", !Res) - ; + else add_res("1 ne\n", !Res) ), - ( unify(ma2, mb2) -> + ( if unify(ma2, mb2) then add_res("2 eq\n", !Res) - ; + else add_res("2 ne\n", !Res) ), - ( unify(mb3, mb3) -> + ( if unify(mb3, mb3) then add_res("3 eq\n", !Res) - ; + else add_res("3 ne\n", !Res) ), - ( unify(ma4, mb4) -> + ( if unify(ma4, mb4) then add_res("4 eq\n", !Res) - ; + else add_res("4 ne\n", !Res) ), - ( compare((<), mai, mbi) -> + ( if compare((<), mai, mbi) then add_res("i lt\n", !Res) - ; + else add_res("i ge\n", !Res) ). diff --git a/tests/debugger/uci_index.m b/tests/debugger/uci_index.m index 437f0d00a..5a229a7f1 100644 --- a/tests/debugger/uci_index.m +++ b/tests/debugger/uci_index.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module uci_index. :- interface. diff --git a/tests/debugger/user_event.m b/tests/debugger/user_event.m index 3598ff1fc..ee0a942c8 100644 --- a/tests/debugger/user_event.m +++ b/tests/debugger/user_event.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module user_event. :- interface. @@ -19,9 +19,9 @@ main(!IO) :- data(Data), - ( queen(Data, Out) -> + ( if queen(Data, Out) then print_list(Out, !IO) - ; + else io.write_string("No solution\n", !IO) ). @@ -64,13 +64,13 @@ nodiag(_, _, []). nodiag(B, D, [N | L]) :- NmB = N - B, BmN = B - N, - ( D = NmB -> + ( if D = NmB then event nodiag_fail("N - B", B, N, [N | L]), fail - ; D = BmN -> + else if D = BmN then event nodiag_fail("B - N", B, N, [N | L]), fail - ; + else true ), D1 = D + 1, @@ -98,6 +98,6 @@ print_list_2([X | Xs], !IO) :- Xs = [] ; Xs = [_ | _], - io__write_string(", ", !IO), + io.write_string(", ", !IO), print_list_2(Xs, !IO) ). diff --git a/tests/debugger/user_event_2.m b/tests/debugger/user_event_2.m index 7afddb984..d2d1c1338 100644 --- a/tests/debugger/user_event_2.m +++ b/tests/debugger/user_event_2.m @@ -1,7 +1,7 @@ %---------------------------------------------------------------------------% % vim: ts=4 sw=4 et ft=mercury %---------------------------------------------------------------------------% -% + :- module user_event_2. :- interface. :- import_module io. diff --git a/tests/debugger/user_event_shallow.m b/tests/debugger/user_event_shallow.m index ec19ed500..44d6117e3 100644 --- a/tests/debugger/user_event_shallow.m +++ b/tests/debugger/user_event_shallow.m @@ -19,9 +19,9 @@ main(!IO) :- data(Data), - ( queen(Data, Out) -> + ( if queen(Data, Out) then print_list(Out, !IO) - ; + else io.write_string("No solution\n", !IO) ). @@ -64,13 +64,13 @@ nodiag(_, _, []). nodiag(B, D, [N | L]) :- NmB = N - B, BmN = B - N, - ( D = NmB -> + ( if D = NmB then event nodiag_fail("N - B", B, N, [N | L]), fail - ; D = BmN -> + else if D = BmN then event nodiag_fail("B - N", B, N, [N | L]), fail - ; + else true ), D1 = D + 1, @@ -98,6 +98,6 @@ print_list_2([X | Xs], !IO) :- Xs = [] ; Xs = [_ | _], - io__write_string(", ", !IO), + io.write_string(", ", !IO), print_list_2(Xs, !IO) ).