[m-rev.] diff: don't use old C interface in extras

Julien Fischer juliensf at csse.unimelb.edu.au
Wed Jul 28 08:31:16 AEST 2010


Remove uses of the old C interface from the extras distribution.

extras/lazy_evaluation/lazy_list.m:
extras/quickcheck/qcheck.m:
extras/references/samples/max_of.m:
 	Use the new foreign language interface instead of the old C
 	interface.

extras/curses/basics.m:
 	As above, and conform to our current coding standards.

Julien.

Index: curses/basics.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/curses/basics.m,v
retrieving revision 1.3
diff -u -r1.3 basics.m
--- curses/basics.m	13 Feb 2002 09:56:27 -0000	1.3
+++ curses/basics.m	27 Jul 2010 22:24:20 -0000
@@ -1,10 +1,10 @@
-%----------------------------------------------------------------------------%
+%---------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
  % Copyright (C) 1994-2000 The University of Melbourne.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury Distribution.
  %----------------------------------------------------------------------------%
-
-%----------------------------------------------------------------------------%
  %
  % File:          basics.m
  % Main author:   conway
@@ -26,66 +26,70 @@
  %
  %----------------------------------------------------------------------------%

-:- module mcurses__basics.
+:- module mcurses.basics.
  :- interface.

-:- import_module char, int, io, string.
+:- import_module char.
+:- import_module int.
+:- import_module io.
+:- import_module string.
+
+%----------------------------------------------------------------------------%

-  % Initialise curses. This is used by user.m, and should not be called by the
-  % programmer.
-:- pred init(io__state, io__state).
-:- mode init(di, uo) is det.
+  % Initialise curses.
+  % This is used by user.m, and should not be called by the programmer.
+  %
+:- pred init(io::di, io::uo) is det.

    % Shutdown curses. This is required before exiting your program, or else you
    % will be left with a practically unusable terminal.
-:- pred endwin(io__state, io__state).
-:- mode endwin(di, uo) is det.
+  %
+:- pred endwin(io::di, io::uo) is det.

-  % Initialise the colour mode for curses. This must be called before
-  % attempting to use anything with colour.
-:- pred start_colour(io__state, io__state).
-:- mode start_colour(di, uo) is det.
+  % Initialise the colour mode for curses.
+  % This must be called before attempting to use anything with colour.
+  %
+:- pred start_colour(io::di, io::uo) is det.

    % Update the curses screen.
-:- pred update(io__state, io__state).
-:- mode update(di, uo) is det.
+  %
+:- pred update(io::di, io::uo) is det.

    % Perform a doupdate.
    % (see the curses man page for descriptions of update and doupdate)
-:- pred doupdate(io__state, io__state).
-:- mode doupdate(di, uo) is det.
+:- pred doupdate(io::di, io::uo) is det.

    % Clear the curses screen.
-:- pred clear(io__state, io__state).
-:- mode clear(di, uo) is det.
+  %
+:- pred clear(io::di, io::uo) is det.

-  % cursor(X, Y, IO0, IO)
-  % places the cursor at position X,Y
-:- pred cursor(int, int, io__state, io__state).
-:- mode cursor(in, in, di, uo) is det.
-
-  % Place a string on the screen, starting at the current cursor position
-:- pred putstr(string, io__state, io__state).
-:- mode putstr(in, di, uo) is det.
-
-  % Place a single character on the screen at the current cursor position
-:- pred putchar(char, io__state, io__state).
-:- mode putchar(in, di, uo) is det.
-
-  % cols(Cols, IO0, IO)
-  % retrieves the number of columns in the screen
-:- pred cols(int, io__state, io__state).
-:- mode cols(out, di, uo) is det.
-
-  % rows(Rows, IO0, IO)
-  % retrieves the number of rows in the screen
-:- pred rows(int, io__state, io__state).
-:- mode rows(out, di, uo) is det.
-
-  % getkey(Key, IO0, IO)
-  % Wait for the next keypress from the user, and return it as Key
-:- pred getkey(int, io__state, io__state).
-:- mode getkey(out, di, uo) is det.
+  % cursor(X, Y, !IO):
+  % Places the cursor at position X, Y.
+  %
+:- pred cursor(int::in, int::in, io::di, io::uo) is det.
+
+  % Place a string on the screen, starting at the current cursor position.
+  %
+:- pred putstr(string::in, io::di, io::uo) is det.
+
+  % Place a single character on the screen at the current cursor position.
+  %
+:- pred putchar(char::in, io::di, io::uo) is det.
+
+  % cols(Cols, !IO):
+  % Retrieves the number of columns in the screen.
+  %
+:- pred cols(int::out, io::di, io::uo) is det.
+
+  % rows(Rows, !IO):
+  % Retrieves the number of rows in the screen.
+  % 
+:- pred rows(int::out, io::di, io::uo) is det.
+
+  % getkey(Key, !IO):
+  % Wait for the next keypress from the user, and return it as Key.
+  %
+:- pred getkey(int::out, io::di, io::uo) is det.

  %----------------------------------------------------------------------------%

@@ -137,170 +141,335 @@

  :- import_module require.

-:- pragma c_header_code("
-	#include <curses.h>
-	#include <term.h>
+:- pragma foreign_decl("C", "
+    #include <curses.h>
+    #include <term.h>
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(init(IO0::di, IO::uo),
-        [will_not_call_mercury], "
-	WINDOW *w;
-	w = initscr();
-	noecho();
-	cbreak();
-	keypad(w, TRUE);
-	IO = IO0;
+:- pragma foreign_proc("C",
+    init(IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    WINDOW *w;
+    w = initscr();
+    noecho();
+    cbreak();
+    keypad(w, TRUE);
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(endwin(IO0::di, IO::uo),
-        [will_not_call_mercury], "
-	endwin();
-	IO = IO0;
+:- pragma foreign_proc("C",
+    endwin(IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    endwin();
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(start_colour(IO0::di, IO::uo),
-	[will_not_call_mercury], "
-        start_color();
-	init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
-	init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
-	init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
-	init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
-	init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
-	init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
-	init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
-	init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
-	IO = IO0;
+:- pragma foreign_proc("C",
+    start_colour(IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    start_color();
+    init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK);
+    init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
+    init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
+    init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
+    init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
+    init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
+    init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
+    init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(doupdate(IO0::di, IO::uo),
-        [will_not_call_mercury], "
-	doupdate();
-	IO = IO0;
+:- pragma foreign_proc("C",
+    doupdate(IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    doupdate();
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(update(IO0::di, IO::uo),
-        [will_not_call_mercury], "
-	refresh();
-	IO = IO0;
+:- pragma foreign_proc("C",
+    update(IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    refresh();
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(clear(IO0::di, IO::uo),
-        [will_not_call_mercury], "
-	clear();
-	IO = IO0;
+:- pragma foreign_proc("C",
+    clear(IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    clear();
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(cursor(X::in, Y::in, IO0::di, IO::uo),
-        [will_not_call_mercury], "
-	move(Y, X);
-	IO = IO0;
+:- pragma foreign_proc("C",
+    cursor(X::in, Y::in, IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    move(Y, X);
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(putstr(Str::in, IO0::di, IO::uo),
-        [will_not_call_mercury], "
-	      addstr(Str);
-	      IO = IO0;
+:- pragma foreign_proc("C",
+    putstr(Str::in, IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    addstr(Str);
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(putchar(C::in, IO0::di, IO::uo),
-	[will_not_call_mercury], "
-	addch((chtype) C);
-	IO = IO0;
+:- pragma foreign_proc("C",
+    putchar(C::in, IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    addch((chtype) C);
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(cols(C::out, IO0::di, IO::uo),
-        [will_not_call_mercury], "
-	C = tigetnum(""cols"");
-	IO = IO0;
+:- pragma foreign_proc("C",
+    cols(C::out, IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    C = tigetnum(""cols"");
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(rows(R::out, IO0::di, IO::uo),
-        [will_not_call_mercury], "
-	R = tigetnum(""lines"");
-	IO = IO0;
+:- pragma foreign_proc("C",
+    rows(R::out, IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    R = tigetnum(""lines"");
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(getkey(C::out, IO0::di, IO::uo),
-        [will_not_call_mercury], "
-	C = getch();
-	IO = IO0;
+:- pragma foreign_proc("C",
+    getkey(C::out, IO0::di, IO::uo),
+    [promise_pure, will_not_call_mercury],
+"
+    C = getch();
+    IO = IO0;
  ").

  %----------------------------------------------------------------------------%

-:- pragma c_code(break = (I::out), [will_not_call_mercury], "I = KEY_BREAK;").
-:- pragma c_code(down = (I::out), [will_not_call_mercury], "I = KEY_DOWN;").
-:- pragma c_code(up = (I::out), [will_not_call_mercury], "I = KEY_UP;").
-:- pragma c_code(left = (I::out), [will_not_call_mercury], "I = KEY_LEFT;").
-:- pragma c_code(right = (I::out), [will_not_call_mercury], "I = KEY_RIGHT;").
-:- pragma c_code(home = (I::out), [will_not_call_mercury], "I = KEY_HOME;").
-:- pragma c_code(backspace = (I::out), [will_not_call_mercury],
-        "I = KEY_BACKSPACE;").
-:- pragma c_code(fn(N::in) = (I::out), [will_not_call_mercury], "I=KEY_F(N);").
-:- pragma c_code(pageup = (I::out), [will_not_call_mercury], "I = KEY_PPAGE;").
-:- pragma c_code(pagedown = (I::out), [will_not_call_mercury], "I=KEY_NPAGE;").
+:- pragma foreign_proc("C",
+    break = (I::out),
+    [promise_pure, will_not_call_mercury],
+"
+    I = KEY_BREAK;
+").
+:- pragma foreign_proc("C",
+    down = (I::out),
+    [promise_pure, will_not_call_mercury],
+"
+    I = KEY_DOWN;
+").
+:- pragma foreign_proc("C",
+    up = (I::out),
+    [promise_pure, will_not_call_mercury],
+"
+    I = KEY_UP;
+").
+:- pragma foreign_proc("C",
+    left = (I::out),
+    [promise_pure, will_not_call_mercury],
+"
+    I = KEY_LEFT;
+").
+:- pragma foreign_proc("C",
+    right = (I::out),
+    [promise_pure, will_not_call_mercury],
+"
+    I = KEY_RIGHT;
+").
+:- pragma foreign_proc("C",
+    home = (I::out),
+    [promise_pure, will_not_call_mercury],
+"
+    I = KEY_HOME;
+").
+:- pragma foreign_proc("C",
+    backspace = (I::out),
+    [promise_pure, will_not_call_mercury],
+"
+    I = KEY_BACKSPACE;
+").
+:- pragma foreign_proc("C",
+    fn(N::in) = (I::out),
+    [promise_pure, will_not_call_mercury],
+"
+    I = KEY_F(N);
+").
+:- pragma foreign_proc("C",
+    pageup = (I::out),
+    [promise_pure, will_not_call_mercury],
+"
+    I = KEY_PPAGE;
+").
+:- pragma foreign_proc("C",
+    pagedown = (I::out),
+    [promise_pure, will_not_call_mercury],
+"
+    I = KEY_NPAGE;
+").

  %----------------------------------------------------------------------------%

-:- pragma c_code(black = (C::out), [will_not_call_mercury], "C=COLOR_BLACK;").
-:- pragma c_code(green = (C::out), [will_not_call_mercury], "C=COLOR_GREEN;").
-:- pragma c_code(red = (C::out), [will_not_call_mercury], "C = COLOR_RED;").
-:- pragma c_code(cyan = (C::out), [will_not_call_mercury], "C = COLOR_CYAN;").
-:- pragma c_code(white = (C::out), [will_not_call_mercury], "C=COLOR_WHITE;").
-:- pragma c_code(magenta = (C::out), [will_not_call_mercury],
-        "C = COLOR_MAGENTA;").
-:- pragma c_code(blue = (C::out), [will_not_call_mercury], "C = COLOR_BLUE;").
-:- pragma c_code(yellow = (C::out), [will_not_call_mercury],
-        "C = COLOR_YELLOW;").
+:- pragma foreign_proc("C",
+    black = (C::out),
+    [promise_pure, will_not_call_mercury],
+"
+    C = COLOR_BLACK;
+").
+:- pragma foreign_proc("C",
+    green = (C::out),
+    [promise_pure, will_not_call_mercury],
+"
+    C = COLOR_GREEN;
+").
+:- pragma foreign_proc("C",
+    red = (C::out),
+    [promise_pure, will_not_call_mercury],
+"
+    C = COLOR_RED;
+").
+:- pragma foreign_proc("C",
+    cyan = (C::out),
+    [promise_pure, will_not_call_mercury],
+"
+    C = COLOR_CYAN;
+").
+:- pragma foreign_proc("C",
+    white = (C::out),
+    [promise_pure, will_not_call_mercury],
+"
+    C = COLOR_WHITE;
+").
+:- pragma foreign_proc("C",
+    magenta = (C::out),
+    [promise_pure, will_not_call_mercury],
+"
+    C = COLOR_MAGENTA;
+").
+:- pragma foreign_proc("C",
+    blue = (C::out),
+    [promise_pure, will_not_call_mercury],
+"
+    C = COLOR_BLUE;
+").
+:- pragma foreign_proc("C",
+    yellow = (C::out),
+    [promise_pure, will_not_call_mercury],
+"
+    C = COLOR_YELLOW;
+").

  %----------------------------------------------------------------------------%

-:- pragma c_code(normal = (A::out), [will_not_call_mercury], "A = A_NORMAL;").
-:- pragma c_code(standout = (A::out), [will_not_call_mercury],
-        "A = A_STANDOUT;").
-:- pragma c_code(underline = (A::out), [will_not_call_mercury],
-        "A = A_UNDERLINE;").
-:- pragma c_code(reverse = (A::out), [will_not_call_mercury], "A=A_REVERSE;").
-:- pragma c_code(blink = (A::out), [will_not_call_mercury], "A = A_BLINK;").
-:- pragma c_code(dim = (A::out), [will_not_call_mercury], "A = A_DIM;").
-:- pragma c_code(bold = (A::out), [will_not_call_mercury], "A = A_BOLD;").
-:- pragma c_code(protect = (A::out), [will_not_call_mercury],
-        "A = A_PROTECT;").
-:- pragma c_code(invis = (A::out), [will_not_call_mercury], "A = A_INVIS;").
-:- pragma c_code(altcharset = (A::out), [will_not_call_mercury],
-        "A = A_ALTCHARSET;").
-:- pragma c_code(chartext = (A::out), [will_not_call_mercury],
-        "A = A_CHARTEXT;").
-:- pragma c_code(colour(C::in) = (A::out), [will_not_call_mercury],
-        "A = COLOR_PAIR(C);").
+:- pragma foreign_proc("C",
+    normal = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = A_NORMAL;
+").
+:- pragma foreign_proc("C",
+    standout = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = A_STANDOUT;
+").
+:- pragma foreign_proc("C",
+    underline = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = A_UNDERLINE;
+").
+:- pragma foreign_proc("C",
+    reverse = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = A_REVERSE;
+").
+:- pragma foreign_proc("C",
+    blink = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = A_BLINK;
+").
+:- pragma foreign_proc("C",
+    dim = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = A_DIM;
+").
+:- pragma foreign_proc("C",
+    bold = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = A_BOLD;
+").
+:- pragma foreign_proc("C",
+    protect = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = A_PROTECT;
+").
+:- pragma foreign_proc("C",
+    invis = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = A_INVIS;
+").
+:- pragma foreign_proc("C",
+    altcharset = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = A_ALTCHARSET;
+").
+:- pragma foreign_proc("C",
+    chartext = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = A_CHARTEXT;
+").
+:- pragma foreign_proc("C",
+    colour(C::in) = (A::out),
+    [promise_pure, will_not_call_mercury],
+"
+    A = COLOR_PAIR(C);
+").

  %----------------------------------------------------------------------------%

-:- pragma c_code("
+:- pragma foreign_code("C", "

  #ifdef MR_CONSERVATIVE_GC

@@ -339,5 +508,7 @@
  #endif

  ").
-%----------------------------------------------------------------------------%

+%----------------------------------------------------------------------------%
+:- end_module mcurses.basics.
+%----------------------------------------------------------------------------%
Index: lazy_evaluation/lazy_list.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/lazy_evaluation/lazy_list.m,v
retrieving revision 1.2
diff -u -r1.2 lazy_list.m
--- lazy_evaluation/lazy_list.m	27 Jul 2010 21:05:29 -0000	1.2
+++ lazy_evaluation/lazy_list.m	27 Jul 2010 21:55:25 -0000
@@ -85,7 +85,7 @@

  % Because the Mercury mode system is not properly polymorphic,
  % it doesn't always infer the right inst.  We sometimes need
-% to use inst casts (which can be implemented using `pragma c_code').
+% to use inst casts (which can be implemented using `pragma foreign_proc').
  % :-(

  :- func list_inst_cast(lazy_list(T)) = lazy_list(T).
Index: quickcheck/qcheck.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/quickcheck/qcheck.m,v
retrieving revision 1.7
diff -u -r1.7 qcheck.m
--- quickcheck/qcheck.m	5 Jan 2007 02:19:40 -0000	1.7
+++ quickcheck/qcheck.m	27 Jul 2010 22:02:16 -0000
@@ -612,70 +612,70 @@
  	% insances of testable.
  :- pred inst_cast_f0(f0, (func) = property).
  :- mode inst_cast_f0(in, out((func) = out is det)) is det.
-:- pragma c_code(inst_cast_f0(F0::in, F1::out((func) = out is det)),
-	[thread_safe, will_not_call_mercury],
+:- pragma foreign_proc("C", inst_cast_f0(F0::in, F1::out((func) = out is det)),
+	[promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  :- pred inst_cast_f1(f1(T1), func(T1) = property).
  :- mode inst_cast_f1(in, out(func(in) = out is det)) is det.
-:- pragma c_code(inst_cast_f1(F0::in, F1::out(func(in) = out is det)),
-	[thread_safe, will_not_call_mercury],
+:- pragma foreign_proc("C", inst_cast_f1(F0::in, F1::out(func(in) = out is det)),
+	[promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  :- pred inst_cast_f2(f2(T1, T2), func(T1, T2) = property).
  :- mode inst_cast_f2(in, out(func(in, in) = out is det)) is det.
-:- pragma c_code(inst_cast_f2(F0::in, F1::out(func(in, in) = out is det)),
-	[thread_safe, will_not_call_mercury],
+:- pragma foreign_proc("C", inst_cast_f2(F0::in, F1::out(func(in, in) = out is det)),
+	[promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  :- pred inst_cast_f3(f3(T1, T2, T3), func(T1, T2, T3) = property).
  :- mode inst_cast_f3(in, out(func(in, in, in) = out is det)) is det.
-:- pragma c_code(inst_cast_f3(F0::in, F1::out(func(in, in, in) = out is det)),
-	[thread_safe, will_not_call_mercury],
+:- pragma foreign_proc("C", inst_cast_f3(F0::in, F1::out(func(in, in, in) = out is det)),
+	[promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  :- pred inst_cast_f4(f4(T1, T2, T3, T4), func(T1, T2, T3, T4) = property).
  :- mode inst_cast_f4(in, out(func(in, in, in, in) = out is det)) is det.
-:- pragma c_code(inst_cast_f4(F0::in, 
+:- pragma foreign_proc("C", inst_cast_f4(F0::in,
  			      F1::out(func(in, in, in, in) = out is det)),
-        [thread_safe, will_not_call_mercury],
+        [promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  :- pred inst_cast_f5(f5(T1, T2, T3, T4, T5),
  		     func(T1, T2, T3, T4, T5) = property).
  :- mode inst_cast_f5(in, out(func(in, in, in, in, in) = out is det)) is det.
-:- pragma c_code(inst_cast_f5(F0::in, 
+:- pragma foreign_proc("C", inst_cast_f5(F0::in,
  	  	              F1::out(func(in, in, in, in, in)=out is det)),
-        [thread_safe, will_not_call_mercury],
+        [promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  :- pred inst_cast_f6(f6(T1, T2, T3, T4, T5, T6),
  		     func(T1, T2, T3, T4, T5, T6) = property).
  :- mode inst_cast_f6(in, out(func(in, in, in, in, in, in) = out is det)) is det.
-:- pragma c_code(inst_cast_f6(F0::in, 
+:- pragma foreign_proc("C", inst_cast_f6(F0::in,
  	  	              F1::out(func(in, in, in, in, in, in)
  			      		   = out is det)),
-        [thread_safe, will_not_call_mercury],
+        [promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  :- pred inst_cast_f7(f7(T1, T2, T3, T4, T5, T6, T7),
  		     func(T1, T2, T3, T4, T5, T6, T7) = property).
  :- mode inst_cast_f7(in, out(func(in, in, in, in, in, in, in)
  		                  = out is det)) is det.
-:- pragma c_code(inst_cast_f7(F0::in, 
+:- pragma foreign_proc("C", inst_cast_f7(F0::in,
  	  	              F1::out(func(in, in, in, in, in, in, in)
  			      	           = out is det)),
-        [thread_safe, will_not_call_mercury],
+        [promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  :- pred inst_cast_f8(f8(T1, T2, T3, T4, T5, T6, T7, T8),
  		     func(T1, T2, T3, T4, T5, T6, T7, T8) = property).
  :- mode inst_cast_f8(in, out(func(in, in, in, in, in, in, in, in)
  			          = out is det)) is det.
-:- pragma c_code(inst_cast_f8(F0::in, 
+:- pragma foreign_proc("C", inst_cast_f8(F0::in,
  	  	     F1::out(func(in, in, in, in, in, in, in, in)
  		     	     = out is det)),
-        [thread_safe, will_not_call_mercury],
+        [promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  :- pred inst_cast_f9(f9(T1, T2, T3, T4, T5, T6, T7, T8, T9), 
@@ -683,10 +683,10 @@
  :- mode inst_cast_f9(in,
  		     out(func(in, in, in, in, in, in, in, in, in)
  		     	      = out is det)) is det.
-:- pragma c_code(inst_cast_f9(F0::in, 
+:- pragma foreign_proc("C", inst_cast_f9(F0::in,
  	  	              F1::out(func(in, in, in, in, in, in,
  			                   in, in, in) = out is det)),
-        [thread_safe, will_not_call_mercury],
+        [promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  :- pred inst_cast_f10(f10(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10), 
@@ -694,10 +694,10 @@
  :- mode inst_cast_f10(in,
  		      out(func(in, in, in, in, in, in, in, in, in, in)
  		               = out is det)) is det.
-:- pragma c_code(inst_cast_f10(F0::in, 
+:- pragma foreign_proc("C", inst_cast_f10(F0::in,
  	  	               F1::out(func(in, in, in, in, in, in,
  			       		    in, in, in, in) = out is det)),
-        [thread_safe, will_not_call_mercury],
+        [promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  %---------------------------------------------------------------------------%
@@ -755,8 +755,8 @@

  :- pred inst_cast_p0((pred), (pred)).
  :- mode inst_cast_p0(in, out((pred) is semidet)) is det.
-:- pragma c_code(inst_cast_p0(F0::in, F1::out((pred) is semidet)),
-	[thread_safe, will_not_call_mercury],
+:- pragma foreign_proc("C", inst_cast_p0(F0::in, F1::out((pred) is semidet)),
+	[promise_pure, thread_safe, will_not_call_mercury],
  	"F1 = F0;").

  %---------------------------------------------------------------------------%
Index: references/samples/max_of.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/extras/references/samples/max_of.m,v
retrieving revision 1.1
diff -u -r1.1 max_of.m
--- references/samples/max_of.m	18 Jun 1998 04:30:31 -0000	1.1
+++ references/samples/max_of.m	27 Jul 2010 21:54:15 -0000
@@ -87,10 +87,16 @@
  :- mode min_solutions(pred(out) is nondet, out(bound(0))) is det.
  :- mode min_solutions(pred(out) is multi, out(bound(1))) is det.

-:- pragma c_code(
+:- pragma foreign_proc("C",
  	min_solutions(_Pred::(pred(out) is nondet), Res::out(bound(0))),
-		will_not_call_mercury, "Res = 0;").
-:- pragma c_code(
+	[will_not_call_mercury],
+"
+	Res = 0;
+").
+:- pragma foreign_proc("C",
  	min_solutions(_Pred::(pred(out) is multi), Res::out(bound(1))),
-		will_not_call_mercury, "Res = 1;").
+	[will_not_call_mercury],
+"
+	Res = 1;
+").


--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list