arithmetic_op

Macro arithmetic_op 

Source
macro_rules! arithmetic_op {
    ($fn_name:ident, $op_name:literal, $op_sym:literal, $checked:ident, $wrapping:ident, $error_kind:literal) => { ... };
}
Expand description

Arithmetic operation helpers with overflow/underflow checking.

All arithmetic operations follow the same pattern:

  1. Determine if unsigned arithmetic should be used
  2. Coerce both operands to appropriate type (i64/u64)
  3. Perform operation with overflow checking (if strict_arithmetic is enabled)
  4. Return result as StackItem

The macros below generate the repetitive boilerplate for each operation. Macro to generate arithmetic operation functions (ADD, SUB, MUL).

§Syntax

arithmetic_op!(fn_name, op_name, op_sym, checked_fn, wrapping_fn, error_kind);

§Example

arithmetic_op!(add_stack_items, "ADD", "+", checked_add, wrapping_add, "overflow");