Files
mercury/tests/hard_coded/read_min_int.inp
Peter Wang 0667216eba lexer.m tokenises "-INTEGER" as two tokens, a minus sign and a positive
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.
2012-05-14 06:30:06 +00:00

12 lines
301 B
Plaintext

% 32-bit
foo(-2147483648). % min_int (ok)
foo(2147483647). % max_int (ok)
foo(2147483648). % max_int+1 (unsupported)
% 64-bit
foo(-9223372036854775808). % min_int (ok)
foo(9223372036854775807). % max_int (ok)
foo(9223372036854775808). % max_int+1 (unsupported)