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:
- Determine if unsigned arithmetic should be used
- Coerce both operands to appropriate type (i64/u64)
- Perform operation with overflow checking (if strict_arithmetic is enabled)
- 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");