mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 23:35:25 +00:00
Estimated hours taken: 4 Branches: main Support impure initialise and finalise predicates in user code. In order to support this the arity of the initialise or finalise predicate can no longer be optionally omitted from the declaration. Supporting impure arity zero initialise/finalise declarations removes the restriction that every module that has an initialise/finalise declaration must import the io module. Allow initialize/finalize to be used as synonyms for initialise/finalise. Improve the documentation of initialise/finalise declarations. In particular: - mention the above changes. - mention that they may be cc_multi. - specify the order in which they invoked with respect to standard library initialisation/finalisation. - mention that these declarations are not currently available on non-C backends. compiler/make_hlds_passes.m: Support impure user initialise/finalise predicates. compiler/mercury_to_mercury.m: Write out the arities of the predicates specified in initialise and finalise declarations. compiler/prog_data.m: Add an arity field to the initialise and finalise items. compiler/prog_io.m: Don't allow the arity to be omitted in initialise and finalise declarations. compiler/module_qual.m: compiler/modules.m: compiler/recompilation.check.m: compiler/recompilation.version.m: Conform to the changes in the initialise and finalise items. library/ops.m: Add the alternate spellings of initialise and finalise to the ops table. doc/reference_manual.texi: Update the ops table. Mention that initialise and finalise predicates may be cc_multi. Document impure initialisation and finalisation predicates. Add some disclaimers: mutable, initialise and finalise declarations are not implemented for the non-C backends. tests/hard_coded/Mmakefile: tests/hard_coded/impure_init_and_final.m: tests/hard_coded/impure_init_and_final.exp: Test impure initialise and finalise declarations. tests/hard_coded/finalise_decl.m: tests/hard_coded/intialise_decl.m: Conform to the above changes. Also test the versions of the declarations that use the -ize ending. tests/hard_coded/sub-modules/finalise_parent.m: tests/hard_coded/sub-modules/initialise_child.m: tests/hard_coded/sub-modules/initialise_parent.m: Conform to the above changes. tests/invalid/bad_finalise.m: tests/invalid/bad_finalise.err_exp: tests/invalid/bad_initialise.m: tests/invalid/bad_initialise.err_exp: Extend these tests to check for missing or bad arities in intialise or finalise declarations. vim/syntax/mercury.vim: Highlight recently added syntax appropriately.
33 lines
549 B
Mathematica
33 lines
549 B
Mathematica
:- module impure_init_and_final.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- initialise init/0.
|
|
:- finalise final/0.
|
|
|
|
main(!IO) :- io.write_string("This is main...\n", !IO).
|
|
|
|
:- pragma foreign_decl("C", "#include <stdio.h>").
|
|
|
|
:- impure pred puts(string::in) is det.
|
|
:- pragma foreign_proc("C",
|
|
puts(S::in),
|
|
[will_not_call_mercury],
|
|
"
|
|
puts(S);
|
|
").
|
|
|
|
:- impure pred init is det.
|
|
|
|
init :- impure puts("This is init...").
|
|
|
|
:- impure pred final is det.
|
|
|
|
final :- impure puts("This is final...").
|