diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-10-14 15:36:36 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-10-14 16:54:44 +1300 |
commit | ace5677f87c2bc042d8d5e807ccea9ddcd828c9e (patch) | |
tree | 77f6461e50a75da6e81f8633fd93a74428915d09 /src/types | |
parent | d95f62157bc17ee8aad12aa8887315766207c326 (diff) | |
download | torque-asm-ace5677f87c2bc042d8d5e807ccea9ddcd828c9e.zip |
Rename the <tal> operator to <sum>
This is a more memorable name, and can be implemented for lists in the
future as well.
Diffstat (limited to 'src/types')
-rw-r--r-- | src/types/expression_stack.rs | 5 | ||||
-rw-r--r-- | src/types/operator.rs | 8 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/types/expression_stack.rs b/src/types/expression_stack.rs index 228fa2d..62a44fb 100644 --- a/src/types/expression_stack.rs +++ b/src/types/expression_stack.rs @@ -62,7 +62,7 @@ impl ExpressionStack { Operator::BitXor => { pop!(b); pop!(a); push!(a ^ b) }, 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::Sum => { pop!(a); push!(ones(a) as isize) }, Operator::Absolute => { pop!(a); push!(a.wrapping_abs()) }, } return Ok(()); @@ -78,7 +78,8 @@ pub fn width(value: isize) -> u32 { } } -pub fn tally(value: isize) -> u32 { +/// Count the number of one bits in a value. +pub fn ones(value: isize) -> u32 { let width = width(value); let mask = 2i32.pow(width) -1; let value = (value as usize) & (mask as usize); diff --git a/src/types/operator.rs b/src/types/operator.rs index da4dfb4..e360567 100644 --- a/src/types/operator.rs +++ b/src/types/operator.rs @@ -19,7 +19,7 @@ pub enum Operator { BitXor, BitNot, Length, - Tally, + Sum, Absolute, } @@ -59,9 +59,9 @@ impl Operator { "<xor>" => Some(Operator::BitXor), "<not>" => Some(Operator::BitNot), "<len>" => Some(Operator::Length), - "<tal>" => Some(Operator::Tally), + "<sum>" => Some(Operator::Sum), "<abs>" => Some(Operator::Absolute), - _ => None, + _ => None, } } } @@ -88,7 +88,7 @@ impl std::fmt::Display for Operator { Operator::BitXor => "<xor>", Operator::BitNot => "<not>", Operator::Length => "<len>", - Operator::Tally => "<tal>", + Operator::Sum => "<sum>", Operator::Absolute => "<abs>", }; write!(f, "{string}") |