[m-dev.] diff: distinguish preds and funcs in the declarative debugger
Mark Anthony BROWN
dougl at cs.mu.OZ.AU
Sun Oct 1 14:09:40 AEDT 2000
Estimated hours taken: 2.5
Distinguish between predicates and functions in the declarative debugger.
browser/declarative_execution.m:
Add a pred_or_func field to trace_atom.
trace/mercury_trace_declarative.c:
Construct trace atoms with the extra field.
browser/declarative_user.m:
Print function call results using function syntax.
browser/debugger_interface.m:
browser/util.m:
Move the definition of type pred_or_func to util.m, so it can
be used by the declarative debugger as well as the external debugger.
runtime/mercury_stack_layout.h:
Update a reference to the location of type pred_or_func.
tests/debugger/declarative/Mmakefile:
tests/debugger/declarative/func_call.{m,inp,exp}:
Test case for the new feature.
tests/debugger/declarative/*.exp:
tests/debugger/declarative/*.exp2:
Update expected output from tests.
? tests/debugger/declarative/func_call.exp
? tests/debugger/declarative/func_call.m
? tests/debugger/declarative/func_call.inp
Index: browser/debugger_interface.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/debugger_interface.m,v
retrieving revision 1.17
diff -u -r1.17 debugger_interface.m
--- browser/debugger_interface.m 2000/02/04 03:45:26 1.17
+++ browser/debugger_interface.m 2000/10/01 02:48:41
@@ -44,14 +44,6 @@
% encoded as specified in ../runtime/mercury_stack_layout.h
% and ../compiler/stack_layout.m.
-% This enumeration must be EXACTLY the same as the MR_PredFunc enum in
-% runtime/mercury_stack_layout.h, and in the same order, since the code
-% assumes the representation is the same.
-
-:- type pred_or_func
- ---> predicate
- ; function.
-
% Depending whether the Opium side is requesting for a user defined procedure
% or a compiler generated one, the event has not exactly the same structure.
Index: browser/declarative_execution.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_execution.m,v
retrieving revision 1.12
diff -u -r1.12 declarative_execution.m
--- browser/declarative_execution.m 2000/08/10 05:50:56 1.12
+++ browser/declarative_execution.m 2000/10/01 02:48:50
@@ -105,6 +105,8 @@
:- type trace_atom
---> atom(
+ pred_or_func,
+
% Procedure name.
%
string,
@@ -852,18 +854,19 @@
).
-:- func construct_trace_atom(string, int) = trace_atom.
-:- pragma export(construct_trace_atom(in, in) = out,
+:- func construct_trace_atom(pred_or_func, string, int) = trace_atom.
+:- pragma export(construct_trace_atom(in, in, in) = out,
"MR_DD_construct_trace_atom").
-construct_trace_atom(Functor, Arity) = atom(Functor, Args) :-
+construct_trace_atom(PredOrFunc, Functor, Arity) = Atom :-
+ Atom = atom(PredOrFunc, Functor, Args),
list__duplicate(Arity, no, Args).
:- func add_trace_atom_arg(trace_atom, int, univ) = trace_atom.
:- pragma export(add_trace_atom_arg(in, in, in) = out,
"MR_DD_add_trace_atom_arg").
-add_trace_atom_arg(atom(F, Args0), Num, Val) = atom(F, Args) :-
+add_trace_atom_arg(atom(C, F, Args0), Num, Val) = atom(C, F, Args) :-
list__replace_nth_det(Args0, Num, yes(Val), Args).
%-----------------------------------------------------------------------------%
Index: browser/declarative_user.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/declarative_user.m,v
retrieving revision 1.10
diff -u -r1.10 declarative_user.m
--- browser/declarative_user.m 2000/08/17 08:06:56 1.10
+++ browser/declarative_user.m 2000/10/01 02:48:56
@@ -156,7 +156,7 @@
:- mode browse_atom_argument(in, in, in, out, di, uo) is det.
browse_atom_argument(Atom, ArgNum, User0, User) -->
- { Atom = atom(_, Args) },
+ { Atom = atom(_, _, Args) },
(
{ list__index1(Args, ArgNum, MaybeArg) },
{ MaybeArg = yes(Arg) }
@@ -385,7 +385,7 @@
:- pred check_decl_atom_size(string, decl_atom).
:- mode check_decl_atom_size(in, in) is semidet.
-check_decl_atom_size(Indent, atom(Functor, Args)) :-
+check_decl_atom_size(Indent, atom(_, Functor, Args)) :-
decl_atom_size_limit(RemSize0),
string__length(Indent, I),
string__length(Functor, F),
@@ -413,11 +413,21 @@
:- pred write_decl_atom_limited(decl_atom, user_state, io__state, io__state).
:- mode write_decl_atom_limited(in, in, di, uo) is det.
-write_decl_atom_limited(atom(Functor, Args), User) -->
+write_decl_atom_limited(atom(PredOrFunc, Functor, Args), User) -->
+ write_decl_atom_category(User^outstr, PredOrFunc),
io__write_string(User^outstr, Functor),
io__nl(User^outstr),
foldl(print_decl_atom_arg(User), Args).
+:- pred write_decl_atom_category(io__output_stream, pred_or_func, io__state,
+ io__state).
+:- mode write_decl_atom_category(in, in, di, uo) is det.
+
+write_decl_atom_category(OutStr, predicate) -->
+ io__write_string(OutStr, "pred ").
+write_decl_atom_category(OutStr, function) -->
+ io__write_string(OutStr, "func ").
+
:- pred print_decl_atom_arg(user_state, maybe(univ), io__state, io__state).
:- mode print_decl_atom_arg(in, in, di, uo) is det.
@@ -431,30 +441,30 @@
io__state, io__state).
:- mode write_decl_atom_direct(in, in, di, uo) is det.
-write_decl_atom_direct(OutStr, atom(Functor, Args)) -->
+write_decl_atom_direct(OutStr, atom(PredOrFunc, Functor, Args)) -->
io__write_string(OutStr, Functor),
(
{ Args = [] }
;
- { Args = [Arg | Args0] },
+ { Args = [FirstArg | ArgsRest] },
io__write_char(OutStr, '('),
- write_decl_atom_arg(OutStr, Arg),
- write_decl_atom_args(OutStr, Args0),
- io__write_char(OutStr, ')')
+ (
+ { PredOrFunc = predicate },
+ io__write_list(OutStr, Args, ", ",
+ write_decl_atom_arg(OutStr)),
+ io__write_char(OutStr, ')')
+ ;
+ { PredOrFunc = function },
+ { get_inputs_and_result(FirstArg, ArgsRest, Inputs,
+ Result) },
+ io__write_list(OutStr, Inputs, ", ",
+ write_decl_atom_arg(OutStr)),
+ io__write_string(OutStr, ") = "),
+ write_decl_atom_arg(OutStr, Result)
+ )
),
io__nl(OutStr).
-:- pred write_decl_atom_args(io__output_stream, list(maybe(univ)),
- io__state, io__state).
-:- mode write_decl_atom_args(in, in, di, uo) is det.
-
-write_decl_atom_args(_, []) -->
- [].
-write_decl_atom_args(OutStr, [Arg | Args]) -->
- io__write_string(OutStr, ", "),
- write_decl_atom_arg(OutStr, Arg),
- write_decl_atom_args(OutStr, Args).
-
:- pred write_decl_atom_arg(io__output_stream, maybe(univ),
io__state, io__state).
:- mode write_decl_atom_arg(in, in, di, uo) is det.
@@ -463,4 +473,11 @@
io__print(OutStr, Arg).
write_decl_atom_arg(OutStr, no) -->
io__write_char(OutStr, '_').
+
+:- pred get_inputs_and_result(T, list(T), list(T), T).
+:- mode get_inputs_and_result(in, in, out, out) is det.
+
+get_inputs_and_result(A, [], [], A).
+get_inputs_and_result(A1, [A2 | As], [A1 | Inputs0], Result) :-
+ get_inputs_and_result(A2, As, Inputs0, Result).
Index: browser/util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/util.m,v
retrieving revision 1.10
diff -u -r1.10 util.m
--- browser/util.m 2000/08/26 17:47:02 1.10
+++ browser/util.m 2000/10/01 02:48:57
@@ -34,6 +34,14 @@
; nondet_pragma_later
.
+% This enumeration must be EXACTLY the same as the MR_PredFunc enum in
+% runtime/mercury_stack_layout.h, and in the same order, since the code
+% assumes the representation is the same.
+
+:- type pred_or_func
+ ---> predicate
+ ; function.
+
:- type goal_path_string == string.
% Get user input via the same method used by the internal
Index: runtime/mercury_stack_layout.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stack_layout.h,v
retrieving revision 1.38
diff -u -r1.38 mercury_stack_layout.h
--- runtime/mercury_stack_layout.h 2000/09/22 06:00:02 1.38
+++ runtime/mercury_stack_layout.h 2000/10/01 02:49:44
@@ -22,7 +22,7 @@
/*-------------------------------------------------------------------------*/
/*
** Definitions for MR_PredFunc. This enum should EXACTLY match the definition
-** of the `pred_or_func' type in browser/debugger_interface.
+** of the `pred_or_func' type in browser/util.m.
*/
typedef enum { MR_PREDICATE, MR_FUNCTION } MR_PredFunc;
Index: tests/debugger/declarative/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/Mmakefile,v
retrieving revision 1.19
diff -u -r1.19 Mmakefile
--- tests/debugger/declarative/Mmakefile 2000/09/27 05:23:36 1.19
+++ tests/debugger/declarative/Mmakefile 2000/10/01 02:49:48
@@ -25,6 +25,7 @@
big \
comp_gen \
filter \
+ func_call \
gcf \
if_then_else \
lpe_example \
@@ -110,6 +111,9 @@
filter.out: filter filter.inp
$(MDB) ./filter < filter.inp > filter.out 2>&1
+
+func_call.out: func_call func_call.inp
+ $(MDB) ./func_call < func_call.inp > func_call.out 2>&1
gcf.out: gcf gcf.inp
$(MDB) ./gcf < gcf.inp > gcf.out 2>&1
Index: tests/debugger/declarative/app.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/app.exp,v
retrieving revision 1.9
diff -u -r1.9 app.exp
--- tests/debugger/declarative/app.exp 2000/08/18 10:59:34 1.9
+++ tests/debugger/declarative/app.exp 2000/10/01 02:49:49
@@ -26,23 +26,23 @@
mdb> continue
19: 2 2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:13)
mdb> dd
-app
+pred app
[1, 2, 3, 4, 5]
[6, 7, 8]
[1, 2, 3, 4, 5, 6, 7, 8]
Valid? no
-app
+pred app
[2, 3, 4, 5]
[6, 7, 8]
[2, 3, 4, 5, 6, 7, 8]
Valid? no
-app
+pred app
[3, 4, 5]
[6, 7, 8]
[3, 4, 5, 6, 7, 8]
Valid? no
Found incorrect contour:
-app
+pred app
[3, 4, 5]
[6, 7, 8]
[3, 4, 5, 6, 7, 8]
@@ -58,58 +58,58 @@
mdb> finish -n
67: 8 2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:18)
mdb> dd
-app
+pred app
.(1, .(2, .(3, ./2)))
[6, 7, 8]
.(1, .(2, .(3, ./2)))
Valid? no
-app
+pred app
.(2, .(3, .(4, ./2)))
[6, 7, 8]
.(2, .(3, .(4, ./2)))
Valid? no
-app
+pred app
.(3, .(4, .(5, ./2)))
[6, 7, 8]
.(3, .(4, .(5, ./2)))
Valid? no
-app
+pred app
.(4, .(5, .(6, ./2)))
[6, 7, 8]
.(4, .(5, .(6, ./2)))
Valid? no
-app
+pred app
.(5, .(6, .(7, ./2)))
[6, 7, 8]
.(5, .(6, .(7, ./2)))
Valid? no
-app
+pred app
.(6, .(7, .(8, ./2)))
[6, 7, 8]
.(6, .(7, .(8, ./2)))
Valid? no
-app
+pred app
[7, 8, 9, 0, 1, 2, 3, 4, 5]
[6, 7, 8]
.(7, .(8, .(9, ./2)))
Valid? no
-app
+pred app
[8, 9, 0, 1, 2, 3, 4, 5]
[6, 7, 8]
.(8, .(9, .(0, ./2)))
Valid? no
-app
+pred app
[9, 0, 1, 2, 3, 4, 5]
[6, 7, 8]
.(9, .(0, .(1, ./2)))
Valid? no
-app
+pred app
[0, 1, 2, 3, 4, 5]
[6, 7, 8]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
Valid? no
Found incorrect contour:
-app
+pred app
[3, 4, 5]
[6, 7, 8]
[3, 4, 5, 6, 7, 8]
Index: tests/debugger/declarative/app.exp2
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/app.exp2,v
retrieving revision 1.9
diff -u -r1.9 app.exp2
--- tests/debugger/declarative/app.exp2 2000/08/18 10:59:35 1.9
+++ tests/debugger/declarative/app.exp2 2000/10/01 02:49:50
@@ -26,23 +26,23 @@
mdb> continue
19: 2 2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:13)
mdb> dd
-app
+pred app
[1, 2, 3, 4, 5]
[6, 7, 8]
[1, 2, 3, 4, 5, 6, 7, 8]
Valid? no
-app
+pred app
[2, 3, 4, 5]
[6, 7, 8]
[2, 3, 4, 5, 6, 7, 8]
Valid? no
-app
+pred app
[3, 4, 5]
[6, 7, 8]
[3, 4, 5, 6, 7, 8]
Valid? no
Found incorrect contour:
-app
+pred app
[3, 4, 5]
[6, 7, 8]
[3, 4, 5, 6, 7, 8]
@@ -58,58 +58,58 @@
mdb> finish -n
71: 10 2 EXIT pred app:app/3-0 (det) app.m:26 (app.m:18)
mdb> dd
-app
+pred app
.(1, .(2, .(3, ./2)))
[6, 7, 8]
.(1, .(2, .(3, ./2)))
Valid? no
-app
+pred app
.(2, .(3, .(4, ./2)))
[6, 7, 8]
.(2, .(3, .(4, ./2)))
Valid? no
-app
+pred app
.(3, .(4, .(5, ./2)))
[6, 7, 8]
.(3, .(4, .(5, ./2)))
Valid? no
-app
+pred app
.(4, .(5, .(6, ./2)))
[6, 7, 8]
.(4, .(5, .(6, ./2)))
Valid? no
-app
+pred app
.(5, .(6, .(7, ./2)))
[6, 7, 8]
.(5, .(6, .(7, ./2)))
Valid? no
-app
+pred app
.(6, .(7, .(8, ./2)))
[6, 7, 8]
.(6, .(7, .(8, ./2)))
Valid? no
-app
+pred app
[7, 8, 9, 0, 1, 2, 3, 4, 5]
[6, 7, 8]
.(7, .(8, .(9, ./2)))
Valid? no
-app
+pred app
[8, 9, 0, 1, 2, 3, 4, 5]
[6, 7, 8]
.(8, .(9, .(0, ./2)))
Valid? no
-app
+pred app
[9, 0, 1, 2, 3, 4, 5]
[6, 7, 8]
.(9, .(0, .(1, ./2)))
Valid? no
-app
+pred app
[0, 1, 2, 3, 4, 5]
[6, 7, 8]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
Valid? no
Found incorrect contour:
-app
+pred app
[3, 4, 5]
[6, 7, 8]
[3, 4, 5, 6, 7, 8]
Index: tests/debugger/declarative/filter.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/filter.exp,v
retrieving revision 1.3
diff -u -r1.3 filter.exp
--- tests/debugger/declarative/filter.exp 2000/08/18 10:59:36 1.3
+++ tests/debugger/declarative/filter.exp 2000/10/01 02:49:51
@@ -58,7 +58,7 @@
mdb> dd
p([1, 2, 3, 7, 8, 9])
Valid? no
-my_append
+pred my_append
[1, 2, 3]
[7, 8, 9]
[1, 2, 3, 7, 8, 9]
Index: tests/debugger/declarative/filter.exp2
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/declarative/filter.exp2,v
retrieving revision 1.3
diff -u -r1.3 filter.exp2
--- tests/debugger/declarative/filter.exp2 2000/08/18 10:59:36 1.3
+++ tests/debugger/declarative/filter.exp2 2000/10/01 02:49:51
@@ -58,7 +58,7 @@
mdb> dd
p([1, 2, 3, 7, 8, 9])
Valid? no
-my_append
+pred my_append
[1, 2, 3]
[7, 8, 9]
[1, 2, 3, 7, 8, 9]
Index: trace/mercury_trace_declarative.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_declarative.c,v
retrieving revision 1.29
diff -u -r1.29 mercury_trace_declarative.c
--- trace/mercury_trace_declarative.c 2000/08/18 03:04:17 1.29
+++ trace/mercury_trace_declarative.c 2000/10/01 02:50:23
@@ -584,7 +584,7 @@
#endif
MR_TRACE_CALL_MERCURY(
- redo = MR_DD_call_node_get_last_interface( (MR_Word) call);
+ redo = MR_DD_call_node_get_last_interface((MR_Word) call);
node = (MR_Trace_Node) MR_DD_construct_fail_node(
(MR_Word) prev, (MR_Word) call,
(MR_Word) redo,
@@ -1023,6 +1023,7 @@
MR_decl_make_atom(const MR_Stack_Layout_Label *layout, MR_Word *saved_regs,
MR_Trace_Port port)
{
+ MR_PredFunc pred_or_func;
MR_ConstString name;
MR_Word arity;
MR_Word atom;
@@ -1037,11 +1038,15 @@
name = MR_decl_atom_name(entry);
if (MR_ENTRY_LAYOUT_COMPILER_GENERATED(layout->MR_sll_entry)) {
arity = entry->MR_sle_comp.MR_comp_arity;
+ pred_or_func = MR_PREDICATE;
} else {
arity = entry->MR_sle_user.MR_user_arity;
+ pred_or_func = entry->MR_sle_user.MR_user_pred_or_func;
}
MR_TRACE_CALL_MERCURY(
- atom = MR_DD_construct_trace_atom((MR_String) name,
+ atom = MR_DD_construct_trace_atom(
+ (MR_Word) pred_or_func,
+ (MR_String) name,
(MR_Word) arity);
);
New file tests/debugger/declarative/func_call.m:
:- module func_call.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.
:- implementation.
:- import_module int.
main -->
io__write_int(fib(6)),
io__nl.
:- func fib(int) = int.
fib(N) =
(
N =< 1
->
1
;
fib(N - 1) +
fib(N - 3) % Oops.
).
New file tests/debugger/declarative/func_call.inp:
echo on
register --quiet
break fib
continue
finish -n
dd
no
no
no
yes
yes
yes
quit -y
New file tests/debugger/declarative/func_call.exp:
1: 1 1 CALL pred func_call:main/2-0 (det) func_call.m:8
mdb> echo on
Command echo enabled.
mdb> register --quiet
mdb> break fib
0: + stop interface func func_call:fib/2-0 (det)
mdb> continue
2: 2 2 CALL func func_call:fib/2-0 (det) func_call.m:14 (func_call.m:9)
mdb> finish -n
69: 2 2 EXIT func func_call:fib/2-0 (det) func_call.m:14 (func_call.m:9)
mdb> dd
fib(6) = 9
Valid? no
fib(5) = 6
Valid? no
fib(4) = 4
Valid? no
fib(3) = 3
Valid? yes
fib(1) = 1
Valid? yes
Found incorrect contour:
fib(4) = 4
Is this a bug? yes
35: 4 4 EXIT func func_call:fib/2-0 (det) func_call.m:14 (func_call.m:20)
mdb> quit -y
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list