mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 09:53:36 +00:00
compiler/ml_unify_gen.m:
Do ORs and shifts on argument values being packed using MR_Unsigned.
Cast the results to MR_Box explicitly.
compiler/ml_util.m:
Add utility functions that return (static terms containing) the MLDS
representations of the builtin integer types.
compiler/mlds_to_c_data.m:
Parenthesize values being cast, to ensure that the cast applies
to the *whole* of the value, not just an initial part. (For example,
"(uint32_t) x >> 32" casts just x, not the result of the shift.)
tests/hard_coded/pack_int32.{m,exp}:
A regression test for the bug report that this diff addresses.
tests/hard_coded/Mmakefile:
Add the new test case.
51 lines
1.5 KiB
Mathematica
51 lines
1.5 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module pack_int32.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- type struct
|
|
---> struct(int32, int32, int32, int32).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
Static = struct(-2_147_483_648_i32, 2_147_483_647_i32,
|
|
-32_768_i32, 32_767_i32),
|
|
write_struct(Static, !IO),
|
|
|
|
Dynamic = struct(id(-2_147_483_648_i32), id(2_147_483_647_i32),
|
|
id(-32_768_i32), id(32_767_i32)),
|
|
write_struct(Dynamic, !IO),
|
|
|
|
Dynamic2 = struct(id(-2_147_483_648_i32), _, _, _),
|
|
Dynamic2 = struct(_, id(2_147_483_647_i32), _, _),
|
|
Dynamic2 = struct(_, _, id(-32_768_i32), _),
|
|
Dynamic2 = struct(_, _, _, id(32_767_i32)),
|
|
write_struct(Dynamic2, !IO).
|
|
|
|
:- func id(int32) = int32.
|
|
:- pragma no_inline(id/1).
|
|
|
|
id(X) = X.
|
|
|
|
:- pred write_struct(struct::in, io::di, io::uo) is det.
|
|
:- pragma no_inline(write_struct/3).
|
|
|
|
write_struct(struct(A, B, C, D), !IO) :-
|
|
io.write_string("struct(", !IO),
|
|
io.write_int32(A, !IO), io.write_string(", ", !IO),
|
|
io.write_int32(B, !IO), io.write_string(", ", !IO),
|
|
io.write_int32(C, !IO), io.write_string(", ", !IO),
|
|
io.write_int32(D, !IO),
|
|
io.write_string(")\n", !IO).
|