[m-rev.] for review: dump terms as docs in mdb

Peter Wang novalazy at gmail.com
Thu Aug 25 11:13:40 AEST 2022


On Thu, 25 Aug 2022 06:42:57 +1000 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> For review by anyone.
> 
> Zoltan.

> Allow terms to be dumped as docs in mdb.
> 

I'm confused by this, as "docs" is not a data format. This functionality
should just be called pretty printing, and the dump command should take
a -p argument.

> The usual mdb "dump" command puts every function symbol on its own line.
> This guarantees that we generate any line that is too long to be displayed
> on terminals, but it also generates output that is too stretched out
> vertically for its structure to be readily apparent. Dumping the term
> as a doc allows pretty_printer.m to put as many function symbols on a line
> as would fit, without exceeding the maximum line length.
> 
> browser/browse.m:
>     Add save_term_to_file_doc, a wrapper around the new write_as_doc
>     predicate in pretty_printer.m that presents the same interface
>     to its callers as the predicates that save terms as XML.
> 
>     Inline a predicate at its only call site. Improve variable names.
> 
> trace/mercury_trace_browse.[ch]:
>     Add MR_trace_save_term_as_doc,

comma

> 
> trace/mercury_trace_cmd_browsing.c:
>     Add support for a new -d/--doc flag to the mdb "dump" command,
>     which asks for the given term to be dumped as a pretty_printer doc.
> 
> doc/user_guide.texi:
> NEWS:
>     Document the new option.
> 
> tests/debugger/browser_test.inp:
>     Dump a term that we already dumped with "dump" with "dump -x" and
>     "dump -d" as well.
> 
> tests/debugger/browser_test.m:
>     Put the code to remove the files we are going to dump to
>     and then later to print the files we have dumped to into separate
>     predicates. This keeps most (but not all) line numbers unchanged
>     even though we now dump to more files.
> 
> tests/debugger/browser_test.exp3:
>     Update this file to account both for the extra output from the just-added
>     dump commands, and for the changes in line numbers.


> diff --git a/NEWS b/NEWS
> index 85aec7ceb..ef45b1200 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -620,6 +620,13 @@ Changes to the Mercury compiler
>    batch files generated by the compiler when creating executables in the `java`
>    grade.
>  
> +Changes to the Mercury debugger
> +-------------------------------
> +
> +* The `dump` command has a new option: `dump -d Var` will dump the value
> +  of the given variable using the `write_as_doc` predicate in the
> +  pretty_printer module of the standard library.
> +

Say dump now supports pretty printing, without mentioning the
implementation method.

> diff --git a/doc/user_guide.texi b/doc/user_guide.texi
> index 295a3c71a..8f8e925ce 100644
> --- a/doc/user_guide.texi
> +++ b/doc/user_guide.texi
> @@ -3401,13 +3401,17 @@ specifies how many of the initial differences to skip.
>  The option @samp{-m} (or @samp{--max}), if present,
>  specifies how many differences to print.
>  @sp 1
> - at item dump [-qx] goal @var{filename}
> + at item dump [-dqx] goal @var{filename}
>  @kindex dump (mdb command)
>  Writes the goal of the current call in its present state of instantiation
>  to the specified file,
>  and outputs a message announcing this fact
>  unless the option @samp{-q} (or @samp{--quiet}) was given.
> -The option @samp{-x} (or @samp{--xml}) causes the output to be in XML.
> +The option @samp{-d} (or @samp{--doc}) causes the term to be output
> +using the @code{write_as_doc} predicate
> +in the @code{pretty_printer} module of the Mercury standard library.

Don't mention the implementation method.

> +The option @samp{-x} (or @samp{--xml}) causes the term to be output
> +in XML format.
>  @sp 1
>  @item dump [-qx] exception @var{filename}
>  Writes the value of the exception at an EXCP port to the specified file,

> diff --git a/trace/mercury_trace_browse.c b/trace/mercury_trace_browse.c
> index 389c5fe18..64d9ee899 100644
> --- a/trace/mercury_trace_browse.c
> +++ b/trace/mercury_trace_browse.c
> @@ -847,19 +847,28 @@ MR_trace_cmd_dump(char **words, int word_count, MR_TraceCmdInfo *cmd,
>              const char  *name;
>  
>              MR_convert_arg_to_var_spec(words[1], &var_spec);
> -            problem = MR_lookup_unambiguous_var_spec(var_spec,
> +            value_problem = MR_lookup_unambiguous_var_spec(var_spec,
>                  &type_info, &value, &name);
> -            if (problem == NULL) {
> +            if (value_problem == NULL) {
>                  browser_term = MR_type_value_to_browser_term(type_info, value);
>              }
>          }
>  
> -        if (problem != NULL) {
> +        if (value_problem != NULL) {
>              fflush(MR_mdb_out);
> -            fprintf(MR_mdb_err, "mdb: %s.\n", problem);
> +            fprintf(MR_mdb_err, "mdb: %s.\n", value_problem);
>          } else {
> +            if (xml && doc) {
> +                fflush(MR_mdb_out);
> +                fprintf(MR_mdb_err,
> +                    "mdb: the -d and -q options of the \"dump\" command "
> +                    "are mutually exclusive; ignoring -d.\n");
> +            }

-q should be -x

Peter


More information about the reviews mailing list