mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-29 16:24:43 +00:00
Estimated hours taken: 8 Branches: main Add optional support for generating a pure interface to mutables. This is done by adding a new mutable attribute, `attach_to_io_state'. If this attribute is specified in the mutable declaration then in addition to the usual non-pure access predicates, the compiler will also add a pair of access predicates that take the IO state. compiler/prog_data.m: Add the `attach_to_io_state' mutable attribute. Add the necessary access predicates for the mutable_var_attributes structure. compiler/prog_io.m: Parse the `attach_to_io_state' attribute. compiler/prog_mutable.m: Shift some of the code for constructing items related to mutables to this module from make_hlds_passes. This reduces unnecessary clutter in the latter. Remove the XXX comment about needing to mangle the names of the globals - we now do that. compiler/make_hlds_passes.m: If a mutable has the `attach_to_io_state' attribute specified then create pure access predicates that take the IO state in addition to the non-pure ones. compiler/modules.m: If we are generating the pure access predicates then output the declarations for these predicates in private interfaces. compiler/type_util.m: Replace the use of ':' as a module qualifier in some comments. doc/reference_manual.texi: Document the `attach_to_io_state' mutable attribute. vim/syntax/mercury.vim: Highlight various mutable attributes appropriately. tests/hard_coded/Mmakefile: tests/hard_coded/pure_mutable.m: tests/hard_coded/pure_mutable.exp: Test mutables with pure access predicates. tests/hard_coded/ppc_bug.m: Unrelated change: update the comments in this test case so they describe what the cause of the bug and the fix were.
44 lines
1.1 KiB
Mathematica
44 lines
1.1 KiB
Mathematica
% The following program compiles incorrectly on PPC/MacOS X in grade reg.gc.
|
|
% find_nth_yes/4 ends up throwing an exception instead of returning `YesPos =
|
|
% 3'. Passing `--no-optimize-fulljumps' causes the test to pass.
|
|
%
|
|
% The test passes with gcc 2.95.2 (Apple version) but fails with gcc 3.3
|
|
% (Apple version).
|
|
%
|
|
% The problem was that gcc's `-floop-optimize' options was incompatible
|
|
% with our use of global registers. The fix is to make sure that option
|
|
% is disabled on powerpc-apple-darwin.
|
|
|
|
:- module ppc_bug.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list, int, bool, std_util, exception.
|
|
|
|
main(!IO) :-
|
|
find_nth_yes([yes, no, yes, yes], 2, 1, X),
|
|
io.write_int(X, !IO),
|
|
io.nl(!IO).
|
|
|
|
:- pred find_nth_yes(list(bool)::in, int::in, int::in, int::out) is det.
|
|
|
|
find_nth_yes([], _, _, _) :- throw("no").
|
|
find_nth_yes([B | Bs], N, Cur, YesPos) :-
|
|
(
|
|
B = no,
|
|
find_nth_yes(Bs, N, Cur + 1, YesPos)
|
|
;
|
|
B = yes,
|
|
( N = 1 ->
|
|
YesPos = Cur
|
|
;
|
|
find_nth_yes(Bs, N - 1, Cur + 1, YesPos)
|
|
)
|
|
).
|