mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-30 16:54:41 +00:00
Branches: main, 10.04
Allow inlining of Java foreign_procs.
This revealed a problem with directly using the `succeeded' flag directly as
the success indicator in Java foreign_procs. When the code of the foreign_proc
becomes a nested function, and after nested functions are eliminated, there may
not be a variable called `succeeded' in that context; it is moved into
environment struct, and the transformation is not able to update handwritten
code to reflect that. The solution is to declare a local variable for the
foreign_proc, let the handwritten code assign that, then assign its final
value to the `succeeded' flag with an MLDS statement.
We take the opportunity to name the local variable `SUCCESS_INDICATOR', in
line with other backends.
compiler/inlining.m:
Allow inlining of Java foreign_procs.
compiler/ml_foreign_proc_gen.m:
In the code generated for semidet Java foreign_procs, declare a local
`SUCCESS_INDICATOR' variable and assign its value to the `succeeded'
flag afterwards.
Add braces to give the foreign_proc variables a limited scope.
compiler/make_hlds_warn.m:
Conform to renaming.
doc/reference_manual.texi:
Update documentation for the renaming of the `succeeded' variable.
library/array.m:
library/bitmap.m:
library/builtin.m:
library/char.m:
library/construct.m:
library/dir.m:
library/exception.m:
library/float.m:
library/int.m:
library/io.m:
library/math.m:
library/private_builtin.m:
library/rtti_implementation.m:
library/string.m:
library/thread.m:
library/time.m:
library/type_desc.m:
library/version_array.m:
Conform to renaming.
Fix problems with Java foreign_procs that may now be copied into other
modules when intermodule optimisation is enabled, some by disallowing
the procedures from being duplicated, some by making referenced
classes/fields `public'.
[Some of the `may_not_duplicate' attributes may not indicate actual
problems, just that it seems not worthwhile inlining calls to the
procedure.]
extras/solver_types/library/any_array.m:
tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/external_unification_pred.m:
tests/hard_coded/java_test.m:
tests/hard_coded/redoip_clobber.m:
tests/hard_coded/user_compare.m:
tests/valid/exported_foreign_type2.m:
tests/warnings/warn_succ_ind.m:
tests/warnings/warn_succ_ind.exp3:
Conform to renaming.
70 lines
1.6 KiB
Mathematica
70 lines
1.6 KiB
Mathematica
% A test of the Java interface.
|
|
|
|
:- module java_test.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
|
|
:- implementation.
|
|
:- import_module int.
|
|
|
|
:- func foo(int) = int.
|
|
/*
|
|
XXX `pragma export' not yet supported for Java
|
|
:- pragma export(foo(in) = out, "foo").
|
|
*/
|
|
foo(X) = X + 1.
|
|
|
|
main -->
|
|
java_write_string("Hello, world\n"),
|
|
( { java_semidet_succeed } ->
|
|
[]
|
|
;
|
|
java_write_string("java_semidet_succeed failed\n")
|
|
),
|
|
( { java_semidet_fail } ->
|
|
java_write_string("java_semidet_fail succeeded\n")
|
|
;
|
|
[]
|
|
).
|
|
|
|
:- pragma foreign_decl("Java", "
|
|
// some Java top-level declarations
|
|
class Foo {}
|
|
").
|
|
|
|
:- pragma foreign_code("Java", "
|
|
// some Java in-class declarations
|
|
static void bar() {
|
|
/*
|
|
XXX `pragma export' not yet supported for Java
|
|
// test `pragma export' functions
|
|
if (foo(42) != 43) {
|
|
throw new java.lang.Error(""bar: foo failed"");
|
|
}
|
|
*/
|
|
}
|
|
").
|
|
|
|
:- pred java_write_string(string::in, io__state::di, io__state::uo) is det.
|
|
|
|
:- pragma foreign_proc("Java",
|
|
java_write_string(Message::in, _IO0::di, _IO::uo),
|
|
[will_not_call_mercury, promise_pure],
|
|
"
|
|
// a Java procedure
|
|
System.out.print(Message);
|
|
// test that foreign_decl declarations are visible
|
|
Foo f;
|
|
// test that foreign_code declarations are visible
|
|
bar();
|
|
").
|
|
|
|
:- pred java_semidet_succeed is semidet.
|
|
:- pred java_semidet_fail is semidet.
|
|
:- pragma foreign_proc("Java", java_semidet_succeed,
|
|
[will_not_call_mercury, promise_pure], "SUCCESS_INDICATOR = true;").
|
|
:- pragma foreign_proc("Java", java_semidet_fail,
|
|
[will_not_call_mercury, promise_pure], "SUCCESS_INDICATOR = false;").
|