Files
mercury/tests/hard_coded/c_write_string.m
2020-04-07 08:25:30 +10:00

37 lines
898 B
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module c_write_string.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
%---------------------------------------------------------------------------%
main(!IO) :-
c_write_string("Hello, world\n", !IO),
c_write_string("I am 8 today!\n", !IO),
c_write_string(X, !IO),
X = "fred\n".
:- pragma foreign_decl("C", "#include <stdio.h>").
:- pred c_write_string(string::in, io::di, io::uo) is det.
:- pragma foreign_proc("C",
c_write_string(Str::in, IO0::di, IO::uo),
[will_not_call_mercury, promise_pure],
"
fputs(Str, stdout);
IO = IO0;
").
c_write_string(Str, !IO) :-
% For the non-C backends.
io.write_string(Str, !IO).