[m-rev.] diff: make 64-bit integers as insts work

Julien Fischer jfischer at opturion.com
Sun Feb 4 23:31:12 AEDT 2018


Make 64-bit integers as insts work.

compiler/prog_util.m:
     Add some missing cases that are preventing insts for 64-bit integers
     working.

tests/invalid/Mmakefile:
tests/invalid/invalid_int64_inst.{m,err_exp}:
tests/invalid/invalid_uint64_inst.{m,err_exp}:
      Add tests for the above.

Julien.

diff --git a/compiler/prog_util.m b/compiler/prog_util.m
index 91395f6..6e0721b 100644
--- a/compiler/prog_util.m
+++ b/compiler/prog_util.m
@@ -727,7 +727,7 @@ make_functor_cons_id(Functor, Arity, ConsId) :-
          Functor = term.integer(Base, Integer, Signedness, Size),
          (
              Signedness = signed,
-            (
+            require_complete_switch [Size] (
                  Size = size_word,
                  source_integer_to_int(Base, Integer, Int),
                  ConsId = int_const(Int)
@@ -743,10 +743,14 @@ make_functor_cons_id(Functor, Arity, ConsId) :-
                  Size = size_32_bit,
                  integer.to_int32(Integer, Int32),
                  ConsId = int32_const(Int32)
+            ;
+                Size = size_64_bit,
+                integer.to_int64(Integer, Int64),
+                ConsId = int64_const(Int64)
              )
          ;
              Signedness = unsigned,
-            (
+            require_complete_switch [Size] (
                  Size = size_word,
                  integer.to_uint(Integer, UInt),
                  ConsId = uint_const(UInt)
@@ -762,6 +766,10 @@ make_functor_cons_id(Functor, Arity, ConsId) :-
                  Size = size_32_bit,
                  integer.to_uint32(Integer, UInt32),
                  ConsId = uint32_const(UInt32)
+            ;
+                Size = size_64_bit,
+                integer.to_uint64(Integer, UInt64),
+                ConsId = uint64_const(UInt64)
              )
          )
      ;
diff --git a/tests/invalid/Mmakefile b/tests/invalid/Mmakefile
index 53c236b..62deb88 100644
--- a/tests/invalid/Mmakefile
+++ b/tests/invalid/Mmakefile
@@ -190,6 +190,7 @@ SINGLEMODULE= \
  	invalid_int \
  	invalid_int16_inst \
  	invalid_int32_inst \
+	invalid_int64_inst \
  	invalid_int8_inst \
  	invalid_main \
  	invalid_mllibs \
@@ -200,6 +201,7 @@ SINGLEMODULE= \
  	invalid_uint_inst \
  	invalid_uint16_inst \
  	invalid_uint32_inst \
+	invalid_uint64_inst \
  	invalid_uint8_inst \
  	io_in_ite_cond \
  	kind \
diff --git a/tests/invalid/invalid_int64_inst.err_exp b/tests/invalid/invalid_int64_inst.err_exp
index e69de29..3cf752b 100644
--- a/tests/invalid/invalid_int64_inst.err_exp
+++ b/tests/invalid/invalid_int64_inst.err_exp
@@ -0,0 +1,8 @@
+invalid_int64_inst.m:015: In clause for `main(di, uo)':
+invalid_int64_inst.m:015:   in argument 1 of call to function
+invalid_int64_inst.m:015:   `invalid_int64_inst.foo'/1:
+invalid_int64_inst.m:015:   mode error: variable `N' has instantiatedness
+invalid_int64_inst.m:015:   `unique(7i64)',
+invalid_int64_inst.m:015:   expected instantiatedness was
+invalid_int64_inst.m:015:   `bound(2i64 ; 4i64 ; 6i64)'.
+For more information, recompile with `-E'.
diff --git a/tests/invalid/invalid_int64_inst.m b/tests/invalid/invalid_int64_inst.m
index e69de29..ee8e03e 100644
--- a/tests/invalid/invalid_int64_inst.m
+++ b/tests/invalid/invalid_int64_inst.m
@@ -0,0 +1,22 @@
+% Check for int64 literals in inst definitions and the error messages
+% concerning them.
+
+:- module invalid_int64_inst.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+main(!IO) :-
+    N = 7i64,
+    X = foo(N),
+    io.print_line(X, !IO).
+
+:- func foo(int64::in(bound(2i64 ; 4i64 ; 6i64))) = (int64::out) is det.
+
+foo(2i64) = 4i64.
+foo(4i64) = 9i64.
+foo(6i64) = 12i64.
diff --git a/tests/invalid/invalid_uint64_inst.err_exp b/tests/invalid/invalid_uint64_inst.err_exp
index e69de29..ab2d4e6 100644
--- a/tests/invalid/invalid_uint64_inst.err_exp
+++ b/tests/invalid/invalid_uint64_inst.err_exp
@@ -0,0 +1,8 @@
+invalid_uint64_inst.m:015: In clause for `main(di, uo)':
+invalid_uint64_inst.m:015:   in argument 1 of call to function
+invalid_uint64_inst.m:015:   `invalid_uint64_inst.foo'/1:
+invalid_uint64_inst.m:015:   mode error: variable `N' has instantiatedness
+invalid_uint64_inst.m:015:   `unique(7u64)',
+invalid_uint64_inst.m:015:   expected instantiatedness was
+invalid_uint64_inst.m:015:   `bound(2u64 ; 4u64 ; 6u64)'.
+For more information, recompile with `-E'.
diff --git a/tests/invalid/invalid_uint64_inst.m b/tests/invalid/invalid_uint64_inst.m
index e69de29..82e6b68 100644
--- a/tests/invalid/invalid_uint64_inst.m
+++ b/tests/invalid/invalid_uint64_inst.m
@@ -0,0 +1,22 @@
+% Check for uint64 literals in inst definitions and the error messages
+% concerning them.
+
+:- module invalid_uint64_inst.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is det.
+
+:- implementation.
+
+main(!IO) :-
+    N = 7u64,
+    X = foo(N),
+    io.print_line(X, !IO).
+
+:- func foo(uint64::in(bound(2u64 ; 4u64 ; 6u64))) = (uint64::out) is det.
+
+foo(2u64) = 4u64.
+foo(4u64) = 9u64.
+foo(6u64) = 12u64.


More information about the reviews mailing list