From ace5677f87c2bc042d8d5e807ccea9ddcd828c9e Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 14 Oct 2025 15:36:36 +1300 Subject: Rename the operator to This is a more memorable name, and can be implemented for lists in the future as well. --- src/types/expression_stack.rs | 5 +++-- 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 { "" => Some(Operator::BitXor), "" => Some(Operator::BitNot), "" => Some(Operator::Length), - "" => Some(Operator::Tally), + "" => Some(Operator::Sum), "" => Some(Operator::Absolute), - _ => None, + _ => None, } } } @@ -88,7 +88,7 @@ impl std::fmt::Display for Operator { Operator::BitXor => "", Operator::BitNot => "", Operator::Length => "", - Operator::Tally => "", + Operator::Sum => "", Operator::Absolute => "", }; write!(f, "{string}") -- cgit v1.2.3-70-g09d2