[m-rev.] for review: implement io__file_modification_time_2 in C#
Peter Ross
pro at missioncriticalit.com
Tue Oct 28 05:11:01 AEDT 2003
Hi,
For stayl to review.
===================================================================
Estimated hours taken: 3
Branches: main
library/io.m:
Implement io__file_modification_time_2 in C#.
library/time.m:
Implement most of this module in C#.
Add construct_time_t to the interface for use by
io__file_modification_time_2.
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.308
diff -u -r1.308 io.m
--- library/io.m 25 Oct 2003 14:21:29 -0000 1.308
+++ library/io.m 27 Oct 2003 18:07:41 -0000
@@ -2394,7 +2394,25 @@
MR_update_io(IO0, IO);
}").
-
+:- pragma foreign_proc("C#",
+ 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],
+"{
+ try {
+ System.DateTime t = System.IO.File.GetLastWriteTime(FileName);
+ Time = mercury.time.mercury_code.construct_time_t_2(t);
+ Msg = """";
+ Status = 1;
+
+ } catch (System.Exception e) {
+ Msg = ""GetLastWriteTime() failed: "" + e.Message;
+ Status = 0;
+ }
+}").
+
+
+
%-----------------------------------------------------------------------------%
io__file_type(FollowSymLinks, FileName, MaybeType) -->
Index: library/time.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/time.m,v
retrieving revision 1.35
diff -u -r1.35 time.m
--- library/time.m 19 Aug 2003 07:48:20 -0000 1.35
+++ library/time.m 27 Oct 2003 18:07:41 -0000
@@ -211,6 +211,8 @@
:- type time_t_rep ---> time_t_rep(c_pointer).
:- pragma foreign_type("C", time_t_rep, "time_t")
where comparison is compare_time_t_reps.
+:- pragma foreign_type(il, time_t_rep, "valuetype [mscorlib]System.DateTime")
+ where comparison is compare_time_t_reps.
:- pred compare_time_t_reps(comparison_result::uo,
time_t_rep::in, time_t_rep::in) is det.
@@ -239,6 +241,12 @@
Ret = (MR_Integer) clock();
MR_update_io(IO0, IO);
}").
+:- pragma foreign_proc("C#", time__c_clock(Ret::out, _IO0::di, _IO::uo),
+ [will_not_call_mercury, promise_pure, tabled_for_io],
+"{
+ // XXX Ticks is long in .NET!
+ Ret = (int) System.DateTime.Now.Ticks;
+}").
%-----------------------------------------------------------------------------%
@@ -255,6 +263,12 @@
"{
Ret = (MR_Integer) CLOCKS_PER_SEC;
}").
+:- pragma foreign_proc("C#", time__c_clocks_per_sec(Ret::out),
+ [will_not_call_mercury, promise_pure],
+"{
+ // XXX TicksPerSecond is long in .NET!
+ Ret = (int) System.TimeSpan.TicksPerSecond;
+}").
%-----------------------------------------------------------------------------%
@@ -344,6 +358,12 @@
Ret = time(NULL);
MR_update_io(IO0, IO);
}").
+:- pragma foreign_proc("C#",
+ time__c_time(Ret::out, _IO0::di, _IO::uo),
+ [will_not_call_mercury, promise_pure, tabled_for_io],
+"{
+ Ret = System.DateTime.Now;
+}").
:- pred time__time_t_is_invalid(time_t_rep).
:- mode time__time_t_is_invalid(in) is semidet.
@@ -354,6 +374,12 @@
"{
SUCCESS_INDICATOR = (Val == -1);
}").
+:- pragma foreign_proc("C#",
+ time__time_t_is_invalid(_Val::in),
+ [will_not_call_mercury, promise_pure],
+"{
+ SUCCESS_INDICATOR = false;
+}").
@@ -373,6 +399,14 @@
"{
Diff = (MR_Float) difftime(T1, T0);
}").
+:- pragma foreign_proc("C#",
+ time__c_difftime(T1::in, T0::in, Diff::out),
+ [will_not_call_mercury, promise_pure],
+"{
+ System.TimeSpan span;
+ span = T1 - T0;
+ Diff = span.Ticks / System.TimeSpan.TicksPerSecond;
+}").
%-----------------------------------------------------------------------------%
@@ -411,6 +445,25 @@
YD = (MR_Integer) p->tm_yday;
N = (MR_Integer) p->tm_isdst;
}").
+:- pragma foreign_proc("C#",
+ time__c_localtime(Time::in, Yr::out, Mnt::out, MD::out, Hrs::out,
+ Min::out, Sec::out, YD::out, WD::out, N::out),
+ [will_not_call_mercury, promise_pure],
+"{
+ System.DateTime t = Time.ToLocalTime();
+
+ // we don't handle leap seconds
+ Sec = t.Second;
+ Min = t.Minute;
+ Hrs = t.Hour;
+ Mnt = t.Month - 1;
+ Yr = t.Year - 1900;
+ WD = (int) t.DayOfWeek;
+ MD = t.Day;
+ YD = t.DayOfYear - 1;
+ // XXX Don't know how to determine if in DST.
+ N = -1;
+}").
%:- func time__gmtime(time_t) = tm.
@@ -448,6 +501,25 @@
YD = (MR_Integer) p->tm_yday;
N = (MR_Integer) p->tm_isdst;
}").
+:- pragma foreign_proc("C#",
+ time__c_gmtime(Time::in, Yr::out, Mnt::out, MD::out, Hrs::out,
+ Min::out, Sec::out, YD::out, WD::out, N::out),
+ [will_not_call_mercury, promise_pure],
+"{
+ System.DateTime t = Time.ToUniversalTime();
+
+ // we don't handle leap seconds
+ Sec = t.Second;
+ Min = t.Minute;
+ Hrs = t.Hour;
+ Mnt = t.Month - 1;
+ Yr = t.Year - 1900;
+ WD = (int) t.DayOfWeek;
+ MD = t.Day;
+ YD = t.DayOfYear - 1;
+ // XXX Don't know how to determine if in DST.
+ N = -1;
+}").
:- func int_to_maybe_dst(int) = maybe(dst).
@@ -491,6 +563,14 @@
Time = mktime(&t);
}").
+:- pragma foreign_proc("C#",
+ time__c_mktime(Yr::in, Mnt::in, MD::in, Hrs::in, Min::in, Sec::in,
+ _YD::in, _WD::in, _N::in, Time::out),
+ [will_not_call_mercury, promise_pure],
+ "{
+ // We don't use YD, WD and N.
+ Time = new System.DateTime(Yr + 1900, Mnt + 1, MD, Hrs, Min, Sec);
+}").
:- func maybe_dst_to_int(maybe(dst)) = int.
@@ -537,6 +617,18 @@
MR_make_aligned_string_copy(Str, s);
}").
+:- pragma foreign_proc("C#",
+ time__c_asctime(Yr::in, Mnt::in, MD::in, Hrs::in, Min::in, Sec::in,
+ _YD::in, _WD::in, _N::in, Str::out),
+ [will_not_call_mercury, promise_pure],
+"{
+ // We don't use YD, WD and N.
+ System.DateTime Time = new System.DateTime(Yr + 1900, Mnt + 1, MD,
+ Hrs, Min, Sec);
+
+ // XXX this may need to be formatted differently.
+ Str = Time.ToString();
+}").
%-----------------------------------------------------------------------------%
@@ -561,6 +653,24 @@
MR_make_aligned_string_copy(Str, s);
}").
+:- pragma foreign_proc("C",
+ time__c_ctime(Time::in, Str::out),
+ [will_not_call_mercury, promise_pure],
+"{
+ // XXX this may need to be formatted differently.
+ Str = Time.ToString();
+}").
+
+%-----------------------------------------------------------------------------%
+
+% XXX This needs to be in the interface because pragma export doesn't work yet
+% on the .NET backend and io.m needs to access this.
+:- interface.
+:- type time_t_rep.
+:- func construct_time_t(time_t_rep) = time_t.
+:- implementation.
+:- pragma export(construct_time_t(in) = out, "ML_construct_time_t").
+construct_time_t(T) = time_t(T).
%-----------------------------------------------------------------------------%
:- end_module time.
--
Peter Ross
Software Engineer (Work) +32 2 757 10 15
Mission Critical (Mobile) +32 485 482 559
--------------------------------------------------------------------------
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