ISLE: support more flexible integer constants. (#4559)

The ISLE language's lexer previously used a very primitive
`i64::from_str_radix` call to parse integer constants, allowing values
in the range -2^63..2^63 only. Also, underscores to separate digits (as
is allwoed in Rust) were not supported. Finally, 128-bit constants were
not supported at all.

This PR addresses all issues above:
- Integer constants are internally stored as 128-bit values.
- Parsing supports either signed (-2^127..2^127) or unsigned (0..2^128)
  range. Negation works independently of that, so one can write
  `-0xffff..ffff` (128 bits wide, i.e., -(2^128-1)) to get a `1`.
- Underscores are supported to separate groups of digits, so one can
  write `0xffff_ffff`.
- A minor oversight was fixed: hex constants can start with `0X`
  (uppercase) as well as `0x`, for consistency with Rust and C.

This PR also adds a new kind of ISLE test that actually runs a driver
linked to compiled ISLE code; we previously didn't have any such tests,
but it is now quite useful to assert correct interpretation of constant
values.
This commit is contained in:
Chris Fallin
2022-07-29 14:52:14 -07:00
committed by GitHub
parent b1273548fb
commit 8e9e9c52a1
10 changed files with 95 additions and 28 deletions

View File

@@ -12,6 +12,7 @@ fn main() {
emit_tests(&mut out, "isle_examples/pass", "run_pass");
emit_tests(&mut out, "isle_examples/fail", "run_fail");
emit_tests(&mut out, "isle_examples/link", "run_link");
emit_tests(&mut out, "isle_examples/run", "run_run");
let output = out_dir.join("isle_tests.rs");
std::fs::write(output, out).unwrap();