mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 20:03:44 +00:00
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.
86 lines
2.3 KiB
Mathematica
86 lines
2.3 KiB
Mathematica
% vim: ft=mercury ts=4 sw=4 et
|
|
%
|
|
% This is a regression test for a bug in construct.get_functor/5,
|
|
% where it was not handling equivalence types properly.
|
|
|
|
:- module construct_bug.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module construct_bug_submodule.
|
|
|
|
:- import_module int.
|
|
:- import_module io.file.
|
|
:- import_module list.
|
|
:- import_module require.
|
|
:- import_module std_util.
|
|
:- import_module string.
|
|
|
|
main(!IO) :-
|
|
FileName = "temp.term",
|
|
|
|
call(
|
|
( pred(!.S::in, !:S::out) is det:-
|
|
count(["A"], !S),
|
|
count(["A", "A2"], !S),
|
|
count(["B"], !S),
|
|
count(["B", "B1"], !S),
|
|
count(["B", "B2"], !S),
|
|
count(["B", "B3"], !S),
|
|
count(["C"], !S),
|
|
count(["C", "C1"], !S)
|
|
), construct_bug_submodule.init, Map),
|
|
|
|
io.open_output(FileName, Result, !IO),
|
|
( if Result = ok(Temp_ORDIE_Out_OutStream) then
|
|
OutStream = Temp_ORDIE_Out_OutStream
|
|
else
|
|
error( "Failed to write to '" ++ FileName ++ "'.")
|
|
),
|
|
io.write(OutStream, Map, !IO),
|
|
io.write_string(OutStream, ".", !IO),
|
|
close_output(OutStream, !IO),
|
|
|
|
io.write_string("Saved the map to file: " ++ FileName ++ "\n", !IO),
|
|
|
|
io.open_input(FileName, Result2, !IO),
|
|
( if Result2 = ok(Temp_ORDIE_Out_InStream) then
|
|
InStream = Temp_ORDIE_Out_InStream
|
|
else
|
|
error( "Failed to open '" ++ FileName ++ "'.")
|
|
),
|
|
io.read(InStream, MayDataTerm, !IO),
|
|
io.close_input(InStream, !IO),
|
|
(
|
|
MayDataTerm = ok(ReadMap `with_type` stat)
|
|
;
|
|
MayDataTerm = eof,
|
|
error("Unexpected end of file: '" ++ FileName ++ "'.")
|
|
;
|
|
MayDataTerm = error(E, _),
|
|
error("Error reading term from: '" ++ FileName ++ "': " ++ E ++ ".")
|
|
),
|
|
|
|
io.write_string("Loaded the map from file: " ++ FileName ++ "\n", !IO),
|
|
|
|
( if Map = ReadMap then
|
|
io.write_string("The representations are identical.\n", !IO)
|
|
else
|
|
io.write_string("The representations are different.\n", !IO)
|
|
),
|
|
|
|
io.file.remove_file(FileName, RmResult, !IO),
|
|
(
|
|
RmResult = ok
|
|
;
|
|
RmResult = error(E2),
|
|
error("Error deleting file '" ++ FileName ++ "': "
|
|
++ io.error_message(E2) ++ ".")
|
|
).
|