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

@@ -18,7 +18,7 @@ pub fn run_fail(filename: &str) {
assert!(build(filename).is_err());
}
pub fn run_link(isle_filename: &str) {
fn build_and_link_isle(isle_filename: &str) -> (tempfile::TempDir, std::path::PathBuf) {
let tempdir = tempfile::tempdir().unwrap();
let code = build(isle_filename).unwrap();
@@ -45,10 +45,27 @@ pub fn run_link(isle_filename: &str) {
let mut rustc = std::process::Command::new("rustc")
.arg(&rust_driver)
.arg("-o")
.arg(output)
.arg(output.clone())
.spawn()
.unwrap();
assert!(rustc.wait().unwrap().success());
(tempdir, output)
}
pub fn run_link(isle_filename: &str) {
build_and_link_isle(isle_filename);
}
pub fn run_run(isle_filename: &str) {
let (_tempdir, exe) = build_and_link_isle(isle_filename);
assert!(std::process::Command::new(exe)
.spawn()
.unwrap()
.wait()
.unwrap()
.success());
}
// Generated by build.rs.