library/io.m:
As above. Also, when several exported predicates use the same
utility predicate, pass their $pred to the utility for use
in exception messages.
tests/hard_coded/read_min_int.exp*:
Expect the updated exception messages.
Make base_string_to_int check for overflow and underflow when converting
from strings in all bases, not only base 10. Fixes bug #376.
Previously it was stated that "numbers not in base 10 are assumed to
denote bit patterns and are not checked for overflow." Though not a
safe assumption in general, in Mercury source files it is useful to be
able to write values with the high bit set, e.g. 0x80000000 on 32-bit
machines, that would be greater than max_int if interpreted as a
positive integer.
The changed behaviour of base_string_to_int would reject such literals
from Mercury sources, so additional changes are required to maintain
that usage. However, unlike before, the compiler will report an
error if some non-zero bits of the literal would be discarded.
library/string.m:
Enable overflow/underflow checking for base_string_to_int for
any base.
Update documentation.
library/lexer.m:
Allow `big_integer' token functor to represent non-base 10
literals as well.
Add `integer_base' type.
library/term.m:
Add `big_integer' term functor.
Add `integer_base' type.
library/term_io.m:
Add private helper functions `integer_base_int' and
`integer_base_prefix'.
Conform to changes.
library/parser.m:
Pass through `big_integer' tokens as `big_integer' terms.
Conform to changes.
compiler/prog_util.m:
Add predicate to convert integer terms to ints with the
aforementioned concession for bit patterns.
`make_functor_cons_id' can now fail due to integer tokens
exceeding the range of `int'.
compiler/superhomogeneous.m:
Make `unravel_var_functor_unification' convert `big_integer'
tokens on the RHS to a simple `int' with the aforementioned
concession for bit patterns, or add an error message if any
significant bits would be discarded.
compiler/fact_table.m:
compiler/mercury_to_mercury.m:
compiler/module_imports.m:
compiler/prog_io_util.m:
Conform to changes.
compiler/make.util.m:
Delete unused predicate.
tests/general/test_string_to_int_overflow.m:
tests/general/test_string_to_int_overflow.exp:
tests/general/test_string_to_int_overflow.exp2:
tests/general/test_string_to_int_overflow.exp3:
Rewrite test case.
tests/hard_coded/lexer_bigint.exp:
tests/hard_coded/lexer_bigint.exp2:
tests/hard_coded/read_min_int.exp:
tests/hard_coded/read_min_int.exp2:
Update expected outputs due to the lexer and term module changes.
tests/invalid/Mmakefile:
tests/invalid/invalid_int.err_exp:
tests/invalid/invalid_int.err_exp2:
tests/invalid/invalid_int.m:
Add new test case.
NEWS:
Announce the changes.
Branches: main
lexer.m tokenises "-INTEGER" as two tokens, a minus sign and a positive
integer. This fails when the overall negative value is min_int, i.e. the
absolute value is max_int+1 -- too big to store in an int.
One less obvious consequence of the bug is that io.read could not parse some
plain Mercury terms written out by io.write.
library/lexer.m:
Add a `token.big_integer' constructor to hold big integer literals in
their string representation. Currently this is only done for base 10
literals which cannot fit in an int.
library/parser.m:
Parse the token sequence, minus sign followed by big_integer max_int+1,
as the integer term with value min_int.
tests/hard_coded/Mmakefile:
tests/hard_coded/lexer_bigint.exp:
tests/hard_coded/lexer_bigint.exp2:
tests/hard_coded/lexer_bigint.inp:
tests/hard_coded/lexer_bigint.m:
tests/hard_coded/read_min_int.exp:
tests/hard_coded/read_min_int.exp2:
tests/hard_coded/read_min_int.inp:
tests/hard_coded/read_min_int.m:
Add test cases.