[m-rev.] diff: fix undefined references in java version of standard library

Peter Wang novalazy at gmail.com
Tue Apr 28 12:07:15 AEST 2009


Branches: main

library/dir.m:
library/io.m:
        Update these modules using `:- pragma foreign_export' in Java grades
        to fix undefined reference errors.

library/Mercury.options:
        Set `--no-halt-at-warn' on io.m for now as compilers more than a week
        old will warn about the foreign_exports, even though they work.

diff --git a/library/Mercury.options b/library/Mercury.options
index 4ef18a2..c97775c 100644
--- a/library/Mercury.options
+++ b/library/Mercury.options
@@ -30,6 +30,10 @@ MCFLAGS-std_util += --no-halt-at-warn
 MCFLAGS-dir += --no-halt-at-warn
 MCFLAGS-exception += --no-halt-at-warn

+# Older versions of the compiler warn about `:- pragma foreign_export'
+# not being implemented for Java, which is a lie.
+MCFLAGS-io += --no-halt-at-warn
+
 # Ignore warnings about obsolete procedures from this module since
 # the entire module is obsolete.
 #
diff --git a/library/dir.m b/library/dir.m
index 1dd302e..93cc9c4 100644
--- a/library/dir.m
+++ b/library/dir.m
@@ -960,7 +960,7 @@ dir.make_directory(PathName, Result, !IO) :-
                 ""a file with that name already exists"");
         }
         if (dir.isDirectory()) {
-            Res = check_dir_accessibility_4_p_0(DirName);
+            Res = ML_check_dir_accessibility(DirName);
         } else {
             if (!dir.mkdirs()) {
                 throw new java.lang.RuntimeException(
@@ -969,7 +969,7 @@ dir.make_directory(PathName, Result, !IO) :-
             Res = make_mkdir_res_ok_0_f_0();
         }
     } catch (java.lang.Exception e) {
-        Res = make_mkdir_res_error_4_p_0(e);
+        Res = ML_make_mkdir_res_error(e);
     }
 ").

@@ -1123,23 +1123,23 @@ dir.make_single_directory(DirName, Result, !IO) :-
         java.io.File parent = newDir.getParentFile();

         if (parent == null) {
-            Result = make_mkdir_res_error_4_p_0(
+            Result = ML_make_mkdir_res_error(
                 new java.io.IOException(""can't create root directory""));
         } else if (!parent.exists()) {
-            Result = make_mkdir_res_error_4_p_0(
+            Result = ML_make_mkdir_res_error(
                 new java.io.IOException(""parent directory does not exist""));
         } else if (ErrorIfExists == 1 && newDir.exists()) {
-            Result = make_mkdir_res_error_4_p_0(
+            Result = ML_make_mkdir_res_error(
                 new java.io.IOException(""directory already exists""));
         } else {
             if (!newDir.mkdir()) {
                 throw new java.lang.RuntimeException(
                     ""make_single_directory failed"");
             }
-            Result = make_mkdir_res_ok_0_f_0();
+            Result = ML_make_mkdir_res_ok();
         }
     } catch (java.lang.Exception e) {
-        Result = make_mkdir_res_error_4_p_0(e);
+        Result = ML_make_mkdir_res_error(e);
     }
 ").

@@ -1165,6 +1165,8 @@ dir.make_single_directory(DirName, Result, !IO) :-
     "ML_make_mkdir_res_ok").
 :- pragma foreign_export("IL", (dir.make_mkdir_res_ok = out),
     "ML_make_mkdir_res_ok").
+:- pragma foreign_export("Java", (dir.make_mkdir_res_ok = out),
+    "ML_make_mkdir_res_ok").
 :- pragma foreign_export("Erlang", (dir.make_mkdir_res_ok = out),
     "ML_make_mkdir_res_ok").

@@ -1176,6 +1178,8 @@ dir.make_mkdir_res_ok = ok.
     "ML_make_mkdir_res_error").
 :- pragma foreign_export("IL", dir.make_mkdir_res_error(in, out, di, uo),
     "ML_make_mkdir_res_error").
+:- pragma foreign_export("Java", dir.make_mkdir_res_error(in, out, di, uo),
+    "ML_make_mkdir_res_error").
 :- pragma foreign_export("Erlang", dir.make_mkdir_res_error(in, out, di, uo),
     "ML_make_mkdir_res_error").

@@ -1189,6 +1193,8 @@ dir.make_mkdir_res_error(Error,
error(make_io_error(Msg)), !IO) :-
     "ML_make_mkdir_res_exists").
 :- pragma foreign_export("IL", dir.make_mkdir_res_exists(in, in, out, di, uo),
     "ML_make_mkdir_res_exists").
+:- pragma foreign_export("Java", dir.make_mkdir_res_exists(in, in,
out, di, uo),
+    "ML_make_mkdir_res_exists").
 :- pragma foreign_export("Erlang", dir.make_mkdir_res_exists(in, in,
out, di, uo),
     "ML_make_mkdir_res_exists").

@@ -1206,6 +1212,8 @@ dir.make_mkdir_res_exists(Error, DirName, Res, !IO) :-
     "ML_check_dir_accessibility").
 :- pragma foreign_export("IL", dir.check_dir_accessibility(in, out, di, uo),
     "ML_check_dir_accessibility").
+:- pragma foreign_export("Java", dir.check_dir_accessibility(in, out, di, uo),
+    "ML_check_dir_accessibility").
 :- pragma foreign_export("Erlang", dir.check_dir_accessibility(in,
out, di, uo),
     "ML_check_dir_accessibility").

@@ -1596,9 +1604,9 @@ dir.open(DirName, Res, !IO) :-
         java.lang.String[] fileList = (new java.io.File(DirName)).list();
         java.util.List list = java.util.Arrays.asList(fileList);

-        Result = read_first_entry_4_p_0(list.iterator());
+        Result = ML_dir_read_first_entry(list.iterator());
     } catch (java.lang.Exception e) {
-        Result = make_dir_open_result_error_4_p_0(e);
+        Result = ML_make_dir_open_result_error(e);
     }
 ").

@@ -1667,6 +1675,8 @@ dir.check_dir_readable(DirName, IsReadable,
Result, !IO) :-
     "ML_dir_read_first_entry").
 :- pragma foreign_export("IL", dir.read_first_entry(in, out, di, uo),
     "ML_dir_read_first_entry").
+:- pragma foreign_export("Java", dir.read_first_entry(in, out, di, uo),
+    "ML_dir_read_first_entry").
 :- pragma foreign_export("Erlang", dir.read_first_entry(in, out, di, uo),
     "ML_dir_read_first_entry").

@@ -1675,9 +1685,14 @@ dir.read_first_entry(Dir, Result, !IO) :-

 :- pred make_win32_dir_open_result_ok(dir.stream::in, c_pointer::in,
     io.result({dir.stream, string})::out, io::di, io::uo) is det.
-:- pragma foreign_export("C", make_win32_dir_open_result_ok(in, in,
out, di, uo),
+:- pragma foreign_export("C",
+    make_win32_dir_open_result_ok(in, in, out, di, uo),
+    "ML_make_win32_dir_open_result_ok").
+:- pragma foreign_export("IL",
+    make_win32_dir_open_result_ok(in, in, out, di, uo),
     "ML_make_win32_dir_open_result_ok").
-:- pragma foreign_export("IL", make_win32_dir_open_result_ok(in, in,
out, di, uo),
+:- pragma foreign_export("Java",
+    make_win32_dir_open_result_ok(in, in, out, di, uo),
     "ML_make_win32_dir_open_result_ok").

 make_win32_dir_open_result_ok(Dir, FirstFilePtr, Result, !IO) :-
@@ -1732,6 +1747,8 @@ copy_c_string(_) = _ :-
     "ML_make_dir_open_result_eof").
 :- pragma foreign_export("IL", (make_dir_open_result_eof = out),
     "ML_make_dir_open_result_eof").
+:- pragma foreign_export("Java", (make_dir_open_result_eof = out),
+    "ML_make_dir_open_result_eof").

 make_dir_open_result_eof = eof.

@@ -1741,6 +1758,8 @@ make_dir_open_result_eof = eof.
     "ML_make_dir_open_result_error").
 :- pragma foreign_export("IL", make_dir_open_result_error(in, out, di, uo),
     "ML_make_dir_open_result_error").
+:- pragma foreign_export("Java", make_dir_open_result_error(in, out, di, uo),
+    "ML_make_dir_open_result_error").
 :- pragma foreign_export("Erlang", make_dir_open_result_error(in, out, di, uo),
     "ML_make_dir_open_result_error").

diff --git a/library/io.m b/library/io.m
index 1ec7b8f..4840f60 100644
--- a/library/io.m
+++ b/library/io.m
@@ -3336,11 +3336,11 @@ io.check_file_accessibility(FileName,
AccessTypes, Result, !IO) :-
 "
     java.lang.String permissions = null;

-    if (access_types_includes_read_1_p_0((mercury.list.List_1) AccessTypes)) {
+    if (ML_access_types_includes_read((mercury.list.List_1) AccessTypes)) {
         permissions = ""read"";
     }

-    if (access_types_includes_write_1_p_0((mercury.list.List_1) AccessTypes)) {
+    if (ML_access_types_includes_write((mercury.list.List_1) AccessTypes)) {
         if (permissions == null) {
             permissions = ""write"";
         } else {
@@ -3348,7 +3348,7 @@ io.check_file_accessibility(FileName,
AccessTypes, Result, !IO) :-
         }
     }

-    if (access_types_includes_execute_1_p_0((mercury.list.List_1) AccessTypes))
+    if (ML_access_types_includes_execute((mercury.list.List_1) AccessTypes))
     {
         if (permissions == null) {
             permissions = ""execute"";
@@ -3362,10 +3362,10 @@ io.check_file_accessibility(FileName,
AccessTypes, Result, !IO) :-
             java.lang.System.getSecurityManager().checkPermission(
                 new java.io.FilePermission(FileName, permissions));
         }
-        Result = make_io_res_0_ok_0_f_0();
+        Result = ML_make_io_res_0_ok();
     }
     catch (java.lang.Exception e) {
-        Result = make_io_res_0_error_msg_1_f_0(e.getMessage());
+        Result = ML_make_io_res_0_error_msg(e.getMessage());
     }
 ").

@@ -3572,6 +3572,8 @@ check_directory_accessibility_dotnet(_, _, _, Res, !IO) :-
     "ML_access_types_includes_read").
 :- pragma foreign_export("IL", access_types_includes_read(in),
     "ML_access_types_includes_read").
+:- pragma foreign_export("Java", access_types_includes_read(in),
+    "ML_access_types_includes_read").
 :- pragma foreign_export("Erlang", access_types_includes_read(in),
     "ML_access_types_includes_read").

@@ -3583,6 +3585,8 @@ access_types_includes_read(Access) :-
     "ML_access_types_includes_write").
 :- pragma foreign_export("IL", access_types_includes_write(in),
     "ML_access_types_includes_write").
+:- pragma foreign_export("Java", access_types_includes_write(in),
+    "ML_access_types_includes_write").
 :- pragma foreign_export("Erlang", access_types_includes_write(in),
     "ML_access_types_includes_write").

@@ -3594,6 +3598,8 @@ access_types_includes_write(Access) :-
     "ML_access_types_includes_execute").
 :- pragma foreign_export("IL", access_types_includes_execute(in),
     "ML_access_types_includes_execute").
+:- pragma foreign_export("Java", access_types_includes_execute(in),
+    "ML_access_types_includes_execute").
 :- pragma foreign_export("Erlang", access_types_includes_execute(in),
     "ML_access_types_includes_execute").

@@ -3605,6 +3611,8 @@ access_types_includes_execute(Access) :-
     "ML_make_io_res_0_ok").
 :- pragma foreign_export("IL", (make_io_res_0_ok = out),
     "ML_make_io_res_0_ok").
+:- pragma foreign_export("Java", (make_io_res_0_ok = out),
+    "ML_make_io_res_0_ok").
 :- pragma foreign_export("Erlang", (make_io_res_0_ok = out),
     "ML_make_io_res_0_ok").

@@ -3616,6 +3624,8 @@ make_io_res_0_ok = ok.
     "ML_make_io_res_0_error").
 :- pragma foreign_export("IL", make_io_res_0_error(in, in, out, di, uo),
     "ML_make_io_res_0_error").
+:- pragma foreign_export("Java", make_io_res_0_error(in, in, out, di, uo),
+    "ML_make_io_res_0_error").
 :- pragma foreign_export("Erlang", make_io_res_0_error(in, in, out, di, uo),
     "ML_make_io_res_0_error").

@@ -3627,6 +3637,8 @@ make_io_res_0_error(Error, Msg0,
error(make_io_error(Msg)), !IO) :-
     "ML_make_io_res_0_error_msg").
 :- pragma foreign_export("IL", (make_io_res_0_error_msg(in) = out),
     "ML_make_io_res_0_error_msg").
+:- pragma foreign_export("Java", (make_io_res_0_error_msg(in) = out),
+    "ML_make_io_res_0_error_msg").

 make_io_res_0_error_msg(Msg) = error(make_io_error(Msg)).

@@ -3635,6 +3647,8 @@ make_io_res_0_error_msg(Msg) = error(make_io_error(Msg)).
     "ML_make_io_res_1_ok_file_type").
 :- pragma foreign_export("IL", (make_io_res_1_ok_file_type(in) = out),
     "ML_make_io_res_1_ok_file_type").
+:- pragma foreign_export("Java", (make_io_res_1_ok_file_type(in) = out),
+    "ML_make_io_res_1_ok_file_type").
 :- pragma foreign_export("Erlang", (make_io_res_1_ok_file_type(in) = out),
     "ML_make_io_res_1_ok_file_type").

@@ -3648,6 +3662,9 @@ make_io_res_1_ok_file_type(FileType) = ok(FileType).
 :- pragma foreign_export("IL",
     make_io_res_1_error_file_type(in, in, out, di, uo),
     "ML_make_io_res_1_error_file_type").
+:- pragma foreign_export("Java",
+    make_io_res_1_error_file_type(in, in, out, di, uo),
+    "ML_make_io_res_1_error_file_type").
 :- pragma foreign_export("Erlang",
     make_io_res_1_error_file_type(in, in, out, di, uo),
     "ML_make_io_res_1_error_file_type").
@@ -3658,6 +3675,8 @@ make_io_res_1_error_file_type(Error, Msg0,
error(make_io_error(Msg)), !IO) :-
 :- func make_io_res_1_ok_string(string) = io.res(string).
 :- pragma foreign_export("C", (make_io_res_1_ok_string(in) = out),
     "ML_make_io_res_1_ok_string").
+:- pragma foreign_export("Java", (make_io_res_1_ok_string(in) = out),
+    "ML_make_io_res_1_ok_string").
 :- pragma foreign_export("Erlang", (make_io_res_1_ok_string(in) = out),
     "ML_make_io_res_1_ok_string").

@@ -3668,6 +3687,9 @@ make_io_res_1_ok_string(String) = ok(String).
 :- pragma foreign_export("C",
     make_io_res_1_error_string(in, in, out, di, uo),
     "ML_make_io_res_1_error_string").
+:- pragma foreign_export("Java",
+    make_io_res_1_error_string(in, in, out, di, uo),
+    "ML_make_io_res_1_error_string").
 :- pragma foreign_export("Erlang",
     make_io_res_1_error_string(in, in, out, di, uo),
     "ML_make_io_res_1_error_string").
@@ -4512,6 +4534,8 @@ io.write_many(Stream, [f(F) | Rest], !IO) :-
     "ML_io_print_to_cur_stream").
 :- pragma foreign_export("IL", io.print(in, di, uo),
     "ML_io_print_to_cur_stream").
+:- pragma foreign_export("Java", io.print(in, di, uo),
+    "ML_io_print_to_cur_stream").

 io.print(Term, !IO) :-
     io.output_stream(Stream, !IO),
@@ -4533,6 +4557,8 @@ io.print_cc(Term, !IO) :-
     "ML_io_print_to_stream").
 :- pragma foreign_export("IL", io.print_to_stream(in, in, di, uo),
     "ML_io_print_to_stream").
+:- pragma foreign_export("Java", io.print_to_stream(in, in, di, uo),
+    "ML_io_print_to_stream").

 io.print_to_stream(Stream, Term, !IO) :-
     io.print(output_stream(Stream), canonicalize, Term, !IO).
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list