Expand description
AWK operation IDs for Op::ExtendedWide(id, payload) dispatch.
These IDs are used by AWK frontends (awkrs) to emit bytecode that drives
AWK-specific semantics — field access, record I/O, print/printf, the
string builtins (sub/gsub/split/sprintf/match/…), and special
variables (NF/NR/FS/OFS/…) — through a registered AwkHost.
Unlike the universal arithmetic/array ops (which the VM executes natively),
AWK ops cannot use fusevm::Value faithfully: AWK has POSIX numeric-string
duality, CONVFMT/OFMT formatting, field/$0 coupling, and SUBSEP
associative arrays. Those semantics live host-side. The VM dispatches the
AWK op range to vm.awk_host (see crate::vm::VM::set_awk_host); operands
that aren’t carried in the payload come from the value stack.
§Encoding
AWK ops are emitted as Op::ExtendedWide(id, payload) where id is one of
the constants below (all >= AWK_OP_BASE). payload carries the inline
integer operand for ops that need one (field index for field ops, argument
count for variadic ops, name-pool index for special-variable ops). Value
operands are pushed on the stack in source order before the op.
use fusevm::{ChunkBuilder, Op};
use fusevm::awk_builtins::*;
// `$1` — push the field index, then read the field.
let mut b = ChunkBuilder::new();
b.emit(Op::LoadInt(1), 1);
b.emit(Op::ExtendedWide(AWK_FIELD_GET, 0), 1);Modules§
- getline_
source getlinesource kinds carried in theAWK_GETLINEpayload.- signal
- AWK control-flow signal codes carried by
Op::AwkSignal(code). The op halts the chunk; the frontend driver readsVM::awk_signal()and maps the code to its own control-flow (next record / next file / exit).
Constants§
- AWK_AND
and(v1, v2, ...)— bitwise AND of ≥2 args. Payload = argument count.- AWK_
ARRAY_ CLEAR delete arr— clear the whole array (no stack operand).- AWK_
ARRAY_ DELETE delete arr[k]— stack[key].- AWK_
ARRAY_ EXISTS (k in arr)— stack[key]; pushes Bool.- AWK_
ARRAY_ GET arr[k]— stack[key]; pushes the element (auto-vivifies to “” per POSIX).- AWK_
ARRAY_ LEN length(arr)— push the element count.- AWK_
ARRAY_ SET arr[k] = v— stack[value, key].- AWK_
ATAN2 atan2(y, x)— arctangent ofy/x. Stack[y, x].- AWK_CHR
chr(n)— single-character string for codepointn(empty if invalid). Pops one argument, pushes a string.- AWK_
COMPL compl(v)— bitwise complement. Stack[v].- AWK_COS
cos(x)— cosine (radians). Stack[x].- AWK_EXP
exp(x)— e^x. Stack[x].- AWK_
FIELD_ GET $i— read fieldi.iis popped from the stack; pushes the field value.- AWK_
FIELD_ SET $i = v— assign fieldi. Stack:[value, index]; rebuilds$0/NF.- AWK_
GENSUB gensub(re, repl, how [, target])— returntarget(or$0when omitted) withrematches replaced perhow("g"/"G"= all, positive integer = that occurrence), expanding&and\1..\9backrefs inrepl. Payload = argument count (3..=4). Pushes the result string. Host-bound: regex compilation honorsIGNORECASEand the 3-arg form reads$0.- AWK_
GETLINE getlinefamily.payloadencodes the source (plain/var/file/cmd). Stack holds the source operand (file/cmd string) when applicable; pushes status (1 = record read, 0 = EOF, -1 = error).- AWK_
GSUB gsub(re, repl [, target])— popspayloadargs; pushes substitution count.- AWK_
INDEX index(s, t)— stack[s, t]; pushes 1-based position or 0.- AWK_INT
int(x)— truncate toward zero. Stack[x].- AWK_
INTDIV intdiv(a, b)— integer (truncating) quotienta / bas a number. Non-bignum path only; division by zero pushesUndef(a host may raise the gawk fatal). Pops two arguments, pushes a number.- AWK_
INTDI V0 intdiv0(a, b)— likeintdiv, but division by zero yields0(the “safe” gawk variant; never errors). Pops two arguments, pushes a number.- AWK_
LENGTH length/length(x)— popspayloadargs (0 ⇒length($0)).- AWK_LOG
log(x)— natural log. Stack[x].- AWK_
LSHIFT lshift(v, n)— left shiftvbyn & 0x3fbits. Stack[v, n].- AWK_
MATCH match(s, re)— stack[s, re]; setsRSTART/RLENGTH, pushesRSTART.- AWK_
MKBOOL mkbool(x)—1ifxis truthy, else0. Pops one argument, pushes a number.- AWK_
MKTIME mktime(datespec [, utc])—"YYYY MM DD HH MM SS"→ epoch seconds (or -1). Payload = argument count (1..=2). Pushes a number. Host-independent.- AWK_NF
NF— push the current field count.- AWK_
OP_ BASE - First AWK op ID. The VM routes
ExtendedWideops withid >= AWK_OP_BASE(and< AWK_OP_END) to the registeredAwkHost. Chosen high to leave the lowExtended/ExtendedWideid space free for generic frontend handlers (stryke, etc.) that useset_extension_wide_handler. - AWK_
OP_ END - One past the last AWK op ID (exclusive upper bound of the reserved range).
- AWK_OR
or(v1, v2, ...)— bitwise OR of ≥2 args. Payload = argument count.- AWK_ORD
ord(s)— Unicode scalar value of the first character ofs(0 if empty). Nullary payload-free; pops one argument, pushes a number.- AWK_
PRINT print a, b, ...— popspayloadargs, joins withOFS, ends withORS.- AWK_
PRINTF printf fmt, a, ...— popspayloadargs (last popped is the format).- AWK_
RAND rand()— next pseudo-random number in[0, 1). Nullary; pushes a number. Advances the VM-owned LCG seed. Host-independent.- AWK_
RSHIFT rshift(v, n)— right shiftvbyn & 0x3fbits. Stack[v, n].- AWK_
SET_ RECORD $0 = v— replace the whole record. Stack:[value]; resplits fields.- AWK_SIN
sin(x)— sine (radians). Stack[x].- AWK_
SPECIAL_ GET - Read a special AWK variable by name-pool index (
FS/OFS/ORS/RS/NR/FNR/SUBSEP/RSTART/RLENGTH/FILENAME/CONVFMT/OFMT/…). - AWK_
SPECIAL_ SET - Assign a special AWK variable by name-pool index. Stack:
[value]. - AWK_
SPLIT split(s, arr [, fs])— popspayloadargs; pushes field count.- AWK_
SPRINTF sprintf(fmt, a, ...)— likeAWK_PRINTFbut pushes the formatted string.- AWK_
SQRT sqrt(x)— square root. Stack[x].- AWK_
SRAND srand([x])— reseed the PRNG, returning the previous seed (low 32 bits). Payload = argument count (0 → seed from clock, 1 → seed from popped value).- AWK_
STRFTIME strftime([fmt [, ts [, utc]]])— format a timestamp. Payload = argument count (0..=3). Pushes a string. Host-independent (chrono + system tz).- AWK_
STRTONUM strtonum(s)— parse0x…hex,0…octal, else longest decimal/float prefix. Stack[s]; returns a number. Host-independent.- AWK_SUB
sub(re, repl [, target])— popspayloadargs; pushes substitution count.- AWK_
SUBSTR substr(s, m [, n])— popspayloadargs (2 or 3).- AWK_
SYSTIME systime()— seconds since the Unix epoch. Nullary; pushes a number. Host-independent (reads the system clock viastd::time, no deps).- AWK_
TOLOWER tolower(s)— stack[s].- AWK_
TOUPPER toupper(s)— stack[s].- AWK_XOR
xor(v1, v2, ...)— bitwise XOR of ≥2 args. Payload = argument count.
Functions§
- is_
awk_ op - True when
idfalls in the reserved AWK op range.