module Termisu::Terminfo::Tparm::Operations

Overview

Operations lookup tables for tparm processor.

This module provides dispatch tables for the tparm stack machine. The terminfo parametrized string format uses a stack-based language where operations pop operands from the stack, compute results, and push them back.

Operation Categories

Performance

Optimized for high-frequency operations like cursor positioning (cup) and color setting (setaf/setab) which are called thousands of times per frame.

Defined in:

termisu/terminfo/tparm/operations.cr

Constant Summary

ALL_OPS = ((OUTPUT_OPS | VARIABLE_OPS) | CONSTANT_OPS) | SPECIAL_OPS

All non-binary operation characters for fast membership testing. Used to quickly determine if a character is a known operation.

BINARY = {'+' => ->(left : Int64, right : Int64) do left + right end, '-' => ->(left : Int64, right : Int64) do left - right end, '*' => ->(left : Int64, right : Int64) do left * right end, '/' => ->(left : Int64, right : Int64) do right != 0 ? left // right : 0_i64 end, 'm' => ->(left : Int64, right : Int64) do right != 0 ? left % right : 0_i64 end, '&' => ->(left : Int64, right : Int64) do left & right end, '|' => ->(left : Int64, right : Int64) do left | right end, '^' => ->(left : Int64, right : Int64) do left ^ right end, '=' => ->(left : Int64, right : Int64) do left == right ? 1_i64 : 0_i64 end, '<' => ->(left : Int64, right : Int64) do left < right ? 1_i64 : 0_i64 end, '>' => ->(left : Int64, right : Int64) do left > right ? 1_i64 : 0_i64 end, 'A' => ->(left : Int64, right : Int64) do ((left != 0) && (right != 0)) ? 1_i64 : 0_i64 end, 'O' => ->(left : Int64, right : Int64) do ((left != 0) || (right != 0)) ? 1_i64 : 0_i64 end}

Binary operations - arithmetic, bitwise, comparison, logical.

All binary ops pop two values (right first, then left), compute, and push result. Division and modulo return 0 on divide-by-zero to prevent crashes.

CONSTANT_OPS = Set {'\'', '{'}

Constant operations - push literal integer or character values.

OUTPUT_OPS = Set {'%', 'c', 'd', 's'}

Output format operations - pop and write to output buffer.

SPECIAL_OPS = Set {'i', 'l', '!', '~', '?'}

Special operations - control flow, unary operations, and special commands.

VARIABLE_OPS = Set {'p', 'P', 'g'}

Variable operations - parameter push and variable get/set.