Enum ConstantExpr
#[repr(u8)]pub enum ConstantExpr {
Int(Span<IntValue>),
Var(Span<Arc<Path>>),
BinaryOp {
span: SourceSpan,
op: ConstantOp,
lhs: Box<ConstantExpr>,
rhs: Box<ConstantExpr>,
},
String(Ident),
Word(Span<WordValue>),
Hash(HashKind, Ident),
}Expand description
Represents a constant expression or value in Miden Assembly syntax.
Variants§
Int(Span<IntValue>)
A literal [Felt] value.
Var(Span<Arc<Path>>)
A reference to another constant.
BinaryOp
An binary arithmetic operator.
String(Ident)
A plain spanned string.
Word(Span<WordValue>)
A literal [‘WordValue’].
Hash(HashKind, Ident)
A spanned string with a HashKind showing to which type of value the given string should
be hashed.
Implementations§
§impl ConstantExpr
impl ConstantExpr
pub fn is_value(&self) -> bool
pub fn is_value(&self) -> bool
Returns true if this expression is already evaluated to a concrete value
pub fn expect_int(&self) -> IntValue
pub fn expect_int(&self) -> IntValue
Unwrap an IntValue from this expression or panic.
This is used in places where we expect the expression to have been folded to an integer, otherwise a bug occurred.
pub fn expect_felt(&self) -> Felt
pub fn expect_felt(&self) -> Felt
Unwrap a [Felt] value from this expression or panic.
This is used in places where we expect the expression to have been folded to a felt value, otherwise a bug occurred.
pub fn expect_string(&self) -> Arc<str>
pub fn expect_string(&self) -> Arc<str>
Unwrap a Arc<str> value from this expression or panic.
This is used in places where we expect the expression to have been folded to a string value, otherwise a bug occurred.
pub fn expect_value(&self) -> ConstantValue
pub fn expect_value(&self) -> ConstantValue
Unwrap a ConstantValue from this expression or panic.
This is used in places where we expect the expression to have been folded to a concrete value, otherwise a bug occurred.
pub fn into_value(self) -> Result<ConstantValue, ConstantExpr>
pub fn into_value(self) -> Result<ConstantValue, ConstantExpr>
Try to convert this expression into a ConstantValue, if the expression is a value.
Returns Err if the expression cannot be represented as a ConstantValue.
pub fn as_value(&self) -> Option<ConstantValue>
pub fn as_value(&self) -> Option<ConstantValue>
Get the ConstantValue representation of this expression, if it is a value.
Returns None if the expression cannot be represented as a ConstantValue.
pub fn try_fold(self) -> Result<ConstantExpr, ParsingError>
pub fn try_fold(self) -> Result<ConstantExpr, ParsingError>
Attempt to fold to a single value.
This will only succeed if the expression has no references to other constants.
§Errors
Returns an error if an invalid expression is found while folding, such as division by zero.
pub fn references(&self) -> Vec<Span<Arc<Path>>>
pub fn references(&self) -> Vec<Span<Arc<Path>>>
Get any references to other symbols present in this expression
Trait Implementations§
§impl Arbitrary for ConstantExpr
Available on crate feature arbitrary only.
impl Arbitrary for ConstantExpr
arbitrary only.§type Parameters = ()
type Parameters = ()
arbitrary_with accepts for configuration
of the generated Strategy. Parameters must implement Default.§type Strategy = BoxedStrategy<ConstantExpr>
type Strategy = BoxedStrategy<ConstantExpr>
Strategy used to generate values of type Self.§fn arbitrary_with(
_args: <ConstantExpr as Arbitrary>::Parameters,
) -> <ConstantExpr as Arbitrary>::Strategy
fn arbitrary_with( _args: <ConstantExpr as Arbitrary>::Parameters, ) -> <ConstantExpr as Arbitrary>::Strategy
§impl Clone for ConstantExpr
impl Clone for ConstantExpr
§fn clone(&self) -> ConstantExpr
fn clone(&self) -> ConstantExpr
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for ConstantExpr
impl Debug for ConstantExpr
§impl From<ConstantValue> for ConstantExpr
impl From<ConstantValue> for ConstantExpr
§fn from(value: ConstantValue) -> ConstantExpr
fn from(value: ConstantValue) -> ConstantExpr
§impl Hash for ConstantExpr
impl Hash for ConstantExpr
§impl PartialEq for ConstantExpr
impl PartialEq for ConstantExpr
§impl PrettyPrint for ConstantExpr
impl PrettyPrint for ConstantExpr
§fn to_pretty_string(&self) -> String
fn to_pretty_string(&self) -> String
§fn pretty_print(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn pretty_print(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§impl Spanned for ConstantExpr
impl Spanned for ConstantExpr
fn span(&self) -> SourceSpan
impl Eq for ConstantExpr
Auto Trait Implementations§
impl Freeze for ConstantExpr
impl RefUnwindSafe for ConstantExpr
impl Send for ConstantExpr
impl Sync for ConstantExpr
impl Unpin for ConstantExpr
impl UnsafeUnpin for ConstantExpr
impl UnwindSafe for ConstantExpr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more