[m-rev.] for review: library additions for erlang

Peter Wang wangp at students.csse.unimelb.edu.au
Mon Jul 30 17:48:24 AEST 2007


Just the erlang_conf.m addition requires review.


Branches: main

Implement more standard library predicates for Erlang.

configure.in:
library/Mercury.options:
library/erlang_conf.m.in:
	Add a module erlang_conf.m which is generated from erlang_conf.m.in to
	contain the VERSION and FULLARCH constants.

library/library.m:
	Include erlang_conf.m and implement library.version.

library/dir.m:
	Implement dir.make_directory, dir.make_single_directory.

library/io.m:
	Implement io.file_modification_time and io.file_type.

	Turn mercury_current_{text,binary}_{input,output} functions into
	macros to avoid an intermodule function call each time we want to get
	a current stream.

	Fix io.call_system in the case that the called command produced no
	output.

	Delete an XXX from the Erlang implementation of io.rename_file,
	which behaves properly (it was an misunderstanding).

library/time.m:
	Fix time.c_time and time.c_difftime to work with {Date,Time} tuples
	instead of just the Time part.


Index: configure.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/configure.in,v
retrieving revision 1.495
diff -u -r1.495 configure.in
--- configure.in	20 Jul 2007 01:21:59 -0000	1.495
+++ configure.in	30 Jul 2007 07:22:27 -0000
@@ -4570,6 +4570,7 @@
 bindist/bindist.INSTALL bindist/bindist.Makefile
 tools/lmc tools/dotime runtime/mercury_dotnet.cs java/runtime/Constants.java
 java/runtime/Native.java
+library/erlang_conf.m
 compiler/COMP_FLAGS
 library/LIB_FLAGS
 mdbcomp/MDBCOMP_FLAGS
Index: library/Mercury.options
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/Mercury.options,v
retrieving revision 1.27
diff -u -r1.27 Mercury.options
--- library/Mercury.options	20 Jul 2007 01:22:04 -0000	1.27
+++ library/Mercury.options	30 Jul 2007 07:22:27 -0000
@@ -42,6 +42,7 @@
 MCFLAGS-string += --no-warn-unknown-format-calls
 
 MCFLAGS-erlang_builtin += --no-warn-nothing-exported
+MCFLAGS-erlang_conf += --no-warn-nothing-exported
 MCFLAGS-mer_std += --no-warn-nothing-exported
 
 # Avoid warnings about insts with non-existent function symbols in their
Index: library/dir.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/dir.m,v
retrieving revision 1.40
diff -u -r1.40 dir.m
--- library/dir.m	21 Mar 2007 22:30:23 -0000	1.40
+++ library/dir.m	30 Jul 2007 07:22:27 -0000
@@ -905,6 +905,21 @@
     }
 ").
 
+:- pragma foreign_proc("Erlang",
+    dir.make_directory(DirName::in, Res::out, _IO0::di, _IO::uo),
+    [may_call_mercury, promise_pure, tabled_for_io, thread_safe, terminates],
+"
+    % filelib:ensure_dir makes all the parent directories.
+    case filelib:ensure_dir(DirName) of
+        ok ->
+            ErrorIfExists = 0,
+            Res = mercury__dir:'ML_make_single_directory_2'(ErrorIfExists,
+                DirName);
+        {error, Reason} ->
+            Res = mercury__dir:'ML_make_mkdir_res_error'(Reason)
+    end
+").
+
 :- pred can_implement_make_directory is semidet.
 
 can_implement_make_directory :- semidet_fail.
@@ -936,10 +951,20 @@
     succeeded = true;
 "
 ).
+:- pragma foreign_proc("Erlang",
+    can_implement_make_directory,
+    [will_not_call_mercury, promise_pure, thread_safe],
+"
+    SUCCESS_INDICATOR = true
+").
 
 dir.make_single_directory(DirName, Result, !IO) :-
     dir.make_single_directory_2(1, DirName, Result, !IO).
 
+:- pragma foreign_export("Erlang",
+    dir.make_single_directory_2(in, in, out, di, uo),
+    "ML_make_single_directory_2").
+
 :- pred dir.make_single_directory_2(int::in, string::in, io.res::out,
     io::di, io::uo) is det.
 
@@ -1048,11 +1073,28 @@
     }
 ").
 
+:- pragma foreign_proc("Erlang",
+    dir.make_single_directory_2(ErrorIfExists::in, DirName::in,
+        Result::out, _IO0::di, _IO::uo),
+    [may_call_mercury, promise_pure, tabled_for_io, thread_safe, terminates],
+"
+    case file:make_dir(DirName) of
+        ok ->
+            Result = mercury__dir:'ML_make_mkdir_res_ok'();
+        {error, eexist} when ErrorIfExists =:= 0 ->
+            Result = mercury__dir:'ML_make_mkdir_res_exists'(eexist, DirName);
+        {error, Reason} ->
+            Result = mercury__dir:'ML_make_mkdir_res_error'(Reason)
+    end
+").
+
 :- func dir.make_mkdir_res_ok = io.res.
 :- pragma foreign_export("C", (dir.make_mkdir_res_ok = out),
     "ML_make_mkdir_res_ok").
 :- pragma foreign_export("IL", (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").
 
 dir.make_mkdir_res_ok = ok.
 
@@ -1062,6 +1104,8 @@
     "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("Erlang", dir.make_mkdir_res_error(in, out, di, uo),
+    "ML_make_mkdir_res_error").
 
 dir.make_mkdir_res_error(Error, error(make_io_error(Msg)), !IO) :-
     io.make_maybe_win32_err_msg(Error, "dir.make_directory failed: ",
@@ -1073,6 +1117,8 @@
     "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("Erlang", dir.make_mkdir_res_exists(in, in, out, di, uo),
+    "ML_make_mkdir_res_exists").
 
 dir.make_mkdir_res_exists(Error, DirName, Res, !IO) :-
     io.file_type(yes, DirName, TypeResult, !IO),
@@ -1088,6 +1134,8 @@
     "ML_check_dir_accessibility").
 :- pragma foreign_export("IL", 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").
 
 dir.check_dir_accessibility(DirName, Res, !IO) :-
     % Check whether we can read and write the directory.
Index: library/io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.399
diff -u -r1.399 io.m
--- library/io.m	18 Jul 2007 05:23:30 -0000	1.399
+++ library/io.m	30 Jul 2007 07:22:27 -0000
@@ -2841,6 +2841,24 @@
     Time = date;
 ").
 
+:- pragma foreign_proc("Erlang",
+    io.file_modification_time_2(FileName::in, Status::out, Msg::out,
+        Time::out, _IO0::di, _IO::uo),
+    [will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
+"
+    case filelib:last_modified(FileName) of
+        {YMD, HMS} ->
+            Status = 1,
+            Msg = """",
+            % time_t in Erlang is in UTC.
+            Time = {time_t, erlang:localtime_to_universaltime({YMD, HMS})};
+        _ ->
+            Status = 0,
+            Msg = ""filelib:last_modified failed"",
+            Time = -1
+    end
+").
+
 %-----------------------------------------------------------------------------%
 
 io.file_type(FollowSymLinks, FileName, MaybeType, !IO) :-
@@ -2878,6 +2896,12 @@
 "
     succeeded = true;
 ").
+:- pragma foreign_proc("Erlang",
+    file_type_implemented,
+    [will_not_call_mercury, promise_pure, thread_safe],
+"
+    SUCCESS_INDICATOR = true
+").
 
 :- pred io.file_type_2(int::in, string::in, io.res(io.file_type)::out,
     io::di, io::uo) is det.
@@ -3068,6 +3092,44 @@
     }
 ").
 
+:- pragma foreign_decl("Erlang", local, "
+-include_lib(""kernel/include/file.hrl"").
+").
+
+:- pragma foreign_proc("Erlang",
+    io.file_type_2(FollowSymLinks::in, FileName::in,
+        Result::out, _IO0::di, _IO::uo),
+    [may_call_mercury, promise_pure, tabled_for_io, thread_safe, terminates],
+"
+    case FollowSymLinks of
+        0 -> Read = fun file:read_link_info/1;
+        1 -> Read = fun file:read_file_info/1
+    end,
+    case Read(FileName) of
+        {ok, FileInfo} ->
+            #file_info{type = Type} = FileInfo,
+            case Type of
+                device ->
+                    % XXX It may be a block device, but Erlang doesn't
+                    % distinguish between character and block devices.
+                    Result = mercury__io:'ML_make_io_res_1_ok_file_type'(
+                        mercury__io:'ML_file_type_character_device'());
+                directory ->
+                    Result = mercury__io:'ML_make_io_res_1_ok_file_type'(
+                        mercury__io:'ML_file_type_directory'());
+                regular ->
+                    Result = mercury__io:'ML_make_io_res_1_ok_file_type'(
+                        mercury__io:'ML_file_type_regular'());
+                other ->
+                    Result = mercury__io:'ML_make_io_res_1_ok_file_type'(
+                        mercury__io:'ML_file_type_unknown'())
+            end;
+        {error, Reason} ->
+            Result = mercury__io:'ML_make_io_res_1_error_file_type'(Reason,
+                ""io.file_type failed: "")
+    end
+").
+
 :- func file_type_character_device = file_type.
 :- func file_type_block_device = file_type.
 :- func file_type_fifo = file_type.
@@ -3096,6 +3158,8 @@
     "ML_file_type_character_device").
 :- pragma foreign_export("IL", file_type_character_device = out,
     "ML_file_type_character_device").
+:- pragma foreign_export("Erlang", file_type_character_device = out,
+    "ML_file_type_character_device").
 :- pragma foreign_export("C", file_type_block_device = out,
     "ML_file_type_block_device").
 :- pragma foreign_export("IL", file_type_block_device = out,
@@ -3108,6 +3172,8 @@
     "ML_file_type_directory").
 :- pragma foreign_export("IL", file_type_directory = out,
     "ML_file_type_directory").
+:- pragma foreign_export("Erlang", file_type_directory = out,
+    "ML_file_type_directory").
 :- pragma foreign_export("C", file_type_socket = out,
     "ML_file_type_socket").
 :- pragma foreign_export("IL", file_type_socket = out,
@@ -3120,6 +3186,8 @@
     "ML_file_type_regular").
 :- pragma foreign_export("IL", file_type_regular = out,
     "ML_file_type_regular").
+:- pragma foreign_export("Erlang", file_type_regular = out,
+    "ML_file_type_regular").
 :- pragma foreign_export("C", file_type_message_queue = out,
     "ML_file_type_message_queue").
 :- pragma foreign_export("IL", file_type_message_queue = out,
@@ -3136,6 +3204,8 @@
     "ML_file_type_unknown").
 :- pragma foreign_export("IL", file_type_unknown = out,
     "ML_file_type_unknown").
+:- pragma foreign_export("Erlang", file_type_unknown = out,
+    "ML_file_type_unknown").
 
 %-----------------------------------------------------------------------------%
 
@@ -3395,6 +3465,8 @@
     "ML_access_types_includes_read").
 :- pragma foreign_export("IL", access_types_includes_read(in),
     "ML_access_types_includes_read").
+:- pragma foreign_export("Erlang", access_types_includes_read(in),
+    "ML_access_types_includes_read").
 
 access_types_includes_read(Access) :-
     list.member(read, Access).
@@ -3404,6 +3476,8 @@
     "ML_access_types_includes_write").
 :- pragma foreign_export("IL", access_types_includes_write(in),
     "ML_access_types_includes_write").
+:- pragma foreign_export("Erlang", access_types_includes_write(in),
+    "ML_access_types_includes_write").
 
 access_types_includes_write(Access) :-
     list.member(write, Access).
@@ -3413,6 +3487,8 @@
     "ML_access_types_includes_execute").
 :- pragma foreign_export("IL", access_types_includes_execute(in),
     "ML_access_types_includes_execute").
+:- pragma foreign_export("Erlang", access_types_includes_execute(in),
+    "ML_access_types_includes_execute").
 
 access_types_includes_execute(Access) :-
     list.member(execute, Access).
@@ -3422,6 +3498,8 @@
     "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("Erlang", (make_io_res_0_ok = out),
+    "ML_make_io_res_0_ok").
 
 make_io_res_0_ok = ok.
 
@@ -3448,6 +3526,8 @@
     "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("Erlang", (make_io_res_1_ok_file_type(in) = out),
+    "ML_make_io_res_1_ok_file_type").
 
 make_io_res_1_ok_file_type(FileType) = ok(FileType).
 
@@ -3459,6 +3539,9 @@
 :- 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("Erlang",
+    make_io_res_1_error_file_type(in, in, out, di, uo),
+    "ML_make_io_res_1_error_file_type").
 
 make_io_res_1_error_file_type(Error, Msg0, error(make_io_error(Msg)), !IO) :-
     io.make_err_msg(Error, Msg0, Msg, !IO).
@@ -6130,10 +6213,6 @@
     mercury_seek/2,
 
     % We may want to inline the following by hand to avoid inter-module calls.
-    mercury_current_text_input/0,
-    mercury_current_text_output/0,
-    mercury_current_binary_input/0,
-    mercury_current_binary_output/0,
     mercury_set_current_text_input/1,
     mercury_set_current_text_output/1,
     mercury_set_current_binary_input/1,
@@ -6141,6 +6220,17 @@
 ]).
 ").
 
+:- pragma foreign_decl("Erlang", "
+
+    % Avoid an intermodule function call every time we want to get the current
+    % stream.
+    %
+-define(ML_get_current_text_input, get('ML_io_current_text_input')).
+-define(ML_get_current_text_output, get('ML_io_current_text_output')).
+-define(ML_get_current_binary_input, get('ML_io_current_binary_input')).
+-define(ML_get_current_binary_output, get('ML_io_current_binary_output')).
+").
+
 :- pragma foreign_code("Erlang", "
 
     % For each open file we have a process running in the background.
@@ -6359,18 +6449,6 @@
             end
     end.
 
-mercury_current_text_input() ->
-    get('ML_io_current_text_input').
-
-mercury_current_text_output() ->
-    get('ML_io_current_text_output').
-
-mercury_current_binary_input() ->
-    get('ML_io_current_binary_input').
-
-mercury_current_binary_output() ->
-    get('ML_io_current_binary_output').
-
 mercury_set_current_text_input(Stream) ->
     put('ML_io_current_text_input', Stream).
 
@@ -7369,7 +7447,7 @@
     [will_not_call_mercury, promise_pure, thread_safe, tabled_for_io,
         terminates],
 "
-    Stream = mercury__io:mercury_current_text_output(),
+    Stream = ?ML_get_current_text_output,
     mercury__io:mercury_write_string(Stream, Message)
 ").
 :- pragma foreign_proc("Erlang",
@@ -7377,7 +7455,7 @@
     [will_not_call_mercury, promise_pure, thread_safe, tabled_for_io,
         terminates],
 "
-    Stream = mercury__io:mercury_current_text_output(),
+    Stream = ?ML_get_current_text_output,
     mercury__io:mercury_write_char(Stream, Character)
 ").
 :- pragma foreign_proc("Erlang",
@@ -7385,7 +7463,7 @@
     [will_not_call_mercury, promise_pure, thread_safe, tabled_for_io,
         terminates],
 "
-    Stream = mercury__io:mercury_current_text_output(),
+    Stream = ?ML_get_current_text_output,
     mercury__io:mercury_write_int(Stream, Val)
 ").
 
@@ -7393,7 +7471,7 @@
     io.write_byte(Byte::in, _IO0::di, _IO::uo),
     [may_call_mercury, promise_pure, thread_safe, tabled_for_io, terminates],
 "
-    Stream = mercury__io:mercury_current_binary_output(),
+    Stream = ?ML_get_current_binary_output,
     mercury__io:mercury_write_char(Stream, Byte)
 ").
 
@@ -7401,7 +7479,7 @@
     io.write_bytes(Bytes::in, _IO0::di, _IO::uo),
     [may_call_mercury, promise_pure, thread_safe, tabled_for_io, terminates],
 "
-    Stream = mercury__io:mercury_current_binary_output(),
+    Stream = ?ML_get_current_binary_output,
     mercury__io:mercury_write_string(Stream, Bytes)
 ").
 
@@ -7410,7 +7488,7 @@
     [will_not_call_mercury, promise_pure, thread_safe, tabled_for_io,
         terminates],
 "
-    Stream = mercury__io:mercury_current_text_output(),
+    Stream = ?ML_get_current_text_output,
     mercury__io:mercury_sync(Stream)
 ").
 :- pragma foreign_proc("Erlang",
@@ -7418,7 +7496,7 @@
     [will_not_call_mercury, promise_pure, thread_safe, tabled_for_io,
         terminates],
 "
-    Stream = mercury__io:mercury_current_binary_output(),
+    Stream = ?ML_get_current_binary_output,
     mercury__io:mercury_sync(Stream)
 ").
 
@@ -8618,35 +8696,35 @@
     io.input_stream_2(Stream::out, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    Stream = mercury__io:mercury_current_text_input()
+    Stream = ?ML_get_current_text_input
 ").
 
 :- pragma foreign_proc("Erlang",
     io.output_stream_2(Stream::out, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    Stream = mercury__io:mercury_current_text_output()
+    Stream = ?ML_get_current_text_output
 ").
 
 :- pragma foreign_proc("Erlang",
     io.binary_input_stream_2(Stream::out, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    Stream = mercury__io:mercury_current_binary_input()
+    Stream = ?ML_get_current_binary_input
 ").
 
 :- pragma foreign_proc("Erlang",
     io.binary_output_stream_2(Stream::out, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    Stream = mercury__io:mercury_current_binary_output()
+    Stream = ?ML_get_current_binary_output
 ").
 
 :- pragma foreign_proc("Erlang",
     io.get_line_number(LineNum::out, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    Stream = mercury__io:mercury_current_text_input(),
+    Stream = ?ML_get_current_text_input,
     LineNum = mercury__io:mercury_get_line_number(Stream)
 ").
 
@@ -8661,7 +8739,7 @@
     io.set_line_number(LineNum::in, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    Stream = mercury__io:mercury_current_text_input(),
+    Stream = ?ML_get_current_text_input,
     mercury__io:mercury_set_line_number(Stream, LineNum)
 ").
 
@@ -8676,7 +8754,7 @@
     io.get_output_line_number(LineNum::out, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    Stream = mercury__io:mercury_current_text_output(),
+    Stream = ?ML_get_current_text_output,
     LineNum = mercury__io:mercury_get_line_number(Stream)
 ").
 
@@ -8691,7 +8769,7 @@
     io.set_output_line_number(LineNum::in, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    Stream = mercury__io:mercury_current_text_output(),
+    Stream = ?ML_get_current_text_output,
     mercury__io:mercury_set_line_number(Stream, LineNum)
 ").
 
@@ -8706,7 +8784,7 @@
     io.set_input_stream_2(NewStream::in, OutStream::out, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    OutStream = mercury__io:mercury_current_text_input(),
+    OutStream = ?ML_get_current_text_input,
     mercury__io:mercury_set_current_text_input(NewStream)
 ").
 
@@ -8714,7 +8792,7 @@
     io.set_output_stream_2(NewStream::in, OutStream::out, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    OutStream = mercury__io:mercury_current_text_output(),
+    OutStream = ?ML_get_current_text_output,
     mercury__io:mercury_set_current_text_output(NewStream)
 ").
 
@@ -8723,7 +8801,7 @@
         _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    OutStream = mercury__io:mercury_current_binary_input(),
+    OutStream = ?ML_get_current_binary_input,
     mercury__io:mercury_set_current_binary_input(NewStream)
 ").
 
@@ -8732,7 +8810,7 @@
         _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    OutStream = mercury__io:mercury_current_binary_output(),
+    OutStream = ?ML_get_current_binary_output,
     mercury__io:mercury_set_current_binary_output(NewStream)
 ").
 
@@ -9095,11 +9173,18 @@
     [will_not_call_mercury, promise_pure, tabled_for_io, thread_safe,
         does_not_affect_liveness],
 "
-    % XXX this is shit
+    % XXX this is bad
+    % 1. output doesn't come out until process finishes
+    % 2. error code is got in an inefficient way
+    %
     OutputCode = os:cmd(Command ++ ""; echo -n $?""),
-    NL = string:rchr(OutputCode, $\\n),
-    {Output, [$\\n, Code]} = lists:split(NL - 1, OutputCode),
-    io:put_chars(Output),
+    case string:rchr(OutputCode, $\\n) of
+        0 ->
+            Code = OutputCode;
+        NL ->
+            {Output, [$\\n, Code]} = lists:split(NL - 1, OutputCode),
+            io:put_chars(Output)
+    end,
     {Status, []} = string:to_integer(Code),
     case Status =:= 0 of
         true ->
@@ -10067,8 +10152,6 @@
         RetStr::out, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io, thread_safe],
 "
-    % XXX it is not enough to specify destination directory
-    % see erl -man file
     case file:rename(OldFileName, NewFileName) of
         ok ->
             RetVal = 0,
Index: library/library.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/library.m,v
retrieving revision 1.110
diff -u -r1.110 library.m
--- library/library.m	12 Jun 2007 06:53:58 -0000	1.110
+++ library/library.m	30 Jul 2007 07:22:27 -0000
@@ -145,6 +145,7 @@
 % NOTE: changes to this list may need to be reflected in mdbcomp/prim_data.m.
 %
 :- import_module erlang_builtin.
+:- import_module erlang_conf.
 :- import_module erlang_rtti_implementation.
 :- import_module mutvar.
 :- import_module par_builtin.
@@ -190,6 +191,13 @@
         + mercury.runtime.Constants.MR_FULLARCH;
 ").
 
+:- pragma foreign_proc("Erlang",
+    library.version(Version::out),
+    [will_not_call_mercury, promise_pure, thread_safe],
+"
+    Version = ?MR_VERSION ++ "" configured for "" ++ ?MR_FULLARCH
+").
+
 %---------------------------------------------------------------------------%
 
 mercury_std_library_module("array").
@@ -216,6 +224,7 @@
 mercury_std_library_module("enum").
 mercury_std_library_module("eqvclass").
 mercury_std_library_module("erlang_builtin").
+mercury_std_library_module("erlang_conf").
 mercury_std_library_module("erlang_rtti_implementation").
 mercury_std_library_module("exception").
 mercury_std_library_module("float").
Index: library/time.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/time.m,v
retrieving revision 1.58
diff -u -r1.58 time.m
--- library/time.m	30 May 2007 08:16:09 -0000	1.58
+++ library/time.m	30 Jul 2007 07:22:27 -0000
@@ -458,7 +458,7 @@
     time.c_time(Ret::out, _IO0::di, _IO::uo),
     [will_not_call_mercury, promise_pure, tabled_for_io],
 "
-    Ret = time()
+    Ret = erlang:universaltime()
 ").
 
 :- pred time.time_t_is_invalid(time_t_rep::in) is semidet.
@@ -481,6 +481,12 @@
 "
     succeeded = false;
 ").
+:- pragma foreign_proc("Erlang",
+    time.time_t_is_invalid(_Val::in),
+    [will_not_call_mercury, promise_pure, thread_safe],
+"
+    SUCCESS_INDICATOR = false
+").
 
 %-----------------------------------------------------------------------------%
 
@@ -515,7 +521,9 @@
     time.c_difftime(T1::in, T0::in, Diff::out),
     [will_not_call_mercury, promise_pure, thread_safe],
 "
-    Diff = float(calendar:time_to_seconds(T1) - calendar:time_to_seconds(T0))
+    S0 = calendar:datetime_to_gregorian_seconds(T0),
+    S1 = calendar:datetime_to_gregorian_seconds(T1),
+    Diff = float(S1 - S0)
 ").
 
 %-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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