Files
mercury/tests/hard_coded/stdlib_init.m
Julien Fischer 5e09921375 Workaround standard library initialization problems in the Java grades.
In the Java grade, the standard streams were not being entered into the stream
database and the I/O globals were not being initialized.  For executables,
generate a call to library.std_library_init/2 before main/2 is invoked.  There
is still a problem for Mercury libraries called from Java programs and for
predicates specified in `:- initialise' declarations.   For the latter, Mercury
requires that all standard library initialization be performed *before* any
user specified initialize predicates, but because we currently implement all of
this in Java using static initializers we can't guarantee that the order things
occur in.

The same issue affects the C# grade; I'll add a workaround for it separately.

library/io.m:
    In the predicate io.init_state/2, in the Java grade do not
    bother setting the current stream since for the standard text
    streams we do so as part of class initialization and

library/library.m:
    Export std_library_init/2 to Java.

compiler/mlds_to_java.m:
     Generate a call to library.std_library_init/2 before main/2 is called.
     XXX TODO we should roll the call that initializes the benchmarking module
     into the same.

tests/hard_coded/Mmakefile:
tests/hard_coded/stdlib_init.{m,exp}:
    Test that the stream database and globals in the io module are
    initialized before main/2 is called.
2016-03-06 00:30:20 +11:00

23 lines
540 B
Mathematica

% Test that the standard library is initialised before main/2 is called.
:- module stdlib_init.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
main(!IO) :-
io.get_globals(Globals, !IO),
io.print_line(Globals, !IO),
io.get_op_table(OpsTable, !IO),
io.print_line(OpsTable, !IO),
io.stdin_stream(Stdin, !IO),
io.print_line(Stdin, !IO),
io.stdout_stream(Stdout, !IO),
io.print_line(Stdout, !IO),
io.stderr_stream(Stderr, !IO),
io.print_line(Stderr, !IO).