mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 09:23:44 +00:00
compiler/ml_unify_gen.m:
Expand double-word args and pack sub-word arguments in the same pass,
initially for dynamically constructed cells only.
Doing both in the same pass is a prerequisite for future improvements
in argument packing schemes.
tests/hard_coded/packed_arg_partial_inst.{m,exp}:
A new test case to test the packing of arguments when some of them
have inst "free".
tests/hard_coded/Mmakefile:
Enable the new test case.
88 lines
2.4 KiB
Mathematica
88 lines
2.4 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% Test the construction of a cell in which a free argument is packed
|
|
% together into the same word with other arguments.
|
|
|
|
:- module packed_arg_partial_inst.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module bool.
|
|
:- import_module list.
|
|
|
|
:- type struct
|
|
---> struct(int, fruit, bool, fruit, bool, fruit, string).
|
|
|
|
:- type fruit
|
|
---> apple
|
|
; pear
|
|
; orange.
|
|
|
|
:- pred foo(list(struct)::in, string::out) is det.
|
|
|
|
foo(Xs, R) :-
|
|
( if
|
|
X = struct(42, _, yes, orange, _, _, _),
|
|
member(X, Xs)
|
|
then
|
|
R = "found struct(42, _, yes, orange, _, _, _)\n"
|
|
else
|
|
R = "not found struct(42, _, yes, orange, _, _, _)\n"
|
|
).
|
|
|
|
:- pred bar(list(struct)::in, string::out) is det.
|
|
|
|
bar(Xs, R) :-
|
|
( if
|
|
X = struct(_, _, _, orange, _, pear, _),
|
|
member(X, Xs)
|
|
then
|
|
R = "found struct(_, _, _, orange, _, pear, _)\n"
|
|
else
|
|
R = "not found struct(_, _, _, orange, _, pear, _)\n"
|
|
).
|
|
|
|
main(!IO) :-
|
|
StructA = struct(11, apple, yes, orange, no, pear, "abc"),
|
|
StructB = struct(22, apple, yes, orange, no, pear, "abc"),
|
|
StructC = struct(22, apple, no, orange, no, pear, "abc"),
|
|
StructD = struct(42, apple, yes, orange, no, pear, "abc"),
|
|
StructE = struct(42, apple, yes, apple, no, pear, "abc"),
|
|
StructF = struct(42, apple, no, orange, no, pear, "abc"),
|
|
|
|
Tests = [
|
|
[StructA],
|
|
[StructB],
|
|
[StructC],
|
|
[StructD],
|
|
[StructE],
|
|
[StructF],
|
|
[StructA, StructB],
|
|
[StructA, StructB, StructC],
|
|
[StructA, StructB, StructC, StructD],
|
|
[StructA, StructB, StructC, StructE],
|
|
[StructA, StructB, StructC, StructF],
|
|
[StructA, StructD, StructE, StructF]
|
|
],
|
|
list.foldl(test, Tests, !IO).
|
|
|
|
:- pred test(list(struct)::in, io::di, io::uo) is det.
|
|
|
|
test(Struct, !IO) :-
|
|
io.write_line(Struct, !IO),
|
|
foo(Struct, FooResult),
|
|
io.write_string(FooResult, !IO),
|
|
bar(Struct, BarResult),
|
|
io.write_string(BarResult, !IO),
|
|
io.nl(!IO).
|