Commit Graph

1 Commits

Author SHA1 Message Date
Peter Wang
43052bb247 Add a new calling convention for Mercury procedures exported to Java with
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.
2009-11-30 00:31:56 +00:00