Files
mercury/tests/hard_coded/ppc_bug.m
Julien Fischer 192a58021b Add optional support for generating a pure interface to mutables.
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.
2005-10-06 08:26:12 +00:00

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)
)
).