[m-rev.] diff: fix term deconstruction for uints

Julien Fischer jfischer at opturion.com
Sun Jun 18 21:12:08 AEST 2017


Fix term deconstruction for uints.

runtime/mercury_ml_expand_body.h:
library/rtti_implementation.m:
library/erlang_rtti_implementation.m:
     As above.

tests/hard_coded/deconstruct_arg.m:
      Add a test for uints.

      Avoid the use of a deprecated predicate.

tests/hard_coded/deconstruct_arg.{exp,exp2}:
      Update expected outputs for the above.

Julien.

diff --git a/library/erlang_rtti_implementation.m b/library/erlang_rtti_implementation.m
index 35f9c4867..156bd7a83 100644
--- a/library/erlang_rtti_implementation.m
+++ b/library/erlang_rtti_implementation.m
@@ -826,7 +826,8 @@ deconstruct_2(Term, TypeInfo, TypeCtorInfo, TypeCtorRep, NonCanon,
          Arguments = []
      ;
          TypeCtorRep = etcr_uint,
-        Functor = "<<uint>>",
+        det_dynamic_cast(Term, UInt),
+        Functor = string.uint_to_string(UInt) ++ "u",
          FunctorNumber = 0,
          Arity = 0,
          Arguments = []
diff --git a/library/rtti_implementation.m b/library/rtti_implementation.m
index fb6500fb4..b85e3ff71 100644
--- a/library/rtti_implementation.m
+++ b/library/rtti_implementation.m
@@ -2710,7 +2710,8 @@ deconstruct_2(Term, TypeInfo, TypeCtorInfo, TypeCtorRep, NonCanon,
          Arguments = []
      ;
          TypeCtorRep = tcr_uint,
-        Functor = "<<uint>>",
+        det_dynamic_cast(Term, UInt),
+        Functor = string.uint_to_string(UInt) ++ "u",
          Ordinal = -1,
          Arity = 0,
          Arguments = []
diff --git a/runtime/mercury_ml_expand_body.h b/runtime/mercury_ml_expand_body.h
index a2fa33513..e62639b34 100644
--- a/runtime/mercury_ml_expand_body.h
+++ b/runtime/mercury_ml_expand_body.h
@@ -783,7 +783,7 @@ EXPAND_FUNCTION_NAME(MR_TypeInfo type_info, MR_Word *data_word_ptr,
                  char    *str;

                  data_word = *data_word_ptr;
-                sprintf(buf, "%" MR_INTEGER_LENGTH_MODIFIER "u",
+                sprintf(buf, "%" MR_INTEGER_LENGTH_MODIFIER "uu",
                      (MR_Unsigned) data_word);
                  MR_make_aligned_string_copy_saved_hp(str, buf, NULL);
                  expand_info->EXPAND_FUNCTOR_FIELD = str;
diff --git a/tests/hard_coded/deconstruct_arg.exp b/tests/hard_coded/deconstruct_arg.exp
index 3e9e5b4e5..ce944bd0f 100644
--- a/tests/hard_coded/deconstruct_arg.exp
+++ b/tests/hard_coded/deconstruct_arg.exp
@@ -152,6 +152,20 @@ deconstruct deconstruct: functor 4 arity 0
  deconstruct limited deconstruct 3 of 4
  functor 4 arity 0 []

+deconstruct functor: 561u/0
+deconstruct argument 0 of 561 doesn't exist
+deconstruct argument 1 of 561 doesn't exist
+deconstruct argument 2 of 561 doesn't exist
+deconstruct argument 'moo' doesn't exist
+deconstruct argument 'mooo!' doesn't exist
+deconstruct argument 'packed1' doesn't exist
+deconstruct argument 'packed2' doesn't exist
+deconstruct argument 'packed3' doesn't exist
+deconstruct deconstruct: functor 561u arity 0
+[]
+deconstruct limited deconstruct 3 of 561
+functor 561u arity 0 []
+
  deconstruct functor: univ_cons/1
  deconstruct argument 0 of ["hi! I\'m a univ!"] is ["hi! I\'m a univ!"]
  deconstruct argument 1 of ["hi! I\'m a univ!"] doesn't exist
@@ -194,7 +208,7 @@ deconstruct deconstruct: functor newline arity 0
  deconstruct limited deconstruct 3 of '<<predicate>>'
  functor newline arity 0 []

-deconstruct functor: lambda_deconstruct_arg_m_125/1
+deconstruct functor: lambda_deconstruct_arg_m_127/1
  deconstruct argument 0 of '<<predicate>>' is [1, 2]
  deconstruct argument 1 of '<<predicate>>' doesn't exist
  deconstruct argument 2 of '<<predicate>>' doesn't exist
@@ -203,10 +217,10 @@ deconstruct argument 'mooo!' doesn't exist
  deconstruct argument 'packed1' doesn't exist
  deconstruct argument 'packed2' doesn't exist
  deconstruct argument 'packed3' doesn't exist
-deconstruct deconstruct: functor lambda_deconstruct_arg_m_125 arity 1
+deconstruct deconstruct: functor lambda_deconstruct_arg_m_127 arity 1
  [[1, 2]]
  deconstruct limited deconstruct 3 of '<<predicate>>'
-functor lambda_deconstruct_arg_m_125 arity 1 [[1, 2]]
+functor lambda_deconstruct_arg_m_127 arity 1 [[1, 2]]

  deconstruct functor: p/3
  deconstruct argument 0 of '<<predicate>>' is 1
diff --git a/tests/hard_coded/deconstruct_arg.exp2 b/tests/hard_coded/deconstruct_arg.exp2
index e402c3aea..57ce78c60 100644
--- a/tests/hard_coded/deconstruct_arg.exp2
+++ b/tests/hard_coded/deconstruct_arg.exp2
@@ -152,6 +152,20 @@ deconstruct deconstruct: functor 4 arity 0
  deconstruct limited deconstruct 3 of 4
  functor 4 arity 0 []

+deconstruct functor: 561u/0
+deconstruct argument 0 of 561 doesn't exist
+deconstruct argument 1 of 561 doesn't exist
+deconstruct argument 2 of 561 doesn't exist
+deconstruct argument 'moo' doesn't exist
+deconstruct argument 'mooo!' doesn't exist
+deconstruct argument 'packed1' doesn't exist
+deconstruct argument 'packed2' doesn't exist
+deconstruct argument 'packed3' doesn't exist
+deconstruct deconstruct: functor 561u arity 0
+[]
+deconstruct limited deconstruct 3 of 561
+functor 561u arity 0 []
+
  deconstruct functor: univ_cons/1
  deconstruct argument 0 of ["hi! I\'m a univ!"] is ["hi! I\'m a univ!"]
  deconstruct argument 1 of ["hi! I\'m a univ!"] doesn't exist
diff --git a/tests/hard_coded/deconstruct_arg.m b/tests/hard_coded/deconstruct_arg.m
index 9ffb95f47..677b6c7d6 100644
--- a/tests/hard_coded/deconstruct_arg.m
+++ b/tests/hard_coded/deconstruct_arg.m
@@ -80,11 +80,11 @@ set(List) = set_rep(List).
  % convert set to sorted list
  :- func set_to_sorted_list(set(T)) = list(T).

-set_to_sorted_list(Set) =
-    promise_only_solution((pred(Sorted::out) is cc_multi :-
+set_to_sorted_list(Set) = Sorted :-
+    promise_equivalent_solutions [Sorted] (
          Set = set_rep(Unsorted),
          list.sort_and_remove_dups(Unsorted, Sorted)
-    )).
+    ).

  :- pred set_equal(set(T)::in, set(T)::in) is semidet.

@@ -115,6 +115,8 @@ main -->
      test_all(0.12345678901234566), newline,
          % test integers
      test_all(4), newline,
+        % test unigned integers
+    test_all(561u), newline,
          % test univ.
      { type_to_univ(["hi! I'm a univ!"], Univ) },
      test_all(Univ), newline,



More information about the reviews mailing list