[m-rev.] trivial diff: minor fixes for stdlib

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Mar 6 16:47:26 AEDT 2007


Estimated hours taken: 0.2
Branches: main

Formatting and style fixes for standard library modules.

Fix a bunch of minor problems, e.g. unnecessary module imports.

library/bitmap.m:
 	s/memcpy/MR_memcpy/ in a spot.

 	Call throw/1 rather than error/1 and don't import the require
 	module.

library/term_to_xml.m:
 	Don't import the require module.  It is unused here.

library/time.m:
 	Add some missing `thread_safe' annotations.

library/bool.m:
library/cord.m:
library/gc.m:
library/multi_map.m:
library/queue.m:
library/rtti_implementation.m:
library/set.m:
library/set_bbbtree.m:
library/svarray.m:
library/svbag.m:
library/svbimap.m:
library/sveqvclass.m:
 	Formatting and style fixes.

Julien.

Index: bitmap.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/bitmap.m,v
retrieving revision 1.16
diff -u -r1.16 bitmap.m
--- bitmap.m	17 Feb 2007 01:10:06 -0000	1.16
+++ bitmap.m	6 Mar 2007 05:39:19 -0000
@@ -23,7 +23,6 @@
  %-----------------------------------------------------------------------------%

  :- module bitmap.
-
  :- interface.

  :- import_module bool.
@@ -49,8 +48,9 @@
  :- mode bitmap_ui == in(uniq_bitmap).

      % The exception thrown for any error.
+    %
  :- type bitmap_error
-    ---> bitmap_error(string).
+    --->    bitmap_error(string).

  %-----------------------------------------------------------------------------%

@@ -60,9 +60,11 @@
  :- type num_bytes == int.

      % 8 bits stored in the least significant bits of the integer.
+    %
  :- type byte == int.

      % An integer interpreted as a vector of int.bits_per_int bits.
+    %
  :- type word == int.

  %-----------------------------------------------------------------------------%
@@ -366,6 +368,7 @@
  :- mode flip(in, bitmap_di, bitmap_uo) is det.

  %-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

  :- implementation.
  :- interface.
@@ -388,13 +391,13 @@
  :- pragma obsolete(unsafe_get/2).

  %-----------------------------------------------------------------------------%
+
  :- implementation.

  :- import_module char.
  :- import_module exception.
  :- import_module int.
  :- import_module list.
-:- import_module require.
  :- import_module string.

  %-----------------------------------------------------------------------------%
@@ -801,8 +804,7 @@
          unsafe_copy_bits(SameBM, SrcBM, SrcStartBit,
              DestBM, DestStartBit, NumBits)
        else
-        throw_bitmap_error(
-          "bitmap.copy_bits_in_bitmap: out of range")
+        throw_bitmap_error("bitmap.copy_bits_in_bitmap: out of range")
      ).

  :- func unsafe_copy_bits(int, bitmap, bit_index,
@@ -970,7 +972,7 @@
          memmove(DestBM->elements + DestFirstByteIndex,
              SrcBM->elements + SrcFirstByteIndex, NumBytes);
      } else {
-        memcpy(DestBM->elements + DestFirstByteIndex,
+        MR_memcpy(DestBM->elements + DestFirstByteIndex,
              SrcBM->elements + SrcFirstByteIndex, NumBytes);
      }

@@ -1234,7 +1236,7 @@
              !:Chars = [HighChar, LowChar | !.Chars],
              to_string_chars(Index - 1, BM, !Chars)
            else
-            error("bitmap.to_string: internal error")
+            throw(software_error("bitmap.to_string: internal error"))
          )
      ).

@@ -1258,7 +1260,7 @@
      ).

  :- pred hex_chars_to_bitmap(string::in, int::in, int::in, byte_index::in,
-            bitmap::bitmap_di, bitmap::bitmap_uo) is semidet.
+    bitmap::bitmap_di, bitmap::bitmap_uo) is semidet.

  hex_chars_to_bitmap(Str, Index, End, ByteIndex, !BM) :-
      ( if Index = End then
@@ -1406,9 +1408,9 @@
  :- pragma foreign_proc("C",
      bitmap_equal(BM1::in, BM2::in),
      [will_not_call_mercury, thread_safe, promise_pure, will_not_modify_trail],
-"{
+"
      SUCCESS_INDICATOR = MR_bitmap_eq(BM1, BM2);
-}").
+").

  bitmap_equal(BM1, BM2) :-
      BM1 ^ num_bits = (BM2 ^ num_bits) @ NumBits,
@@ -1431,13 +1433,13 @@
  :- pragma foreign_proc("C",
      bitmap_compare(Result::uo, BM1::in, BM2::in),
      [will_not_call_mercury, thread_safe, promise_pure, will_not_modify_trail],
-"{
+"
      int res;
      res = MR_bitmap_cmp(BM1, BM2);
      Result = ((res < 0) ? MR_COMPARE_LESS
                  : (res == 0) ? MR_COMPARE_EQUAL
                  : MR_COMPARE_GREATER);
-}").
+").

  bitmap_compare(Result, BM1, BM2) :-
      compare(Result0, BM1 ^ num_bits, (BM2 ^ num_bits) @ NumBits),
@@ -1729,6 +1731,7 @@
      % Return an integer whose NumBits least significant bits contain
      % bits FirstBit, FirstBit + 1, ... FirstBit + NumBits - 1,
      % in order from most significant to least significant.
+    %
  :- func extract_bits_from_byte(byte, bit_index_in_byte, num_bits) = byte.

  extract_bits_from_byte(Byte, FirstBit, NumBits) = Bits :-
@@ -1743,6 +1746,7 @@
      % Replace bits FirstBit, FirstBit + 1, ... FirstBit + NumBits - 1,
      % with the NumBits least significant bits of Bits, replacing FirstBit
      % with the most significant of those bits.
+    %
  :- func set_bits_in_byte(byte, bit_index_in_byte, num_bits, byte) = byte.

  set_bits_in_byte(Byte0, FirstBit, NumBits, Bits) = Byte :-
@@ -1762,7 +1766,8 @@

  :- pred throw_bitmap_error(string::in) is erroneous.

-throw_bitmap_error(Msg) :- throw(bitmap_error(Msg)).
+throw_bitmap_error(Msg) :-
+    throw(bitmap_error(Msg)).

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
Index: bool.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/bool.m,v
retrieving revision 1.18
diff -u -r1.18 bool.m
--- bool.m	18 Jan 2007 07:33:02 -0000	1.18
+++ bool.m	6 Mar 2007 05:39:19 -0000
@@ -16,7 +16,6 @@
  %-----------------------------------------------------------------------------%

  :- module bool.
-
  :- interface.

  :- import_module enum.
Index: cord.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/cord.m,v
retrieving revision 1.7
diff -u -r1.7 cord.m
--- cord.m	27 Sep 2006 06:16:38 -0000	1.7
+++ cord.m	6 Mar 2007 05:39:19 -0000
@@ -29,6 +29,8 @@

  :- import_module list.

+%---------------------------------------------------------------------------%
+
      % Cords that contain the same members in the same order will not
      % necessarily have the same representation and will, therefore,
      % not necessarily either unify or compare as equal.
Index: gc.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/gc.m,v
retrieving revision 1.24
diff -u -r1.24 gc.m
--- gc.m	18 Jan 2007 07:33:03 -0000	1.24
+++ gc.m	6 Mar 2007 05:39:19 -0000
@@ -18,7 +18,10 @@

  :- module gc.
  :- interface.
+
  :- import_module io.
+
+%-----------------------------------------------------------------------------%

  	% Force a garbage collection.
  	%
Index: multi_map.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/multi_map.m,v
retrieving revision 1.24
diff -u -r1.24 multi_map.m
--- multi_map.m	27 Sep 2006 06:16:41 -0000	1.24
+++ multi_map.m	6 Mar 2007 05:39:19 -0000
@@ -31,7 +31,7 @@

  %-----------------------------------------------------------------------------%

-:- type multi_map(Key, Data)    ==  map(Key, list(Data)).
+:- type multi_map(Key, Data) == map(Key, list(Data)).

  %-----------------------------------------------------------------------------%

Index: queue.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/queue.m,v
retrieving revision 1.34
diff -u -r1.34 queue.m
--- queue.m	1 Oct 2006 04:57:39 -0000	1.34
+++ queue.m	6 Mar 2007 05:39:19 -0000
@@ -23,6 +23,7 @@

  :- module queue.
  :- interface.
+
  :- import_module list.

  %--------------------------------------------------------------------------%
Index: rtti_implementation.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/rtti_implementation.m,v
retrieving revision 1.74
diff -u -r1.74 rtti_implementation.m
--- rtti_implementation.m	13 Feb 2007 01:58:54 -0000	1.74
+++ rtti_implementation.m	6 Mar 2007 05:39:19 -0000
@@ -60,14 +60,13 @@
  :- pred generic_compare(comparison_result::out, T::in, T::in) is det.

  :- pred compare_type_infos(comparison_result::out,
-        type_info::in, type_info::in) is det.
+    type_info::in, type_info::in) is det.

-:- pred type_ctor_and_args(type_info::in,
-        type_ctor_info::out,
-        list(type_info)::out) is det.
+:- pred type_ctor_and_args(type_info::in, type_ctor_info::out,
+    list(type_info)::out) is det.

  :- pred type_ctor_name_and_arity(type_ctor_info::in,
-        string::out, string::out, int::out) is det.
+    string::out, string::out, int::out) is det.

  :- pred deconstruct(T, noncanon_handling, string, int, list(univ)).
  :- mode deconstruct(in, in(do_not_allow), out, out, out) is det.
Index: set.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set.m,v
retrieving revision 1.81
diff -u -r1.81 set.m
--- set.m	6 Feb 2007 23:46:59 -0000	1.81
+++ set.m	6 Mar 2007 05:39:19 -0000
@@ -23,6 +23,8 @@
  :- import_module bool.
  :- import_module list.

+%--------------------------------------------------------------------------%
+
  :- type set(T).

      % `set.init(Set)' is true iff `Set' is an empty set.
Index: set_bbbtree.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/set_bbbtree.m,v
retrieving revision 1.31
diff -u -r1.31 set_bbbtree.m
--- set_bbbtree.m	19 Apr 2006 05:17:56 -0000	1.31
+++ set_bbbtree.m	6 Mar 2007 05:39:19 -0000
@@ -21,6 +21,8 @@
  :- import_module bool.
  :- import_module list.

+%------------------------------------------------------------------------------%
+
  :- type set_bbbtree(T).

      % `set_bbbtree.init(Set)' returns an initialized empty set.
@@ -28,7 +30,7 @@
  :- pred set_bbbtree.init(set_bbbtree(T)::uo) is det.
  :- func set_bbbtree.init = set_bbbtree(T).

-        % `set_bbbtree.empty(Set) is true iff `Set' is contains no elements.
+    % `set_bbbtree.empty(Set) is true iff `Set' is contains no elements.
      %
  :- pred set_bbbtree.empty(set_bbbtree(T)::in) is semidet.

@@ -342,7 +344,6 @@
  %------------------------------------------------------------------------------%

  % set_bbbtree.member(X, empty) :- fail.
-
  set_bbbtree.member(X, tree(V, _N, L, R)) :-
      compare(Result, X, V),
      (
Index: svarray.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/svarray.m,v
retrieving revision 1.6
diff -u -r1.6 svarray.m
--- svarray.m	27 Feb 2007 02:12:34 -0000	1.6
+++ svarray.m	6 Mar 2007 05:39:19 -0000
@@ -21,6 +21,8 @@

  :- import_module array.

+%-----------------------------------------------------------------------------%
+
      % svarray.set sets the nth element of an array, and returns the
      % resulting array (good opportunity for destructive update ;-).
      % Throws an exception if the index is out of bounds.
Index: svbag.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/svbag.m,v
retrieving revision 1.6
diff -u -r1.6 svbag.m
--- svbag.m	19 Apr 2006 05:17:58 -0000	1.6
+++ svbag.m	6 Mar 2007 05:39:19 -0000
@@ -23,6 +23,8 @@
  :- import_module list.
  :- import_module set.

+%---------------------------------------------------------------------------%
+
      % Insert a particular value in a bag.
      %
  :- pred svbag.insert(T::in, bag(T)::in, bag(T)::out) is det.
Index: svbimap.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/svbimap.m,v
retrieving revision 1.5
diff -u -r1.5 svbimap.m
--- svbimap.m	19 Apr 2006 05:17:58 -0000	1.5
+++ svbimap.m	6 Mar 2007 05:39:19 -0000
@@ -32,6 +32,7 @@
  :- pred svbimap.set(K::in, V::in, bimap(K, V)::in, bimap(K, V)::out) is det.

  %-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%

  :- implementation.

Index: sveqvclass.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/sveqvclass.m,v
retrieving revision 1.6
diff -u -r1.6 sveqvclass.m
--- sveqvclass.m	19 Apr 2006 05:17:58 -0000	1.6
+++ sveqvclass.m	6 Mar 2007 05:39:19 -0000
@@ -23,6 +23,8 @@

  :- import_module eqvclass.

+%-----------------------------------------------------------------------------%
+
      % Make an element known to the equivalence class.
      % The element may already be known to the class;
      % if it isn't, it is created without any equivalence relationships.
Index: term_to_xml.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/term_to_xml.m,v
retrieving revision 1.17
diff -u -r1.17 term_to_xml.m
--- term_to_xml.m	30 Oct 2006 07:20:56 -0000	1.17
+++ term_to_xml.m	6 Mar 2007 05:39:19 -0000
@@ -564,7 +564,6 @@
  :- import_module exception.
  :- import_module int.
  :- import_module map.
-:- import_module require.
  :- import_module string.
  :- import_module unit.
  :- import_module univ.
Index: time.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/time.m,v
retrieving revision 1.55
diff -u -r1.55 time.m
--- time.m	18 Jan 2007 07:33:04 -0000	1.55
+++ time.m	6 Mar 2007 05:39:19 -0000
@@ -24,6 +24,8 @@
  :- import_module io.
  :- import_module maybe.

+%-----------------------------------------------------------------------------%
+
      % The `clock_t' type represents times measured in clock ticks.
      % NOTE: the unit used for a value of this type depends on whether it was
      % returned by `time.clock' or `time.times'.  See the comments on these
@@ -254,10 +256,10 @@
  :- pragma foreign_proc("C",
      time.c_clock(Ret::out, IO0::di, IO::uo),
      [will_not_call_mercury, promise_pure, tabled_for_io],
-"{
+"
      Ret = (MR_Integer) clock();
      MR_update_io(IO0, IO);
-}").
+").
  /* XXX need to add System.dll to the references list.
  :- pragma foreign_proc("C#",
      time.c_clock(Ret::out, _IO0::di, _IO::uo),
@@ -289,9 +291,9 @@
  :- pragma foreign_proc("C",
      time.clocks_per_sec = (Ret::out),
      [will_not_call_mercury, promise_pure],
-"{
+"
      Ret = (MR_Integer) CLOCKS_PER_SEC;
-}").
+").
  :- pragma foreign_proc("C#",
      time.clocks_per_sec = (Ret::out),
      [will_not_call_mercury, promise_pure],
@@ -388,13 +390,13 @@
  :- pragma foreign_proc("C",
      time.c_clk_tck = (Ret::out),
      [will_not_call_mercury, promise_pure],
-"{
+"
  #if defined(MR_CLOCK_TICKS_PER_SECOND)
      Ret = MR_CLOCK_TICKS_PER_SECOND;
  #else
      Ret = -1;
  #endif
-}").
+").
  time.c_clk_tck = -1.   % default is to throw an exception.

  :- pragma foreign_proc("C#",
@@ -433,10 +435,10 @@
  :- pragma foreign_proc("C",
      time.c_time(Ret::out, IO0::di, IO::uo),
      [will_not_call_mercury, promise_pure, tabled_for_io],
-"{
+"
      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],
@@ -454,19 +456,19 @@

  :- pragma foreign_proc("C",
      time.time_t_is_invalid(Val::in),
-    [will_not_call_mercury, promise_pure],
-"{
+    [will_not_call_mercury, promise_pure, thread_safe],
+"
      SUCCESS_INDICATOR = (Val == -1);
-}").
+").
  :- pragma foreign_proc("C#",
      time.time_t_is_invalid(_Val::in),
-    [will_not_call_mercury, promise_pure],
+    [will_not_call_mercury, promise_pure, thread_safe],
  "{
      SUCCESS_INDICATOR = false;
  }").
  :- pragma foreign_proc("Java",
      time.time_t_is_invalid(_Val::in),
-    [will_not_call_mercury, promise_pure],
+    [will_not_call_mercury, promise_pure, thread_safe],
  "
      succeeded = false;
  ").
@@ -483,9 +485,9 @@
  :- pragma foreign_proc("C",
      time.c_difftime(T1::in, T0::in, Diff::out),
      [will_not_call_mercury, promise_pure],
-"{
+"
      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],
@@ -514,7 +516,7 @@
      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],
-"{
+"
      struct tm   *p;
      time_t      t;

@@ -533,7 +535,7 @@
      MD = (MR_Integer) p->tm_mday;
      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),

--------------------------------------------------------------------------
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