mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 14:25:56 +00:00
Estimated hours taken: 160
Implement a new data structure for declarative debugging. The
major differences between this and the old implementation are:
- The data structure is implemented in Mercury. The definition
of the type, and procedures for constructing values of that
type, have been moved from trace/mercury_trace_declarative.{c,h}
to browser/declarative_execution.m (which is a new module).
- The front end no longer needs to call the back end via an
indirect pointer---the front end does not call the back end at
all.
- The data structure is not specifically for wrong answer
analysis, it is intended to be used for any sort of analysis.
- The data structure represents execution at a lower level---the
new front end defines a more abstract view in terms of this
data structure.
Implement a test harness for debugging the front end code. This allows
the front end to run as a stand-alone program, which can then be
debugged using `mdb'.
The code in the front end does not currently handle the new structure
very nicely. This is because that code is about to undergo some major
structural changes, so there is little point cleaning it up now.
Consequently:
- Some of the code in the front end is incorrect (eg. the
user interface does not print missing answer nodes
properly).
- The tests have not been reinstated.
These things will be fixed in subsequent changes.
Likewise the compiler still reserves two stack slots, even though
only one is required. After this change the algorithm should be able
to get away with using no stack slots, so modifications to the compiler
will be postponed until then.
browser/declarative_execution.m:
New module. Implement the execution_tree typeclass, which
represents the execution of a Mercury program. Implement
two instances of this typeclass, one for normal use and one for
testing purposes.
browser/declarative_test.m:
New module. A test harness that can be compiled as a
stand-alone program, enabling the front end to be debugged.
trace/mercury_trace_declarative.c:
trace/mercury_trace_declarative.h:
- Remove the definition of the old data structure.
- Add some macros which enable the new Mercury data structure
to be destructively updated by C code.
- Change the interface to this module so that it reflects more
general diagnosis, not just wrong answer analysis.
- Implement the new algorithm.
- Call an alternative front end if in test mode.
- Update comments.
trace/mercury_trace_internal.h:
Add a new mode for debugging the declarative debugger.
trace/mercury_trace_internal.c:
Change the command from `dd_wrong' to `dd', since it is not
specifically for wrong answer analysis. Add a new command
`dd_dd' which calls the alternative front end used for testing.
runtime/mercury_init.h:
runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
util/mkinit.c:
Remove any reference to `MR_edt_root_node', since it is no
longer used.
browser/declarative_debugger.m:
- Add a case for missing answer nodes to `edt_node'.
- Change the `evaluation_tree' typeclass into `mercury_edt'
typeclass. This is to make it more distinct from the new
`execution_tree' typeclass, which is a lower level concept.
- New interface to the diagnoser: types `diagnoser_response'
and `diagnoser_state', and procedure `diagnosis'.
- Define an instance of `mercury_edt' from an instance of
`execution_tree'.
- Updates to the analyser to get it to compile---further changes
will be forthcoming.
browser/declarative_user.m:
- Updates to the user interface to get it to compile---further
changes will be forthcoming.
browser/browser_library.m:
Import the new module (declarative_execution.m).
browser/debugger_interface.m:
browser/util.m:
Move the definitions of trace_port_type and goal_path_string
to browser/util.m, since they are now used by more than just
the external debugger.
browser/Mmakefile:
Add the test harness as a `depend' target.
browser/browse_test.m:
Use the correct interface to the browser.
136 lines
3.6 KiB
Mathematica
136 lines
3.6 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1998-1999 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU Library General
|
|
% Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module util.
|
|
|
|
:- interface.
|
|
|
|
:- import_module list, string, io.
|
|
|
|
% The stuff defined below is similar to types goal_path and trace_port
|
|
% defined in modules compiler/hlds_goal.m and compiler/trace.m.
|
|
% This enumeration must be EXACTLY the same as the MR_trace_port enum in
|
|
% runtime/mercury_trace_base.h, and in the same order, since the code
|
|
% assumes the representation is the same.
|
|
|
|
:- type trace_port_type
|
|
---> call
|
|
; exit
|
|
; redo
|
|
; fail
|
|
; ite_cond
|
|
; ite_then
|
|
; ite_else
|
|
; neg_enter
|
|
; neg_success
|
|
; neg_failure
|
|
; disj
|
|
; switch
|
|
; nondet_pragma_first
|
|
; nondet_pragma_later
|
|
; exception
|
|
.
|
|
|
|
:- type goal_path_string == string.
|
|
|
|
% Get user input via the same method used by the internal
|
|
% debugger.
|
|
:- pred util__trace_getline(string, io__result(string), io__state,
|
|
io__state).
|
|
:- mode util__trace_getline(in, out, di, uo) is det.
|
|
|
|
:- pred util__trace_getline(string, io__result(string), io__input_stream,
|
|
io__output_stream, io__state, io__state).
|
|
:- mode util__trace_getline(in, out, in, in, di, uo) is det.
|
|
|
|
:- pred util__zip_with(pred(T1, T2, T3), list(T1), list(T2), list(T3)).
|
|
:- mode util__zip_with(pred(in, in, out) is det, in, in, out) is det.
|
|
|
|
% Apply predicate to argument repeatedly until the result
|
|
% remains the same.
|
|
:- pred util__limit(pred(list(T), list(T)), list(T), list(T)).
|
|
:- mode util__limit(pred(in,out) is det, in, out) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
:- implementation.
|
|
|
|
:- import_module int, require.
|
|
|
|
util__trace_getline(Prompt, Result) -->
|
|
io__input_stream(MdbIn),
|
|
io__output_stream(MdbOut),
|
|
util__trace_getline(Prompt, Result, MdbIn, MdbOut).
|
|
|
|
:- pragma promise_pure(util__trace_getline/6).
|
|
|
|
util__trace_getline(Prompt, Result, MdbIn, MdbOut) -->
|
|
{
|
|
impure call_trace_getline(MdbIn, MdbOut, Prompt, Line)
|
|
->
|
|
Result = ok(Line)
|
|
;
|
|
Result = eof
|
|
}.
|
|
|
|
:- impure pred call_trace_getline(input_stream, output_stream, string, string).
|
|
:- mode call_trace_getline(in, in, in, out) is semidet.
|
|
|
|
:- pragma c_header_code("
|
|
#include ""mercury_wrapper.h""
|
|
#include ""mercury_string.h""
|
|
#include ""mercury_trace_base.h""
|
|
#include ""mercury_trace_internal.h""
|
|
").
|
|
|
|
:- pragma c_code(call_trace_getline(MdbIn::in, MdbOut::in, Prompt::in,
|
|
Line::out),
|
|
[will_not_call_mercury],
|
|
"
|
|
char *line;
|
|
char *mercury_string;
|
|
MercuryFile *mdb_in = (MercuryFile *) MdbIn;
|
|
MercuryFile *mdb_out = (MercuryFile *) MdbOut;
|
|
|
|
if (MR_address_of_trace_getline != NULL) {
|
|
line = (*MR_address_of_trace_getline)((char *) Prompt,
|
|
mdb_in->file, mdb_out->file);
|
|
} else {
|
|
MR_tracing_not_enabled();
|
|
/* not reached */
|
|
}
|
|
|
|
if (line == NULL) {
|
|
SUCCESS_INDICATOR = FALSE;
|
|
} else {
|
|
MR_make_aligned_string_copy(mercury_string, line);
|
|
free(line);
|
|
Line = (String) mercury_string;
|
|
SUCCESS_INDICATOR = TRUE;
|
|
}
|
|
"
|
|
).
|
|
|
|
util__zip_with(Pred, XXs, YYs, Zipped) :-
|
|
( (XXs = [], YYs = []) ->
|
|
Zipped = []
|
|
; (XXs = [X|Xs], YYs = [Y|Ys]) ->
|
|
Pred(X,Y,PXY),
|
|
Zipped = [PXY|Rest],
|
|
util__zip_with(Pred, Xs, Ys, Rest)
|
|
;
|
|
error("zip_with: list arguments are of unequal length")
|
|
).
|
|
|
|
util__limit(Pred, Xs, Ys) :-
|
|
Pred(Xs, Zs),
|
|
( Xs = Zs ->
|
|
Ys = Zs
|
|
;
|
|
util__limit(Pred, Zs, Ys)
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|