Commit Graph

686 Commits

Author SHA1 Message Date
Zoltan Somogyi
ecf7afcb8b Fix indentation. 2023-04-25 02:33:04 +10:00
Zoltan Somogyi
a47de48c4d s/input_stream/text_input_stream/ ...
... and the same for output streams.
2023-04-24 14:59:20 +10:00
Zoltan Somogyi
4281a28f73 Make text_{input,output}_stream standalone types ...
... and make {input,output}_stream synonyms for them, rather than vice versa.

library/io.m:
    As above.

library/bitmap.m:
library/dir.m:
library/io.primitives_read.m:
library/io.stream_db.m:
library/io.text_read.m:
library/mercury_term_lexer.m:
library/stream.string_writer.m:
    Conform to the change above.

tests/hard_coded/stream_string_writer_types.exp:
    Expect the new type_ctor for text streams.
2023-04-24 13:52:10 +10:00
Zoltan Somogyi
2a12732260 Improve well-formedness checks on UTF strings.
library/io.m:
    Add the predicates

        read_named_file_as_string_wf
        read_named_file_as_lines_wf
        read_file_as_string_wf
        read_file_as_string_and_num_code_units_wf

    which extend their base predicates (without the _wf suffix) by checking
    whether the string read from the file is well formed, and returning
    an error if it is not.

library/io.stream_op.m:
    Fix and expand a comment.

library/io.text_read.m:
    Add a comment.

library/string.m:
    Add check_well_formedness, a predicate that checks whether a string
    is well formed, and (if relevant) specifies the offset of the first
    non-well-formed character.

    Make the documentation of index_next and index_next_repl more detailed.

runtime/mercury_string.[ch]:
    Define MR_utf8_find_ill_formed_char, a version of MR_utf8_verify
    that returns the offset of the first ill-formed UTF-8 char in the
    given string, if there is one. This is used in the implementation of
    check_well_formedness for C.

NEWS.md:
    Announce the new library predicates.

    Sort some lists of pred names.
2023-04-21 15:55:23 +10:00
Julien Fischer
fbd1005eee Add system_error_is_success/1.
library/io.m:
     As above.

library/io.error_util.m:
     Delete the equivalent operation is_success/1 from here and
     just use system_error_is_success/1 instead.

NEWS.md:
     Announce the new predicate.
2023-02-13 11:30:40 +11:00
Zoltan Somogyi
3c5075aced Add the init_posn function.
library/io.m:
    As above.

NEWS:
    Announce the addition.

compiler/generate_dep_d_files.m:
library/mercury_term_parser.m:
    Use the new function.
2023-01-14 00:09:48 +11:00
Peter Wang
bda87983d4 Move some code to new io.error_util module.
This reduces the size of io.m a bit. The other reason for moving the
code is to allow modules that occur in a dependency cycle with io.m
to read results from io.error_util.trans_opt, whereas they may have
been prevented from reading io.trans_opt.

library/io.m:
library/io.error_util.m:
    Move is_error, throw_on_error and other similar predicates to a
    new undocumented submodule of io.m.

    Also move the support functions/predicates used by those predicates.

    Make io.make_io_error_from_system_error and
    io.make_io_error_from_windows_error call the implementations in
    io.error_util.m.

library/MODULES_UNDOC:
library/library.m:
    List the new submodule as undocumented.

library/benchmarking.m:
library/bitmap.m:
library/dir.m:
library/io.call_system.m:
library/io.file.m:
     Import the new submodule.
2023-01-13 18:54:04 +11:00
Zoltan Somogyi
c6d857cb6b Cleanups of ops-related code.
library/io.m:
    Delete the set_io_table predicate, which did nothing and was never
    called from anywhere, and the get_io_table predicate, which always
    returned the same op_table. They were in io.m's interface, but in the
    not-publicly-visible part of the interface.

library/ops.m:
    Rename the lookup_op method to is_op.

    Delete references to the predicates deleted from io.m.

NEWS:
    Announce the lookup_op->is_op rename.

compiler/parse_tree_out_term.m:
library/mercury_term_parser.m:
library/string.to_string.m:
library/term_io.m:
samples/calculator2.m:
tests/hard_coded/bug383.m:
    Conform to the lookup_op->is_op rename.

    Replace calls to get_io_table with code that directly gets
    the Mercury op table.

    In parse_tree_out_term.m, call the predicates operating on the
    Mercury op table directly, not through the op_table type class.

    In mercury_term_parser.m, update some comments.

    In term_io.m, use OpTable to refer to op_tables.

tests/hard_coded/stdlib_init.{m,exp}:
    Don't test get_io_table.
2022-11-12 12:53:07 +11:00
Zoltan Somogyi
5b2f6e533b Disable unknown_format_call warnings using scopes.
configure.ac:
    Require the installed compiler to support disable_warning scopes
    for unknown_format_calls.

compiler/Mercury.options:
library/Mercury.options:
    Do not disable unknown_format_call warnings in whole files.

compiler/parse_tree_out_info.m:
compiler/pd_debug.m:
library/io.m:
library/stream.string_writer.m:
library/string.m:
    Disable unknown_format_call warnings for just the format calls
    that need it.
2022-09-07 12:18:19 +10:00
Zoltan Somogyi
53bdfcc8c9 Inline throw_on_error and related preds ...
... so that compiler optimizations can separate the usual success path,
which does nothing, from the error path, which constructs and throws
an exception.

Modify throw_on_error itself to manually inline is_error, so that
we can (a) eliminate redundant testing for success/failure, and
(b) move all work that is unneeded on the success path out of the
success path. (Marking is_error to be inlined is not sufficient
to do this with our current optimization setup.)
2022-08-30 19:53:46 +10:00
Zoltan Somogyi
b14437552d Fix too-long line. 2022-08-29 22:23:07 +10:00
Peter Wang
2dd6156b45 Allow io.system_error values to be 0 or null.
A Mercury foreign_proc needs to be able to return *something* for a
system_error output argument when there is no error.
On the C backends, it can return 0.
On the C# and Java backends, it can return null.

library/io.m:
    Document 0 and null as valid values for system_error.

    Handle null system_errors in system_error_exception_name and
    get_exception_object_message.
2022-08-29 17:19:13 +10:00
Peter Wang
78a70474fc Allow user code to create io.error values with system errors.
library/io.m:
    Move make_io_error_from_system_error to public interface.

    Add make_io_error_from_windows_error.

    Rename is_maybe_win32_error to is_error_maybe_win32.
    Make it take an argument to indicate whether the error is a Win32
    error code.

    Make make_io_error_from_maybe_win32_error (an internal predicate)
    take an argument to indicate whether the error is a Win32
    error code.

library/dir.m:
    Conform to changes.

NEWS:
    Announce recent system error related changes.
2022-08-29 16:32:29 +10:00
Peter Wang
fc1cd53f83 Reduce size of MR_win32_error_name.
All the strings returned by MR_win32_error_name include a common prefix
"ERROR_". Since there are many (1749) such strings, we can reduce the
size of the data by about 10 KB by returning only the part following the
prefix.

tools/generate_windows_error_name:
runtime/mercury_windows_error_name.c:
    Make MR_win32_error_name return strings without the "ERROR_" prefix.

library/io.m:
    Update caller system_error_win32_error_name to add the "ERROR_"
    prefix.
2022-08-29 10:57:39 +10:00
Peter Wang
5f37702e36 Allow remove_file to remove an empty dir on C# backend.
library/io.file.m:
    Change the C# implementation of remove_file to delete empty
    directories.

    Document that remove_file may delete empty directories.

library/io.m:
    Update comment.
2022-08-26 15:18:55 +10:00
Peter Wang
ca36984af3 Allow rename_file to rename a directory on C# backend.
library/io.file.m:
    As above.

library/io.m:
    Update comment.
2022-08-26 15:18:55 +10:00
Zoltan Somogyi
cb00b3dbdc Make LIBRARY_INTERMODULE=no work again. 2022-08-26 14:43:52 +10:00
Peter Wang
aaa6ac5fe1 Introduce io.system_error to io.m public interface.
Implement the error handling proposals from February 2022 on the
mercury-users list, and August 2022 on the mercury-reviews list.

We add io.system_error to the public interface of io.m
and document what its foreign representation is for each backend.

We allow io.error to optionally contain an io.system_error value,
and provide predicates to retrieve the io.system_error from an io.error.
The user may then inspect the system error via foreign code.

We also provide a predicate that takes an io.error and returns a name
for the system error it contains (if any). This makes it relatively easy
for Mercury programs to check for specific error conditions.

By returning platform-specific (actually, implementation-dependent)
error names, we are pushing the responsibility of mapping strings to
error conditions onto the application programmer. On the other hand, it
is not practical for us to map all possible system-specific error codes
to some common set of values. We could do it for a small set of common
error codes/exceptions, perhaps.

The standard library will construct io.error values containing
io.system_errors. However, we do not yet provide a facility for user
code to do the same.

library/io.m:
    Move io.system_error to the public interface.

    Change the internal representation of io.error to support containing
    a io.system_error. An io.system_error may originate from an errno
    value or a Windows system error code; the constructor distinguishes
    those cases.

    Add predicates to retrieve a system_error from io.error.

    Add predicate to return the name of the system error in an io.error.

    Replace make_err_msg with make_io_error_from_system_error.

    Replace make_maybe_win32_err_msg with
    make_io_error_from_maybe_win32_error.

    Delete ML_make_err_msg and ML_make_win32_err_msg macros.

browser/listing.m:
library/bitmap.m:
library/dir.m:
library/io.call_system.m:
library/io.environment.m:
library/io.file.m:
library/io.text_read.m:
mdbcomp/program_representation.m:
    Conform to changes.

    Leave comments for followup work.

tools/generate_errno_name:
tools/generate_windows_error_name:
    Add scripts to generate mercury_errno_name.c and
    mercury_windows_error_name.c.

runtime/Mmakefile:
runtime/mercury_errno_name.c:
runtime/mercury_errno_name.h:
runtime/mercury_windows_error_name.c:
runtime/mercury_windows_error_name.h:
    Add MR_errno_name() and MR_win32_error_name() functions,
    used by io.m to convert error codes to string names.

tests/hard_coded/null_char.exp:
    Update expected output.
2022-08-23 16:39:48 +10:00
Zoltan Somogyi
752bb66f5b Carve four modules out of term.m.
Most modules that imported the old term.m need only a small subset
of its functionality. After this diff, most modules that used to import
term.m will need to import just one more module, and will import many
fewer predicates and functions in total.

library/term_int.m:
    A new module carved out of term.m containing the predicates
    that recognize terms containing integers, and the functions
    that construct such terms.

    While this job has *some* similarity to the job of the existing
    term_conversion.m module, most modules in the compiler use only one
    of those two modules, so merging them would not be a good idea.

library/term_subst.m:
    A new module carved out of term.m containing code to do
    substitutions and renames of various kinds.

    Rename the occurs predicate as var_occurs_in_subst_term,
    and occurs_list as var_occurs_in_subst_terms, since the latter
    are much more descriptive. Change the argument order to match
    the new names (var, subst, term/terms), as the old one did not
    even have the term/terms and the substitution next to each other,
    even though neither makes sense without the other.

library/term_unify.m:
    A new module carved out of term.m containing code to do unifications.

    Give all the predicates more meaningful names:

    unify_term ->                   unify_terms
    unify_term_list ->              unify_term_lists
    unify_term_dont_bind ->         unify_terms_dont_bind
    unify_term_list_dont_bind ->    unify_term_lists_dont_bind
    list_subsumes ->                first_term_list_subsumes_second

library/term_vars.m:
    A new module carved out of term.m containing code that find variables
    in terms.

    Give all the predicates more meaningful names:

    vars ->                         vars_in_term
    vars_2 ->                       vars_in_term_acc
    vars_list ->                    vars_in_terms
    contains_var ->                 term_contains_var
    contains_var_list ->            terms_contain_var

    Don't move the function version of vars_2 to term_vars.m, effectively
    deleting it, since operations that update an accumulator are awkward
    for functions.

library/term.m:
    Keep the moved predicates and functions in term.m, but

    - change their implementation to simply call the moved copy, and
    - obsolete the original in favor of the moved copy.

    Eventually, after either the next release or the release after the next,
    we should delete the obsoleted predicates and functions.

library/MODULES_DOC:
library/library.m:
    Add the new modules as documented parts of the standard library.

browser/interactive_query.m:
compiler/analysis.file.m:
compiler/det_util.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/intermod.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_passes.m:
compiler/parse_class.m:
compiler/parse_inst_mode_defn.m:
compiler/parse_item.m:
compiler/parse_mutable.m:
compiler/parse_pragma.m:
compiler/parse_pragma_analysis.m:
compiler/parse_sym_name.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_defn.m:
compiler/parse_util.m:
compiler/prog_ctgc.m:
compiler/prog_util.m:
compiler/recompilation.used_file.m:
compiler/recompilation.version.m:
compiler/superhomogeneous.m:
compiler/switch_detection.m:
compiler/typecheck.m:
library/io.m:
library/term_conversion.m:
library/varset.m:
    Conform to the changes above.
2022-08-21 01:01:21 +10:00
Zoltan Somogyi
9047bdbf05 Improve programming style in the browser directory.
browser/declarative_analyser.m:
browser/declarative_debugger.m:
browser/declarative_oracle.m:
browser/declarative_tree.m:
browser/declarative_user.m:
browser/interactive_query.m:
browser/listing.m:
browser/parse.m:
browser/util.m:
    Rename some predicates to avoid ambiguity.

    Factor out common code.

    If some versions of a field of a structure have names in a predicate
    (by being stored in a named variable), then give all *other* versions
    of that field in that structure names in that predicate as well.

    If a field of a structure is used more than once in a predicate,
    then again, store it in a named variable.

    Reorder predicate arguments to put state variables last.

    Use io.format instead of sequences of calls to io.write_string.

    In declarative_user.m, note a probable bug (in a position where
    it is probably rarely stumbled upon).

    In listing.m, use a consistent naming scheme to differentiate
    between Mercury streams and their C counterparts.

    Replace if-then-else chains with switches where possible.

browser/name_mangle.m:
    Note bit rot.

browser/browse.m:
    Conform to the changes above.

library/io.m:
    Improve predicate and variable names.

browser/mdb.m:
browser/mer_browser.m:
browser/percent_encoding.m:
browser/term_rep.m:
browser/tree234_cc.m:
library/library.m:
    Improve comments.
2022-07-03 13:55:54 +10:00
Julien Fischer
857e3b6328 Simplify some code.
library/io.m:
    Avoid looking up the current output stream multiple times in a couple of
    spots.
2022-07-02 02:13:56 +10:00
Julien Fischer
fabd05b7c8 Deprecate stream folds in the io module.
library/io.m:
   Add obsolete pragmas to the stream fold predicates in the io module.

NEWS:
   Announce the above.
2022-05-07 15:18:52 +10:00
Julien Fischer
6d0b861913 Specialise file copying in the compiler.
Specialise the Mercury implementation of file copying in the compiler by
avoiding the use of io.binary_input_stream_foldl_io/5. This allows us to avoid
a higher-order call each time a byte is written and it allows us to use the
unboxed version of the predicate that reads bytes. The other reason for this
change is that we are planning to deprecate (and eventually remove)
io.binary_input_stream_foldl_io/5.

compiler/module_cmds.m:
    As above.

    Add a comment about improving the Mercury implementation of file copying.

    Fix spelling in a spot.

library/io.m:
    Refer to the Boolean constant yes/0 and no/0 in C code as MR_YES
    and MR_NO respectively, rather than MR_TRUE and MR_FALSE.
2022-04-24 19:30:14 +10:00
Julien Fischer
0a7365dd95 Add write_binary_utf8_string.
Add predicates for writing the UTF-8 encoding of strings to binary output
streams.

library/io.m:
library/io.primitives_write.m:
    Add the new predicates.

NEWS:
    Announce the additions.

tests/hard_coded/Mmakefile:
tests/hard_coded/write_binary_utf8.{m,exp}:
    Add a test of the new predicates.
2022-04-07 12:29:46 +10:00
Julien Fischer
9d8012fa75 Address an XXX.
library/io.m:
    Delete a foreign_decl pragma for C# since the using directives it contains
    are now unneeded except for in one spot.  Add a qualifier to that one spot,
    allowing us to remove the entire pragma.
2022-04-03 01:30:29 +11:00
Peter Wang
6b1b49510a Fix build failure on Windows.
library/io.m:
    Include <wchar.h> for the definitions of dev_t and ino_t when
    building for Windows. This became necessary after some recent
    code movement in the io.m module.
2022-03-28 17:48:32 +11:00
Julien Fischer
d13e25064d Add stream writer instances for 64-bit ints.
library/io.m:
    As above.
2022-03-20 14:14:19 +11:00
Zoltan Somogyi
7f1e99ba95 Fix comments. 2022-03-19 04:22:08 +11:00
Zoltan Somogyi
cae42d8053 Read terms using explicit streams.
library/io.m:
    As above. Also, when several exported predicates use the same
    utility predicate, pass their $pred to the utility for use
    in exception messages.

tests/hard_coded/read_min_int.exp*:
    Expect the updated exception messages.
2022-03-15 12:23:36 +11:00
Zoltan Somogyi
d7fe06b6d3 Put args representing errors into consistent order. 2022-03-15 01:59:49 +11:00
Zoltan Somogyi
e163ea91b6 Carve io.text_read.m out of io.m, and ...
... move the implementation of flush_*output to io.stream_ops.m.

In both cases, improve the predicate names a bit.

Add a distinguishing prefix to the names of the function symbols of a type,
to reduce the number of times the function symbol names ok, error and eof
are overloaded from ridiculous to slighly less ridiculous :-(

Move related predicate arguments next to each other.

library/io.text_read.m:
    New submodule containing the code that implement the predicates
    that read values of non-primitive types, all but one of which are text.

library/io.stream_ops.m:
    Move the implementation of flushing output here from io.m.

library/io.m:
    Delete the code moved to the above modules.

library/MODULES_UNDOC:
library/library.m:
    List the new submodule as undocumented.

library/Mercury.options:
    Allow io.text_read.m, instead of io.m, to define an inst for a type
    that has a definition in a foreign language as well as Mercury.
    This diff moves this inst definition to io.text_read.m.
2022-03-15 01:12:07 +11:00
Zoltan Somogyi
b7ca428cef Move error handling and foreign_{decl,code} to end.
library/io.m:
    Move the foreign_decl and foreign_code pragmas to the end of this module.
    Delete two redundant #includes.

    Move the parts of this module that handle errors to just before
    the foreign_decls and foreign_codes.

    Document why it does not make sense to move the error handling code
    to a separate submodule.
2022-03-14 17:18:25 +11:00
Zoltan Somogyi
05fd615471 Carve io.stream_ops.m out of io.m.
Also, move foreign code pieces still in io.m that belong in
previously-carved-out modules to those modules.

library/io.m:
library/io.stream_ops.m:
    As above. The new private submodule contains the implementations
    (helper predicates) of the operations that

    - open and close streams,
    - get and set offsets in those streams,
    - get and set line numbers on streams,
    - return the standard streams, and
    - set streams as the current streams.

library/io.m:
    Make some previously private includes public, to allow modules outside
    of io.m to refer to the C# and Java symbols they define. These includes
    are in the second, undocumented interface section of io.m.

    Delete the foreign code moved to io.primitives_{read,write}.m,
    as well as the foreign code moved to io.stream_ops.m.

    Change {get,set}_{line_number,output_line_number}/3, which used
    to be implemented directly using foreign_procs, to implement them
    in terms of their arity-4 counterparts which take an explicit stream
    argument, which now are in io.stream_ops.m. This can yield a slowdown,
    but it should be so small as to be unmeasurable on all non-microbenchmark
    workloads.

    Move related code together.

    Update module qualifications in C# and Java code.

    Delete the second #include of mercury_library_types.h.

    Delete the MR_{initial,final}_io_state macros.

library/MODULES_UNDOC:
library/library.m:
    List the new submodule as undocumented.

library/io.primitives_read.m:
library/io.primitives_write.m:
    Move the C, C# and Java code related to reading and writing values
    of primitive types here from io.m. Put them into one foreign_decl
    and one foreign_code per language.

    Update module qualifications in C# and Java code.

library/benchmarking.m:
library/bitmap.m:
library/io.call_system.m:
    Update module qualifications in C# and Java code.

library/stm_builtin.m:
    Replace uses of the MR_{initial,final}_io_state macros with their bodies.
2022-03-14 15:20:22 +11:00
Zoltan Somogyi
aa6b78c6b9 Delete putback_byte_2.
library/io.primitives_read.m:
    As above.

library/io.m:
    Implement putback_byte using putback_uint8.
2022-03-12 16:49:02 +11:00
Zoltan Somogyi
de5129f9ae Centralize the interpretation of result codes. 2022-03-12 16:24:40 +11:00
Zoltan Somogyi
f3d7165a3a Carve io.primitives_{read,write}.m out of io.m.
library/io.m:
library/io.primitives_read.m:
library/io.primitives_write.m:
    As above. The two new private submodules contain the implementations
    (helper predicates) of the operations that respectively read and write
    values of primitive types.

library/MODULES_UNDOC:
library/library.m:
    List the new submodules as undocumented.
2022-03-12 15:00:41 +11:00
Zoltan Somogyi
47d4892ddb Put related foreign_code fragments together ...
... and put foreign definitions into the same order as their declarations.

Put all the C #includes into one foreign_decl. Delete a redundant #include.

Merge adjacent foreign code items where there seemed to be no good reason
for keeping them apart.

Add a disambiguating prefix on some function symbols.

Improve English expression in some comments.
2022-03-12 09:26:21 +11:00
Julien Fischer
5b9af32df3 Add a workaround.
library/io.m:
   Commit 318e708 deleted the export of the stream_id/0
   type, but doing so breaks installation in the Java grade.

   Add the abstract declaration of the above type back into
   the non-public interface of this module until the underlying
   issue is resolved.
2022-03-11 23:31:40 +11:00
Zoltan Somogyi
318e708c6c Delete a stray type declaration, and ...
... fix some comments to address issues raised in a review.
2022-03-11 18:30:59 +11:00
Zoltan Somogyi
80e1a47397 Carve io.stream_db.m out of io.m.
library/io.m:
library/io.stream_db.m:
    Move the data types describing the stream database, and the
    predicates and functions managing and accessing it, to the new
    submodule io.stream_db.m. Move the declarations and definitions
    of the global variables holding the dabase accordingly.

library/MODULES_UNDOC:
library/library.m:
    List the new module as an undocumented new module.

browser/browse.m:
browser/browser_info.m:
library/stream.string_writer.m:
    Get stream information from the new module.
2022-03-11 18:13:28 +11:00
Zoltan Somogyi
92b284ca2d Fix "NumCodeUnits != FileStringLen" bug.
library/io.m:
    The code shared between C and C# for reading files into strings
    uses an array. In the C version, which was written first, the array
    elements are UTF-8 code units, and the code treats them as such.
    In the C# version, the array elements are code *points*, which
    occupy one UTF-16 code unit in *most* cases, but not all, so treating
    the number of filled-in positions in the array as a count of code *units*
    was a bug, even though it passes most test cases (because most test
    inputs contain no code points that need more than one UTF-16 code unit).

    Fix this by

    - moving the determination of the number of code units in the string
      to a predicate that has different implementations in C and C#, and

    - having each implementation do what is right for that language.

    Document the above, and document which piece of code is used with
    which target language.

    Also, rename a predicate to avoid a name clash with a related-but-
    distinctly-different predicate in the string module.
2022-03-11 10:13:19 +11:00
Julien Fischer
d905fca596 Fix standard library compilation in the Java grade.
library/io.environment.m:
library/io.file.m:
    Fully qualify entities in foreign_procs that may be inlined
    across module boundaries.

library/io.m:
     Move the definition of the private class StreamPipe from here ...

library/io.call_system.m:
     ... to here where it is actually used.
2022-03-08 23:27:24 +11:00
Julien Fischer
4efb8f24b3 Fix standard library compilation in C# grade.
library/io.environment.m:
    Fully qualify a call to a foreign_exported Mercury predicate in order to
    avoid an error if its containing foreign_proc is inlined across module
    boundaries.

library/io.file.m:
    Fully qualify some foreign_exported enum constants for the same reason.

    Add missing using directives.

    Add a missing definition needed by Mono.

library/io.m:
    Delete trailing whitespace.

    Delete code moved to io.file.m.
2022-03-08 22:44:04 +11:00
Zoltan Somogyi
5951724b30 Put instance decls/defns into consistent orders. 2022-03-08 13:56:04 +11:00
Zoltan Somogyi
2f9dcf1e5b Move bitmap-related stream instances to bitmap.m. 2022-03-08 12:45:57 +11:00
Zoltan Somogyi
b6da884efb Moe decode_system_command_exit_code to io.call_system.m.
library/io.call_system.m:
library/io.m:
    As above.

browser/listing.m:
compiler/process_util.m:
    Conform to the change above.

library/io.environment.m:
    Delete stray ZZZ.
2022-03-08 11:33:43 +11:00
Zoltan Somogyi
c02eb5163e Carve io.{call_system,environment}.m out of io.m.
library/io.call_system.m:
    Move the code in the "system access predicates" section of io.m
    to this new module.

library/io.environment.m:
    Move the predicates dealing with environment variables in io.m
    to this new module.

library/io.m:
    Delete the code moved to the new modules.

    Leave behind in io.m "forwarding predicates", predicates that do nothing
    except call the moved predicates in the new modules, to provide backward
    compatibility. But do mark the forwarding predicates as obsolete,
    to tell people to update their (at their leisure, since the obsoleteness
    warning can be turned off).

    Also leave behind in io.m the definitions of the types used
    by some parameters of some of the moved predicates.

library/MODULES_DOC:
    List the new modules among the documented modules.

library/library.m:
    List the new modules, including io.file.m (added in a previous change)
    among the documented standard library modules.

NEWS:
    Announce the changes.

browser/browse.m:
browser/interactive_query.m:
compiler/fact_table.m:
compiler/handle_options.m:
compiler/make.module_target.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
compiler/optimize.m:
compiler/options_file.m:
deep_profiler/conf.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_test.m:
library/io.file.m:
mdbcomp/trace_counts.m:
ssdb/ssdb.m:
tests/general/environment.m:
tests/hard_coded/closeable_channel_test.m:
tests/hard_coded/setenv.m:
tests/hard_coded/system_sort.m:
    Call the moved predicates directly in their new modules,
    not indirectly through io.m.
2022-03-08 09:38:27 +11:00
Zoltan Somogyi
25b4b67403 Carve io.file.m out of io.m.
library/io.file.m:
library/io.m:
    Move two sections of io.m, the "file handling predicates" section
    and the "handling temporary files" section to the new submodule io.file.m.

    Leave behind in io.m "forwarding predicates", predicates that do nothing
    except call the moved predicates in io.file.m, to provide backward
    compatibility. But do mark the forwarding predicates as obsolete,
    to tell people to update their (at their leisure, since the obsoleteness
    warning can be turned off).

    Also leave behind in io.m the definitions of the two types used
    by some parameters of some of the moved predicates. Document the reason
    why this is done.

library/MODULES_DOC:
    List the new module among the documented modules.

NEWS:
    Announce the changes.

browser/browse.m:
browser/interactive_query.m:
browser/listing.m:
compiler/analysis.file.m:
compiler/compile_target_code.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_util.m:
compiler/handle_options.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
compiler/parse_module.m:
compiler/passes_aux.m:
compiler/prog_event.m:
compiler/recompilation.check.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
deep_profiler/conf.m:
deep_profiler/mdprof_cgi.m:
library/dir.m:
mdbcomp/program_representation.m:
ssdb/ssdb.m:
    Call the file operation predicates directly in io.file.m, not indirectly
    through io.m.

    In two modules, add a #include of fcntl.h in C code. These modules contain
    C code that needs this #include, but until now, they got it via a copy
    in an automatically generated C header file of a foreign_decl pragma
    in io.m that contained that #include. This diff moves that foreign_decl
    to io.file.m, removing that crutch.

tests/debugger/browser_test.m:
tests/hard_coded/bit_buffer_test.m:
tests/hard_coded/bitmap_test.m:
tests/hard_coded/construct_bug.m:
tests/hard_coded/dir_fold.m:
tests/hard_coded/dir_test.m:
tests/hard_coded/read_binary_int16.m:
tests/hard_coded/read_binary_int32.m:
tests/hard_coded/read_binary_int64.m:
tests/hard_coded/read_binary_uint16.m:
tests/hard_coded/read_binary_uint32.m:
tests/hard_coded/read_binary_uint64.m:
tests/hard_coded/read_bitmap_size.m:
tests/hard_coded/remove_file.m:
tests/hard_coded/write_binary.m:
tests/hard_coded/write_binary_int8.m:
tests/hard_coded/write_binary_multibyte_int.m:
tests/hard_coded/write_binary_uint8.m:
    Call the file operation predicates directly in io.file.m, not indirectly
    through io.m.
2022-03-08 06:01:21 +11:00
Zoltan Somogyi
1200014358 Move code to print stats from io to benchmarking.
library/benchmarking.m:
    Move the code of the predicates that print execution statistics
    here from io.m.

    Now that their pure replacements are here, mark the impure predicates
    report_stats and report_full_memory_stats as obsolete.

library/io.m:
    Replace the bodies of the predicates moved to benchmarking.m with
    forwarding calls to benchmarking.m, and mark the predicates themselves
    obsolete in favor of their moved versions.

NEWS:
    Mention the changes above.

compiler/file_util.m:
compiler/mercury_compile_main.m:
    Conform to the changes above.
2022-03-07 15:49:23 +11:00
Zoltan Somogyi
8ff61f8a4b Delete quotes from `VarNames' in stdlib comments.
In the Mercury standard library, every exported predicate or function
has (or at least *should* have) a comment that documents it, including
the meanings of its arguments. About 35-40% of these modules put `'s
(left and right quotes) around the names of the variable representing
those arguments. Some tried to do it consistently (though there were spots
with unquoted or half quoted names), while some did it only a few places.
This is inconsistent: we should either do it everywhere, or nowhere.
This diff makes it nowhere, because

- this is what the majority of the standard library modules do;
- this is what virtually all of the modules in the compiler, profiler,
  deep_profiler etc directories do;
- typing all those quotes when adding new predicates in modules that
  follow this convention is a pain in the ass; and because
- on many modern terminals, `' looks non-symmetrical and weird.

Likewise, the comment explaining a predicate often started with

    % `predname(arguments)' returns ...

This diff deletes these quotes as well, since they add nothing useful.

This diff does leave in place quotes around code fragments, both terms
and goals, where this helps delineate the boundaries of that fragment.
2022-03-07 11:49:00 +11:00