mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 21:35:49 +00:00
Branches: main
Add a new calling convention for Mercury procedures exported to Java with
`:- pragma foreign_export'. When the procedure has multiple output arguments,
require the caller to pass instances of a `Ref<T>' class which contain a field
to hold the output value. This is more verbose than returning an `Object[]'
array, and requires extra memory allocations, but is more type-safe. Another
advantage is that the Ref arguments will appear at the same positions as the
output arguments in the Mercury procedure.
The new convention must be enabled with `--java-export-ref-out'. The plan is
to enable it by default in the future.
compiler/options.m:
doc/reference_manual.texi:
Add the option.
compiler/ml_proc_gen.m:
When the option is set, disable `--det-copy-out' and generate the
function parameters assuming pass-by-reference for outputs.
Only use the new convention when necessary.
compiler/mlds_to_java.m:
Make the code to generate the exported forwarding methods account for
`mlds_ptr_type' parameters. These are converted to `Ref<T>' arguments.
java/runtime/Ref.java:
Add the reference class.
15 lines
380 B
Java
15 lines
380 B
Java
//
|
|
// Copyright (C) 2009 The University of Melbourne.
|
|
// This file may only be copied under the terms of the GNU Library General
|
|
// Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
//
|
|
// This class is used in some cases to hold output values of Mercury
|
|
// procedures exported to Java.
|
|
//
|
|
|
|
package jmercury.runtime;
|
|
|
|
public class Ref<T> {
|
|
public T val;
|
|
}
|