Files
mercury/tests/valid/intermod_nested_uniq2.m
Simon Taylor bbee78b584 Fix a bug reported by Robert Jeschofnik (rejj@students.cs.mu.oz.au)i
Estimated hours taken: 2

Fix a bug reported by Robert Jeschofnik (rejj@students.cs.mu.oz.au)i
which caused unique mode errors to be reported for clauses in
a `.opt' file, but not in the `.m' file. This was due to the
extra headvar unifications added by writing out the clauses
and reading them back in again creating extra aliasing that the
current mode analyser can't handle.

compiler/intermod.m:
	Strip out the extra unifications for the head variables
	of a clause, replacing the introduced unification with
	the RHS term. This doesn't work for lambda-goal unifications,
	but they shouldn't occur in clause heads too often.

compiler/hlds_out.m:
	In hlds_out__write_clause, allow the arguments of the clause
	head to be terms rather than just variables.

tests/valid/Mmakefile:
tests/valid/nested_unique_intermod.m:
tests/valid/nested_unique_intermod2.m:
	Test case.
1999-11-09 01:07:15 +00:00

46 lines
1.1 KiB
Mathematica

%-----------------------------------------------------------------------------%
:- module intermod_nested_uniq2.
:- interface.
:- import_module array.
:- inst uniq_f_matrix == unique(f_matrix(ground, ground, uniq_array)).
:- mode f_matrix_di == di(uniq_f_matrix).
:- mode f_matrix_uo == out(uniq_f_matrix).
:- mode f_matrix_ui == in(uniq_f_matrix).
:- type f_matrix.
:- pred init(int, int, f_matrix).
:- mode init(in, in, f_matrix_uo) is det.
:- pred lookup(int, int, f_matrix, float).
:- mode lookup(in, in, f_matrix_ui, out) is det.
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module array, float, int.
:- type f_matrix --->
f_matrix(
int, % M
int, % N
array(float) % the elements of the matrix
).
%-----------------------------------------------------------------------------%
init(M, N, Matrix) :-
array__init(M * N, 0.0, Array),
Matrix = f_matrix(M, N, Array).
% Lookup element (I, J) in the f_matrix.
% If (I, J) is not a valid index to the matrix, the behaviour is undefined
lookup(I, J, f_matrix(_M, N, Array), Elem) :-
array__lookup(Array, (I * N) + J, Elem).