mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 22:35:41 +00:00
Estimated hours taken: 6
Branches: main
Print streams sensibly in the debugger.
runtime/mercury_library_types.h:
Define MercuryFilePtr as a shorthand for MercuryFile *.
library/io.m:
Define a user-friendly representation for streams that includes not
just the stream's name but all the info about the stream that user
using mdb may wish to know about the stream, as well as a unique stream
id.
Make the changes required to maintain this improved stream database.
If the program is being executed under mdb, then do not ever delete
items from the stream database, since e.g. the declarative debugger
may need to print the stream's representation even after the stream
is closed. (If executing outside mdb, then we delete a stream's entry
from the stream database when the stream is closed, as before.)
To allow the debugger to detect which variables are I/O streams,
change the stream types from being equivalent to c_pointer (and thus
indistinguishable from other c_pointers) to their own type. Implement
this type as MercuryFilePtr in the C backend. In the IL backend, we
represent it as Object[], the minimum representation change possible.
Use the C type definition to get rid of many casts.
When writing streams, write the user-friendly representation, not
a meaningless <<c_pointer>>.
runtime/mercury_init.h:
runtime/mercury_wrapper.[ch]:
runtime/mercury_layout_util.c:
The change in stream's representation changes the types of some of the
arguments of functions exported to C from io.m; conform to those
changes.
browser/browse.m:
browser/sized_pretty.m:
In each of the mechanisms that the debugger can use to display terms,
pass along the stream name database.
browser/browser_info.m:
When deconstructing terms that are streams, return the stream's
user-friendly id, not a c_pointer.
browser/browse_test.m:
Update this test program to test the new way of printing streams.
runtime/mercury_trace_base.[ch]:
Define the MR_trace_ever_enabled variable to let io.m know whether
it is allowed to ever discard stream info.
runtime/mercury_init.h:
runtime/mercury_wrapper.[ch]:
Update the types of the functions dealing with streams to use
MercuryFilePtr to refer to streams instead of MR_Word. These functions
are implemented by Mercury predicates exported to C.
runtime/mercury_wrapper.c:
Set MR_trace_ever_enabled to true when execution tracing is enabled.
This is the only assigment to MR_trace_ever_enabled after
initialization to the default (false).
tests/debugger/declarative/io_stream_test.{m,inp,exp,exp}:
A new test case to test the debugger's printing of I/O streams.
tests/debugger/declarative/Mmakefile:
Enable the new test case.
72 lines
2.0 KiB
Mathematica
72 lines
2.0 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1998-2000, 2003 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.
|
|
%---------------------------------------------------------------------------%
|
|
|
|
% browse_test - Driver to test the browser.
|
|
%
|
|
% authors: aet
|
|
% stability: low
|
|
|
|
:- module browse_test.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state, io__state).
|
|
:- mode main(di, uo) is cc_multi.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module mdb.
|
|
:- import_module mdb__browse.
|
|
:- import_module mdb__browser_info.
|
|
|
|
:- import_module list, string, int, std_util, tree234, assoc_list.
|
|
|
|
main -->
|
|
{ Filename = "/etc/fstab" },
|
|
{ EXIT_FAILURE = 1 },
|
|
{ EXIT_SUCCESS = 0 },
|
|
io__open_input(Filename, Result),
|
|
( { Result = ok(WordsStream) } ->
|
|
read_words(WordsStream, Words),
|
|
io__close_input(WordsStream),
|
|
{ assoc_list__from_corresponding_lists(Words, Words,
|
|
AssocList) },
|
|
{ tree234__assoc_list_to_tree234(AssocList, Tree) },
|
|
io__stdin_stream(StdIn),
|
|
io__stdout_stream(StdOut),
|
|
{ browser_info__init_persistent_state(State0) },
|
|
io__write_string("list:"),
|
|
io__nl,
|
|
browse__browse(AssocList, StdIn, StdOut, _, State0, State1),
|
|
io__write_string("tree:"),
|
|
io__nl,
|
|
browse__browse(Tree, StdIn, StdOut, _, State1, State2),
|
|
io__write_string("stream:"),
|
|
io__nl,
|
|
browse__browse(StdIn, StdIn, StdOut, _, State2, _),
|
|
io__set_exit_status(EXIT_SUCCESS)
|
|
;
|
|
io__write_string("Can't open input file.\n"),
|
|
io__set_exit_status(EXIT_FAILURE)
|
|
).
|
|
|
|
:- pred read_words(io__input_stream::in, list(string)::out,
|
|
io__state::di, io__state::uo) is det.
|
|
|
|
read_words(Stream, Words) -->
|
|
io__read_word(Stream, Result),
|
|
( { Result = ok(Chars) } ->
|
|
{ string__from_char_list(Chars, Word) },
|
|
read_words(Stream, Rest),
|
|
{ Words = [Word | Rest] }
|
|
;
|
|
{ Words = [] }
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|