diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-04-27 16:17:32 +1200 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-04-27 16:17:32 +1200 |
commit | 058938fed4562d4802c7b7d8dc52524dbde354cb (patch) | |
tree | fc74a55c9b00bad0d2833237b6080942651aa7b6 /src | |
parent | a417f9b6440871bbec26520f0921189ee156e9ff (diff) | |
download | torque-asm-058938fed4562d4802c7b7d8dc52524dbde354cb.zip |
Implement <abs> operator for expressions
The <abs> operator returns the absolute value of an integer.
Diffstat (limited to 'src')
-rw-r--r-- | src/types/expression_stack.rs | 1 | ||||
-rw-r--r-- | src/types/operator.rs | 3 |
2 files changed, 4 insertions, 0 deletions
diff --git a/src/types/expression_stack.rs b/src/types/expression_stack.rs index 8e1c87d..228fa2d 100644 --- a/src/types/expression_stack.rs +++ b/src/types/expression_stack.rs @@ -63,6 +63,7 @@ impl ExpressionStack { Operator::BitNot => { pop!(a); push!(!a) }, Operator::Length => { pop!(a); push!(width(a) as isize) }, Operator::Tally => { pop!(a); push!(tally(a) as isize) }, + Operator::Absolute => { pop!(a); push!(a.wrapping_abs()) }, } return Ok(()); } diff --git a/src/types/operator.rs b/src/types/operator.rs index d5b5e94..da4dfb4 100644 --- a/src/types/operator.rs +++ b/src/types/operator.rs @@ -20,6 +20,7 @@ pub enum Operator { BitNot, Length, Tally, + Absolute, } impl Operator { @@ -59,6 +60,7 @@ impl Operator { "<not>" => Some(Operator::BitNot), "<len>" => Some(Operator::Length), "<tal>" => Some(Operator::Tally), + "<abs>" => Some(Operator::Absolute), _ => None, } } @@ -87,6 +89,7 @@ impl std::fmt::Display for Operator { Operator::BitNot => "<not>", Operator::Length => "<len>", Operator::Tally => "<tal>", + Operator::Absolute => "<abs>", }; write!(f, "{string}") } |