-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YdrMaster <[email protected]>
- Loading branch information
Showing
5 changed files
with
225 additions
and
166 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "digit-layout" | ||
description = "Define memory layout of digital types as `[sign|exponent|mantissa; N]`" | ||
version = "0.0.0" | ||
description = "This crate provides a unified data type definition across various libraries, efficiently encodes types in a compact layout, thus avoiding the redundancy of enumerating definitions for data types." | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["YdrMaster <[email protected]>"] | ||
repository = "https://github.com/YdrMaster/digit-layout.git" | ||
|
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
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 |
---|---|---|
@@ -1,48 +1,20 @@ | ||
/// 定义一个 [`DigitLayout`](crate::DigitLayout) 实例。 | ||
#[macro_export] | ||
macro_rules! layout { | ||
($name:ident i($bits:expr)x($packed:expr)) => { | ||
($name:ident u($bits:expr)) => { | ||
#[allow(non_upper_case_globals)] | ||
pub const $name: $crate::DigitLayout = | ||
$crate::DigitLayout::new($packed, true, 0, $bits - 1); | ||
pub const $name: $crate::DigitLayout = $crate::DigitLayout::unsigned($bits); | ||
}; | ||
($name:ident u($bits:expr)x($packed:expr)) => { | ||
($name:ident i($bits:expr)) => { | ||
#[allow(non_upper_case_globals)] | ||
pub const $name: $crate::DigitLayout = | ||
$crate::DigitLayout::new($packed, false, 0, $bits); | ||
pub const $name: $crate::DigitLayout = $crate::DigitLayout::real(0, $bits); | ||
}; | ||
($name:ident e($exp:expr)m($mant:expr)x($packed:expr)) => { | ||
($name:ident e($exponent:expr)m($mantissa:expr)) => { | ||
#[allow(non_upper_case_globals)] | ||
pub const $name: $crate::DigitLayout = | ||
$crate::DigitLayout::new($packed, true, $exp, $mant); | ||
}; | ||
|
||
($name:ident i($bits:expr)) => { | ||
layout!($name i($bits)x(1)); | ||
}; | ||
($name:ident u($bits:expr)) => { | ||
layout!($name u($bits)x(1)); | ||
pub const $name: $crate::DigitLayout = $crate::DigitLayout::real($exponent, $mantissa); | ||
}; | ||
($name:ident e($exp:expr)m($mant:expr)) => { | ||
layout!($name e($exp)m($mant)x(1)); | ||
}; | ||
} | ||
|
||
/// 为类型实现与 [`DigitLayout`](crate::DigitLayout) 相关的 trait。 | ||
#[macro_export] | ||
macro_rules! impl_digit { | ||
($ty:ty : $digit:expr) => { | ||
impl $crate::AsDigit for $ty { | ||
const LAYOUT: $crate::DigitLayout = $digit; | ||
} | ||
}; | ||
|
||
($ty:ty : $digit:expr, $const:ident) => { | ||
impl_digit!($ty : $digit); | ||
|
||
const $const: u32 = $digit.to_u32(); | ||
impl $crate::TypeOf_<$const> for $crate::TypeOf<$const> { | ||
type Type = $ty; | ||
} | ||
($name:ident $text:literal) => { | ||
#[allow(non_upper_case_globals)] | ||
pub const $name: $crate::DigitLayout = $crate::DigitLayout::named($text); | ||
}; | ||
} |
Oops, something went wrong.