mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 09:53:36 +00:00
Branches: main, 10.04
samples/README:
samples/java_interface/README:
samples/java_interface/java_calls_mercury/JavaMain.java:
samples/java_interface/java_calls_mercury/Makefile:
samples/java_interface/java_calls_mercury/java_main_int.m:
samples/java_interface/java_calls_mercury/mercury_lib.m:
samples/java_interface/java_calls_mercury/mercury_main.m:
samples/java_interface/mercury_calls_java/JavaMain.java:
samples/java_interface/mercury_calls_java/Makefile:
samples/java_interface/mercury_calls_java/java_main_int.m:
samples/java_interface/mercury_calls_java/mercury_main.m:
Add examples of Mercury/Java integration.
32 lines
1011 B
Mathematica
32 lines
1011 B
Mathematica
% This module java_main_int defines a Mercury predicate java_main which acts as an
|
|
% interface to the Java method java_main(), which is defined in JavaMain.java.
|
|
|
|
% This source file is hereby placed in the public domain.
|
|
|
|
:- module java_main_int.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
% Since the java_main() function has side effects, we declare the corresponding
|
|
% Mercury predicate as one that takes an io__state pair. If we didn't do
|
|
% this, the Mercury compiler might optimize away calls to it!
|
|
|
|
:- pred java_main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
% Import the Java class containing the method java_main.
|
|
% As usual for Java, this is not necessary; you may also
|
|
% fully qualify the method at the call site.
|
|
:- pragma foreign_decl("Java", "import my_package.JavaMain;").
|
|
|
|
% Define the Mercury predicate java_main to call the Java function
|
|
% java_main.
|
|
:- pragma foreign_proc("Java",
|
|
java_main(IO0::di, IO::uo),
|
|
[promise_pure, will_not_call_mercury],
|
|
"
|
|
JavaMain.java_main();
|
|
IO = IO0;
|
|
").
|