mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 09:53:36 +00:00
Make :- initialise' and :- finalise' declarations work in Java grades.
Branches: main
Make `:- initialise' and `:- finalise' declarations work in Java grades.
Initialisation predicates are simply called from static initialisation blocks.
Finalisation predicates work by registering methods (objects) with the
JavaInternal runtime class. After main/2 terminates each of the registered
methods is called.
compiler/make_hlds_passes.m:
Make add_pass_3_initialise, add_pass_3_finalise generate predicates
for backends other than C.
compiler/mlds_to_java.m:
Generate code to register finalisation predicates with the runtime.
Make the generated code that calls main/2 call run the registered
finalisers as well.
java/runtime/JavaInternal.java:
Add code to register and call finalisers when main/2 terminates.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (C) 2001-2003 The University of Melbourne.
|
||||
// Copyright (C) 2001-2003, 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.
|
||||
//
|
||||
@@ -20,4 +20,17 @@ public class JavaInternal {
|
||||
public static java.lang.String progname;
|
||||
public static java.lang.String[] args;
|
||||
public static int exit_status;
|
||||
|
||||
private static java.util.List<Runnable> finalisers
|
||||
= new java.util.ArrayList();
|
||||
|
||||
public static void register_finaliser(Runnable hook) {
|
||||
finalisers.add(hook);
|
||||
}
|
||||
|
||||
public static void run_finalisers() {
|
||||
for (Runnable r : finalisers) {
|
||||
r.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user