Expand description
Arithmetic operations for Seq
These functions are exported with C ABI for LLVM codegen to call.
§Safety Contract
IMPORTANT: These functions are designed to be called ONLY by compiler-generated code, not by end users or arbitrary C code. The compiler’s type checker is responsible for:
- Ensuring stack has correct number of values
- Ensuring values are the correct types (Int for arithmetic, Int for comparisons)
- Preventing division by zero at compile time when possible
§Overflow Behavior
All arithmetic operations use wrapping semantics for predictable, defined behavior:
add: i64::MAX + 1 wraps to i64::MINsubtract: i64::MIN - 1 wraps to i64::MAXmultiply: overflow wraps arounddivide: i64::MIN / -1 wraps to i64::MIN (special case)
This matches the behavior of Forth and Factor, providing consistency for low-level code.
Re-exports§
pub use patch_seq_add as add;pub use patch_seq_and as and;pub use patch_seq_band as band;pub use patch_seq_bnot as bnot;pub use patch_seq_bor as bor;pub use patch_seq_bxor as bxor;pub use patch_seq_clz as clz;pub use patch_seq_ctz as ctz;pub use patch_seq_divide as divide;pub use patch_seq_eq as eq;pub use patch_seq_gt as gt;pub use patch_seq_gte as gte;pub use patch_seq_int_bits as int_bits;pub use patch_seq_lt as lt;pub use patch_seq_lte as lte;pub use patch_seq_multiply as multiply;pub use patch_seq_neq as neq;pub use patch_seq_not as not;pub use patch_seq_or as or;pub use patch_seq_popcount as popcount;pub use patch_seq_push_bool as push_bool;pub use patch_seq_push_int as push_int;pub use patch_seq_shl as shl;pub use patch_seq_shr as shr;pub use patch_seq_subtract as subtract;
Functions§
- patch_
seq_ ⚠add - Add two integers
- patch_
seq_ ⚠and - Logical AND operation (Forth-style: multiply for boolean values)
- patch_
seq_ ⚠band - Bitwise AND
- patch_
seq_ ⚠bnot - Bitwise NOT (one’s complement)
- patch_
seq_ ⚠bor - Bitwise OR
- patch_
seq_ ⚠bxor - Bitwise XOR
- patch_
seq_ ⚠clz - Count leading zeros
- patch_
seq_ ⚠ctz - Count trailing zeros
- patch_
seq_ ⚠divide - Divide two integers (a / b)
- patch_
seq_ ⚠eq - Integer equality: =
- patch_
seq_ ⚠gt - Greater than: >
- patch_
seq_ ⚠gte - Greater than or equal: >=
- patch_
seq_ ⚠int_ bits - Push the bit width of Int (64)
- patch_
seq_ ⚠lt - Less than: <
- patch_
seq_ ⚠lte - Less than or equal: <=
- patch_
seq_ ⚠multiply - Multiply two integers
- patch_
seq_ ⚠neq - Not equal: <>
- patch_
seq_ ⚠not - Logical NOT operation
- patch_
seq_ ⚠or - Logical OR operation (Forth-style)
- patch_
seq_ ⚠peek_ int_ value - Helper for peeking at the top integer value without popping
- patch_
seq_ ⚠pop_ stack - Helper for popping without extracting the value (for conditionals)
- patch_
seq_ ⚠popcount - Population count (count number of 1 bits)
- patch_
seq_ ⚠push_ bool - Push a boolean literal onto the stack (for compiler-generated code)
- patch_
seq_ ⚠push_ int - Push an integer literal onto the stack (for compiler-generated code)
- patch_
seq_ ⚠shl - Shift left
- patch_
seq_ ⚠shr - Logical shift right (zero-fill)
- patch_
seq_ ⚠subtract - Subtract two integers (a - b)