-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validity check, which is used by safer_ffi
- Loading branch information
Showing
5 changed files
with
103 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,13 @@ | |
// Pierre Avital, <[email protected]> | ||
// | ||
|
||
use std::{ | ||
fmt::Write as FmtWrite, | ||
fs::File, | ||
io::{BufWriter, Write}, | ||
path::PathBuf, | ||
}; | ||
|
||
fn u(mut i: u128) -> String { | ||
let mut result = "UTerm".into(); | ||
let mut ids = Vec::new(); | ||
|
@@ -26,35 +33,59 @@ fn u(mut i: u128) -> String { | |
result | ||
} | ||
|
||
fn main() { | ||
use std::{ | ||
fs::File, | ||
io::{BufWriter, Write}, | ||
path::PathBuf, | ||
}; | ||
fn typenum_unsigned() -> std::io::Result<()> { | ||
const SEQ_MAX: u128 = 1000; | ||
let padding_rs = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()).join("unsigned.rs"); | ||
let mut padding_file = BufWriter::new(File::create(padding_rs).unwrap()); | ||
let filename = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()).join("unsigned.rs"); | ||
let mut file = BufWriter::new(File::create(filename).unwrap()); | ||
for i in 0..=SEQ_MAX { | ||
let u = u(i); | ||
writeln!(padding_file, "/// {i}\npub type U{i} = {u};").unwrap(); | ||
writeln!(padding_file, "/// {i}\npub type Ux{i:X} = {u};").unwrap(); | ||
writeln!(padding_file, "/// {i}\npub type Ub{i:b} = {u};").unwrap(); | ||
writeln!(file, "/// {i}\npub type U{i} = {u};")?; | ||
writeln!(file, "/// {i}\npub type Ux{i:X} = {u};")?; | ||
writeln!(file, "/// {i}\npub type Ub{i:b} = {u};")?; | ||
} | ||
for i in 0..39 { | ||
let ipow = 10u128.pow(i); | ||
let u = u(ipow); | ||
writeln!(padding_file, "/// {i}\npub type U10pow{i} = {u};").unwrap(); | ||
writeln!(file, "/// {i}\npub type U10pow{i} = {u};")?; | ||
if ipow > SEQ_MAX { | ||
writeln!(padding_file, "/// {i}\npub type U{ipow} = {u};").unwrap(); | ||
writeln!(padding_file, "/// {i}\npub type Ux{ipow:X} = {u};").unwrap(); | ||
writeln!(padding_file, "/// {i}\npub type Ub{ipow:b} = {u};").unwrap(); | ||
writeln!(file, "/// {i}\npub type U{ipow} = {u};")?; | ||
writeln!(file, "/// {i}\npub type Ux{ipow:X} = {u};")?; | ||
writeln!(file, "/// {i}\npub type Ub{ipow:b} = {u};")?; | ||
} | ||
} | ||
for i in 0..128 { | ||
let u = u(1 << i); | ||
writeln!(padding_file, "/// {i}\npub type U2pow{i} = {u};").unwrap(); | ||
writeln!(file, "/// {i}\npub type U2pow{i} = {u};")?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn tuples() -> std::io::Result<()> { | ||
let filename = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()).join("tuples.rs"); | ||
let mut file = BufWriter::new(File::create(filename).unwrap()); | ||
for i in 0..128 { | ||
writeln!( | ||
file, | ||
r##"/// An ABI stable tuple | ||
#[crate::stabby] | ||
pub struct Tuple{i}<{generics}>({fields}); | ||
"##, | ||
generics = (0..i).fold(String::new(), |mut acc, it| { | ||
write!(acc, "T{it}, ").unwrap(); | ||
acc | ||
}), | ||
fields = (0..i).fold(String::new(), |mut acc, it| { | ||
write!(acc, "pub T{it}, ").unwrap(); | ||
acc | ||
}), | ||
)?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
typenum_unsigned().unwrap(); | ||
tuples().unwrap(); | ||
if let Ok(toolchain) = std::env::var("RUSTUP_TOOLCHAIN") { | ||
if toolchain.starts_with("nightly") { | ||
println!("cargo:rustc-cfg=stabby_nightly"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.