diff: samples/c_interface/simpler_c_calls_mercury changes
Fergus Henderson
fjh at kryten.cs.mu.OZ.AU
Sat Sep 6 23:03:28 AEST 1997
samples/c_interface/simpler_c_calls_mercury/README:
samples/c_interface/simpler_c_calls_mercury/c_main.c:
samples/c_interface/simpler_c_calls_mercury/mercury_lib.m:
samples/c_interface/simpler_cplusplus_calls_mercury/README:
samples/c_interface/simpler_cplusplus_calls_mercury/cpp_main.cc:
samples/c_interface/simpler_cplusplus_calls_mercury/mercury_lib.m:
Update to use the new mercury_init() and mercury_terminate()
functions.
cvs diff: Diffing .
Index: README
===================================================================
RCS file: /home/staff/zs/imp/mercury/samples/c_interface/simpler_c_calls_mercury/README,v
retrieving revision 1.1
diff -u -u -r1.1 README
--- 1.1 1997/07/25 03:55:16
+++ README 1997/09/06 11:45:21
@@ -2,11 +2,4 @@
where C calls Mercury.
This interface is simpler than having a Mercury main/2 call a c_main()
-function which then calls back Mercury. However, it is still not
-quite general enough -- we really ought to have MR_init_mercury() and
-MR_shutdown_mercury() functions to initialize and shutdown the Mercury
-Runtime engine, rather than the existing interface via mercury_main().
-
-So, the interface shown here should be considered as likely to
-change in future releases.
-
+function which then calls back Mercury.
Index: c_main.c
===================================================================
RCS file: /home/staff/zs/imp/mercury/samples/c_interface/simpler_c_calls_mercury/c_main.c,v
retrieving revision 1.1
diff -u -u -r1.1 c_main.c
--- 1.1 1997/07/25 03:55:17
+++ c_main.c 1997/09/06 11:47:54
@@ -11,15 +11,16 @@
char dummy;
Integer value;
MercuryList list;
+ int exit_status;
printf("In main().\n");
/*
- ** call mercury_main() to initialize the Mercury engine.
+ ** call mercury_init() to initialize the Mercury engine.
** This must be done before we can call any Mercury predicates
** or functions.
*/
- mercury_main(argc, argv, &dummy);
+ mercury_init(argc, argv, &dummy);
/*
** call the C function foo_test(), which is the interface
@@ -79,8 +80,15 @@
printf("baz(100, &value) returns FALSE\n");
}
+ /*
+ ** call mercury_terminate() to shutdown the Mercury engine.
+ ** This should be done after we have finished calling Mercury
+ ** predicates or functions.
+ */
+ exit_status = mercury_terminate();
+
printf("Returning from main().\n");
- return 0;
+ return exit_status;
}
static void print_list(MercuryList list) {
Index: mercury_lib.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/samples/c_interface/simpler_c_calls_mercury/mercury_lib.m,v
retrieving revision 1.1
diff -u -u -r1.1 mercury_lib.m
--- 1.1 1997/07/25 03:55:18
+++ mercury_lib.m 1997/09/06 12:59:49
@@ -3,8 +3,9 @@
:- interface.
:- import_module io.
-% main/2 is called by mercury_main() which is called on startup
-% this can be used as a hook for any actions needed on startup
+% To avoid link errors, there still has to be a main/2 defined somewhere
+% in the program; it won't be used, unless the C program calls
+% mercury_call_main(), which will call main/2.
:- pred main(io__state::di, io__state::uo) is det.
% a Mercury predicate with multiple modes
@@ -26,7 +27,7 @@
:- implementation.
:- import_module std_util, int, list.
-% for this example, we don't need to perform any actions on startup
+% for this example, main/2 isn't useful
main --> [].
% well, this is just a silly example...
The diffs to simpler_cplusplus_calls_mercury are similar.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list