Types and Operators
Data Types
| Type | Description |
|---|---|
int | Arbitrary-precision mathematical integer (no fixed-width overflow; up to 1,048,576 bits). |
bool | Boolean truth value (True or False). |
bytes | Byte sequence (up to 16 MiB). |
string | Unicode text string. Used for error messages, hex/UTF-8 conversions, and f-strings; supports +, ==, and !=. |
list[T] | Homogeneous list where T is int, bool, bytes, or string. Nested lists (list[list[...]]) are not permitted. Up to 1,048,576 elements. |
tuple[...] | Used exclusively for multi-value function returns and unpacking assignments; cannot be stored in variables or lists. |
Script node input and output ports can use bytes, int, bool, and string. Lists and tuples are script-internal types.
Type Checking Rules
- A variable's type is determined at its first assignment and never changes. Reassigning a value of a different type is a compile-time error.
- No implicit type coercion: mixing
intandbool, orintandbytes, is rejected. Use built-in functions such asto_intandto_bytesfor explicit conversion. - Conditions in
if,elif, conditional expressions, and operands ofand/or/notmust have typebool. andandoruse short-circuit evaluation.
Definite Assignment Analysis
Every local variable must be assigned before it is read, and every output port variable must be definitely assigned along all non-failing execution paths by the end of the script:
- An
if/elif/elsestatement counts as assigning a variable only if every branch (including an explicitelse) assigns it or terminates viafail(...)/return. - Assignments inside a
forloop body do not count as definitely assigned after the loop, because the loop body might execute zero times.
if n > 100:
o = "big"
else:
o = "small"
Omitting the else branch above causes a compile-time SCRIPT_OUTPUT_UNASSIGNED diagnostic.
Value Semantics
All values—including bytes and list[T]—have value semantics. Variable assignment and function argument passing behave as independent copies; mutating a byte or list element in one variable never mutates another variable:
a = h"00 00"
b = a
b[0] = 255
Operators
Operator precedence matches Python. Bitwise operators bind tighter than comparisons, so x & 0x80 != 0 parses as (x & 0x80) != 0. Chained comparisons (a < b < c) are rejected.
| Operator | Operands | Result | Meaning |
|---|---|---|---|
+ | int, int | int | Addition |
+ | bytes, bytes | bytes | Concatenation |
+ | string, string | string | String concatenation |
+ | list[T], list[T] | list[T] | List concatenation |
-, * | int, int | int | Subtraction, multiplication |
* | bytes, int (or int, bytes) | bytes | Byte repetition (negative count raises BYTES_INVALID_ARGUMENT) |
//, % | int, int | int | Floor division and modulo (remainder sign matches divisor; divisor 0 raises SCRIPT_DIVISION_BY_ZERO) |
Unary - | int | int | Arithmetic negation |
&, |, ^, ~ | int | int | Two's-complement bitwise operations |
<<, >> | int, int | int | Arithmetic bit shift (negative shift count raises SCRIPT_INVALID_ARGUMENT) |
&, |, ^ | bytes, bytes | bytes | Bytewise AND, OR, XOR (unequal lengths raise BYTES_LENGTH_MISMATCH) |
~ | bytes | bytes | Bitwise NOT across all bytes |
<<, >> | bytes, int | bytes | Whole-buffer bit shift preserving byte length (carries cross byte boundaries; vacant bits zero-filled) |
==, != | Same type | bool | Equality / inequality |
<, <=, >, >= | int, int | bool | Numeric ordering |
<, <=, >, >= | bytes, bytes | bool | Lexicographical byte ordering |
and, or, not | bool | bool | Boolean logic |
Operator Examples
| Expression | Result |
|---|---|
2 + 3 * 4 | 14 |
7 // 2 | 3 |
-7 // 2 | -4 (floor division) |
-7 % 2 | 1 |
7 % -2 | -1 (sign of divisor) |
0xF0 & 0x3C | 48 (0x30) |
0xF0 | 0x0F | 255 |
0xFF ^ 0x0F | 240 (0xF0) |
~5 | -6 |
1 << 8 | 256 |
-16 >> 2 | -4 (arithmetic shift) |
h"0f f0" & h"3c 3c" | 0c30 |
h"0f" | h"f0" | ff |
h"ff" ^ h"0f" | f0 |
~h"0f" | f0 |
h"81 00" << 1 | 0200 (length preserved, overflow bit dropped) |
h"81 00" >> 1 | 4080 |
h"01" + h"02" | 0102 |
h"00" * 3 | 000000 |
2 * h"ff" | ffff |
"ab" + "cd" | abcd |
h"01 02" < h"01 03" | True (lexicographical) |
h"01" < h"01 00" | True (shorter prefix is smaller) |
h"01" == h"02" | False |
x == 0 and not (x > 1) | True |