This commit is contained in:
Jeehoon Kang
2021-06-21 18:45:39 +00:00
parent 2d8d1e7fb4
commit 4535b2ef6f
28 changed files with 696 additions and 370 deletions

View File

@@ -1,6 +1,9 @@
//! The intermediate representation.
mod dtype;
mod equiv;
mod interp;
#[allow(clippy::all)]
mod parse;
mod write_ir;
@@ -247,11 +250,7 @@ impl HasDtype for Instruction {
impl Instruction {
pub fn is_pure(&self) -> bool {
match self {
Self::Store { .. } => false,
Self::Call { .. } => false,
_ => true,
}
!matches!(self, Self::Store { .. } | Self::Call { .. })
}
}
@@ -526,6 +525,7 @@ impl TryFrom<&ast::Constant> for Constant {
ast::IntegerBase::Decimal => Self::DECIMAL,
ast::IntegerBase::Octal => Self::OCTAL,
ast::IntegerBase::Hexadecimal => Self::HEXADECIMAL,
ast::IntegerBase::Binary => Self::BINARY,
};
let value = if integer.suffix.unsigned {
@@ -636,14 +636,11 @@ impl Constant {
const DECIMAL: u32 = 10;
const OCTAL: u32 = 8;
const HEXADECIMAL: u32 = 16;
const BINARY: u32 = 2;
#[inline]
pub fn is_integer_constant(&self) -> bool {
if let Self::Int { .. } = self {
true
} else {
false
}
matches!(self, Self::Int { .. })
}
#[inline]
@@ -730,17 +727,13 @@ impl Constant {
}
_ => panic!(
"constant value generated by `Constant::from_ast_expression` \
must be `Constant{{Int, Float}}`"
must be `Constant(Int, Float)`"
),
}
}
pub fn is_undef(&self) -> bool {
if let Self::Undef { .. } = self {
true
} else {
false
}
matches!(self, Self::Undef { .. })
}
pub fn typecast(self, target_dtype: Dtype) -> Self {