Files
mercury/tests/hard_coded/foreign_code_before_proc.m
Zoltan Somogyi dc47131aea Put foreign_codes before foreign_procs for LLDS.
This fixes a bug reported by Keri Harris on m-users.

compiler/llds_out_file.m:
    Output foreign_codes before the C modules that may contain
    foreign_procs, since those foreign_procs may need to refer
    to entities defined in the foreign_codes.

compiler/mercury_compile_llds_back_end.m:
    Improve some comments.

tests/hard_coded/foreign_code_before_proc.{m,exp}:
    A regression test for this bug.

tests/hard_coded/Mmakefile:
    Enable the regression test.
2020-07-26 21:39:11 +10:00

33 lines
680 B
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
%
% Test whether the contents of a foreign_code pragma are put into
% the generated .c file *before* the foreign_procs that use its contents.
%
:- module foreign_code_before_proc.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
main(!IO) :-
io.write_line(xyzzy, !IO).
:- func xyzzy = int.
:- pragma foreign_proc("C",
xyzzy = (X::out), [promise_pure],
"
X = xyzzy;
").
xyzzy = 42.
:- pragma foreign_code("C", "
int xyzzy = 42;
").