mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-05-01 09:14:08 +00:00
Style and formatting fixes for Java interface samples.
samples/java_interface/java_calls_mercury/mercury_main.m:
samples/java_interface/mercury_calls_java/java_main_int.m:
samples/java_interface/standalone_java/JavaMain.java:
samples/java_interface/standalone_java/Makefile:
samples/java_interface/standalone_java/mercury_lib.m:
As above.
This commit is contained in:
@@ -36,7 +36,7 @@ public class JavaMain {
|
||||
runProgram(args);
|
||||
} finally {
|
||||
// When we have finished calling Mercury procedures then we need
|
||||
// to tell the Mercury Runtime that we've finished using it.
|
||||
// to tell the Mercury Runtime that we have finished using it.
|
||||
// The static method finalise() in the MercuryRuntime class does
|
||||
// this. This call is (currently) mandatory otherwise the JVM
|
||||
// may not exit cleanly, therefore it should be called in a
|
||||
@@ -63,8 +63,8 @@ public class JavaMain {
|
||||
System.exit(MercuryRuntime.getExitStatus());
|
||||
}
|
||||
|
||||
public static void runProgram(String[] args) {
|
||||
|
||||
public static void runProgram(String[] args)
|
||||
{
|
||||
// This is a call to an exported Mercury procedure that does some I/O.
|
||||
// The mercury_lib class contains a static method for each procedure
|
||||
// that is foreign exported to Java.
|
||||
|
||||
@@ -8,7 +8,8 @@ MMC = mmc
|
||||
JAVAC = javac
|
||||
JAVA = java
|
||||
|
||||
# We need to tell javac about the Mercury libraries.
|
||||
# We need to tell javac and java where to find the Mercury runtime and
|
||||
# standard libraries.
|
||||
GRADE = java
|
||||
MER_LIB_DIR = $(dir $(shell which mmc))../lib/mercury/lib/$(GRADE)
|
||||
MER_JARS = $(MER_LIB_DIR)/mer_std.jar:$(MER_LIB_DIR)/mer_rt.jar
|
||||
|
||||
@@ -35,47 +35,47 @@
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
|
||||
:- pragma foreign_export("Java", write_hello(di, uo),
|
||||
"writeHello").
|
||||
:- pragma foreign_export("Java", write_hello(di, uo), "writeHello").
|
||||
|
||||
write_hello(!IO) :-
|
||||
io.print_line("Hello World", !IO).
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
|
||||
:- pragma foreign_export("Java", cube(in) = out,
|
||||
"cube").
|
||||
:- pragma foreign_export("Java", cube(in) = out, "cube").
|
||||
|
||||
cube(X) = X * X * X.
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
%
|
||||
% Trivial concurrency test.
|
||||
%
|
||||
|
||||
% No one would normally write fibs this way.
|
||||
|
||||
:- pragma foreign_export("Java", fibs(in) = out, "fibs").
|
||||
|
||||
%
|
||||
% Trivial concurrency test. No one would normally write fibs this way.
|
||||
%
|
||||
:- pragma foreign_export("Java", fibs(in) = out,
|
||||
"fibs").
|
||||
fibs(N) = fibs_par(N).
|
||||
|
||||
:- func fibs_par(int) = int.
|
||||
|
||||
fibs_par(N) = F :-
|
||||
( N < 2 ->
|
||||
( if N < 2 then
|
||||
F = 1
|
||||
; N > fibs_thresh ->
|
||||
F2 = future((func) = fibs_par(N-2)),
|
||||
F1 = fibs_par(N-1),
|
||||
else if N > fibs_thresh then
|
||||
F2 = future((func) = fibs_par(N - 2)),
|
||||
F1 = fibs_par(N - 1),
|
||||
F = F1 + wait(F2)
|
||||
;
|
||||
F = fibs_seq(N-1) + fibs_seq(N-2)
|
||||
else
|
||||
F = fibs_seq(N - 1) + fibs_seq(N - 2)
|
||||
).
|
||||
|
||||
:- func fibs_seq(int) = int.
|
||||
|
||||
fibs_seq(N) =
|
||||
( N < 2 ->
|
||||
( if N < 2 then
|
||||
1
|
||||
;
|
||||
else
|
||||
fibs_seq(N-2) + fibs_seq(N-1)
|
||||
).
|
||||
|
||||
@@ -85,7 +85,7 @@ fibs_thresh = 20.
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
%
|
||||
% Initialiser for this library
|
||||
% Initialiser for this library.
|
||||
%
|
||||
|
||||
:- initialise initialiser/2.
|
||||
@@ -97,7 +97,7 @@ initialiser(!IO) :-
|
||||
|
||||
%-----------------------------------------------------------------------------%
|
||||
%
|
||||
% Finaliser for this library
|
||||
% Finaliser for this library.
|
||||
%
|
||||
|
||||
:- finalise finaliser/2.
|
||||
|
||||
Reference in New Issue
Block a user