Skip to main content

Module op_table

Module op_table 

Source
Expand description

Operation table for dynamically dispatching operations based on type signatures.

This module provides a scope-based registry for operations that can be looked up based on an operation name (string) and the types of the operands. Built-in operations use compile-time hash tables (via phf) for efficient lookup, while custom operations can be added dynamically through scope functions.

§Design

  • Operator symbols as names: Operations are identified by their operator symbols (e.g., "+", "-", "*") to avoid conflicts with valid identifiers.
  • Function pointers: Built-in operations use stateless function pointers for zero-allocation dispatch.
  • Scope stack: Custom operations are handled through a stack of scope functions that can be pushed and popped as needed.
  • Type optimization: Most built-in operations are homogeneous (both operands share a type), so signatures store a primary TypeId plus arity. Heterogeneous binary ops (e.g. shifts, where the RHS is always u32) additionally store an RHS TypeId index.

§Semantics

Built-in operations follow Rust language semantics. Deviations are:

  • Signed integer overflow: CEL returns Err rather than panicking (debug) or wrapping (release). Use wrapping arithmetic explicitly if overflow is intended.
  • Bit-shift with out-of-range count: CEL returns Err rather than panicking (debug) or masking the shift count (release).

Structs§

OpLookup
Operation lookup with scope stack support.
OperandTypes
A single built-in overload’s declared operand types, exposed for the static type checker (cel_parser::ty::check_expr) — never op_fn, which is execution-only and stays private.
TupleOpSignature
A signature for an operator/function whose selected operand is a tuple.

Functions§

builtin_operand_types
Returns every built-in overload’s declared operand types for name, in registration order.
cast_source_types
Lists every source TypeId with a registered cast to target_name. Used by the type checker (ty.rs) to validate a cast without needing to touch a [DynSegment] - reads the exact same tables OpLookup::lookup_cast does, so the two can’t drift out of sync.

Type Aliases§

OpFn
A function that pushes an operation onto a DynSegment.
ScopeFn
A scope function that attempts to resolve and apply an operation.