[m-rev.] for review: Added support for progname and exit status in grade Java.
James Goddard
goddardjames at yahoo.com
Mon Dec 22 13:37:26 AEDT 2003
Estimated hours taken: 3
Branches: main
Added support for progname and exit status in grade Java.
compiler/mlds_to_java.m:
Added code to maybe_write_main_driver/5 to store the main class's name
and exit status in mercury.runtime.JavaInternal's static variables.
Also, main() now calls java.lang.System.exit() instead of returning,
since Java insists that main must have void return type.
java/runtime/JavaInternal.java:
Added static variables "progname" and "exit_status".
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.48
diff -u -d -r1.48 mlds_to_java.m
--- compiler/mlds_to_java.m 2 Dec 2003 10:01:51 -0000 1.48
+++ compiler/mlds_to_java.m 22 Dec 2003 02:18:49 -0000
@@ -1026,17 +1026,28 @@
io__write_string("(java.lang.String[] args)\n"),
indent_line(Indent),
io__write_string("{\n"),
- indent_line(Indent + 1),
%
- % Save the command line arguments in the class variable
- % `mercury.runtime.JavaInternal.args'.
+ % Save the progname and command line arguments in the class
+ % variables of `mercury.runtime.JavaInternal', as well as
+ % setting the default exit status.
%
+ { unqualify_name(JavaSafeModuleName, ClassName) },
+ indent_line(Indent + 1),
+ io__write_string("mercury.runtime.JavaInternal.progname = """),
+ io__write_string(ClassName),
+ io__write_string(""";\n"),
+ indent_line(Indent + 1),
io__write_string("mercury.runtime.JavaInternal.args = args;\n"),
+ indent_line(Indent + 1),
+ io__write_string("mercury.runtime.JavaInternal.exit_status = "),
+ io__write_string("0;\n"),
indent_line(Indent + 1),
prog_out__write_sym_name(JavaSafeModuleName),
io__write_string(".main_2_p_0();\n"),
indent_line(Indent + 1),
- io__write_string("return;\n"),
+ io__write_string("java.lang.System.exit"),
+ io__write_string("(mercury.runtime.JavaInternal.exit_status);"),
+ io__nl,
indent_line(Indent),
io__write_string("}\n")
;
Index: java/runtime/JavaInternal.java
===================================================================
RCS file: /home/mercury1/repository/mercury/java/runtime/JavaInternal.java,v
retrieving revision 1.1
diff -u -d -r1.1 JavaInternal.java
--- java/runtime/JavaInternal.java 11 Feb 2002 06:31:32 -0000 1.1
+++ java/runtime/JavaInternal.java 22 Dec 2003 01:18:59 -0000
@@ -8,13 +8,16 @@
// compiler/mlds_to_java.m
//
//
-// At the moment this class is just used to store the command line
-// arguments. We can't put them in one of the library modules because
-// we need to hold them in a class variable in a top level class.
+// At the moment this class is used to store the main module's name (progname),
+// command line arguments and the exit status. We can't put them in one of the
+// library modules because we need to hold them in a class variable in a top
+// level class.
//
package mercury.runtime;
public class JavaInternal {
- public static java.lang.String[] args;
+ public static java.lang.String progname;
+ public static java.lang.String[] args;
+ public static int exit_status;
}
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list