table of contents
MAWK-CODE(7) | Miscellaneous | MAWK-CODE(7) |
NAME¶
mawk-code - dumping mawk's byte-code
SYNOPSIS¶
At startup, mawk compiles the script into byte-code. After that, it interprets the compiled byte-code. Use the -Wdump option to show the byte-code.
PROGRAM CODES¶
As mawk executes the program, it maintains a reference to the command to execute in cdp. After that there may be data and/or references in cdp[0], cdp[1], etc.
When an operation requires operands, mawk pushes the values (or array/string references) onto the stack, which updates the stack pointer sp. When the operation completes, mawk consumes those entries on the stack, pushing the result (if any) onto the stack.
While executing user-defined functions, mawk maintains a frame pointer fp to address the function's local variables.
a_cat¶
Concatenate array-indices.
Usage:
Parameters:
- cdp[0]
-
cnt, the number of elements to concatenate follows the command. - sp[0]..sp[1-cnt]
- hold reference to the elements to concatenate.
a_del¶
Delete an array item.
Usage:
Parameters:
a_length¶
Find the length of an array.
Usage:
Parameters:
- sp[0]
- points to array.
Returns the length of the array in sp[0].
a_pusha¶
Push array address onto stack.
Usage:
Parameters:
- cdp[0]
- array reference follows the command.
Returns the array in sp[0].
a_test¶
Test if an expression is present in an array.
Usage:
Parameters:
Returns 1 in sp[0] if the expression is found, 0 otherwise.
add¶
Add two numbers.
Usage:
Parameters:
Returns the sum in sp[0].
add_asg¶
Combined addition/assignment.
Usage:
Parameters:
Stores the sum in the target, leaving sp[0] pointing to the target.
ae_pusha¶
Push reference to array cell, given expression for its index.
Usage:
Parameters:
Returns a reference to the addressed cell in sp[0].
ae_pushi¶
Push contents of array cell, given expression for its index.
Usage:
Parameters:
- sp[0]
- has an expression, used for the index of a cell in the array.
Returns contents of the addressed cell in sp[0].
aloop¶
Update reference to next cell for array loop.
Usage:
Parameters:
Mawk maintains a stack of array-loop state. It updates the array/cell references in the current loop's state.
assign¶
Assigns a value.
Usage:
Parameters:
atan2¶
Compute arc-tangent of two values.
Usage:
Parameters:
Returns the result in sp[0].
call¶
Call a function.
Usage:
Parameters:
Returns function value in sp[0].
cat¶
Concatenate two strings.
Usage:
Parameters:
Returns the result in sp[0].
close¶
Close the file or pipe associated with an expression.
Usage:
Parameters:
- sp[0]
- holds the expression identifying the file to close
Returns the status from closing the file, 0 on success or -1 on failure.
cos¶
Compute the cosine of a value in radians.
Usage:
Parameters:
- sp[0]
- is the value.
Returns the result in sp[0].
del_a¶
Delete an array.
Usage:
Parameters:
- sp[0]
- is the array to delete.
div¶
Divide one number by another.
Usage:
Parameters:
Returns the quotient in sp[0].
div_asg¶
Combined division/assignment.
Usage:
Parameters:
Stores the quotient in the target, leaving sp[0] pointing to the target.
eq¶
Compare two values.
Usage:
Parameters:
Returns 1 in sp[0] if the values are equal, otherwise 0.
exit¶
Exits mawk with a specific exit-code.
Usage:
Parameters:
- sp[0]
- is the exit_code
exit0¶
Exits mawk with success
Usage:
Parameters:
exp¶
Compute base-e exponential function of a value.
Usage:
Parameters:
- sp[0]
- is the value
Returns the result in sp[0].
f_add_asg¶
Combination addition/assignment to NF.
Usage:
Parameters:
- sp[0]
- is the expression to add
f_assign¶
Assign an expression to NF.
Usage:
Parameters:
- sp[0]
- is the expression
f_div_asg¶
Combination division/assignment to NF.
Usage:
Parameters:
- sp[0]
- is the expression
f_mod_asg¶
Combination modulus/assignment to NF.
Usage:
Parameters:
- sp[0]
- is the expression
f_mul_asg¶
Combination multiplication/assignment to NF.
Usage:
Parameters:
- sp[0]
- is the expression
f_post_dec¶
Post-decrement using NF.
Usage:
Parameters:
f_post_inc¶
Post-increment using NF.
Usage:
Parameters:
f_pow_asg¶
Exponentiation using NF.
Usage:
Parameters:
- sp[0]
- is the expression to use
f_pre_dec¶
Predecrement using NF.
Usage:
Parameters:
- sp[0]
- holds a reference to the field to use
f_pre_inc¶
Preincrement using NF.
Usage:
Parameters:
- sp[0]
- holds a reference to the field to use
f_pusha¶
Push array reference to data split-up as fields..
Usage:
getline
Parameters:
- cdp[0]
- is a reference to the data to be split/assigned.
Returns the resulting array reference in sp[0].
f_pushi¶
Push contents of numbered field.
Usage:
Parameters:
Returns the field's value in sp[0].
f_sub_asg¶
Combination subtraction/assignment to NF.
Usage:
Parameters:
- sp[0]
- holds a reference to the field to use
fe_pusha¶
Push reference to numbered field.
Usage:
Parameters:
- sp[0]
- holds the field number
Returns a reference to the field in sp[0].
fe_pushi¶
Push content of numbered field.
Usage:
Parameters:
- sp[0]
- holds the field number
Returns the field's content in sp[0].
fflush¶
Flush the output file or pipe associated with an expression.
Usage:
Parameters:
- sp[0]
- is the expression value
Returns the result in sp[0].
gt¶
Test if first value is greater than the second.
Usage:
Parameters:
Returns 1 in sp[0] if the first value is greater than, otherwise 0.
gte¶
Test if first value is greater than or equal to the second.
Usage:
Parameters:
Returns 1 in sp[0] if the first value is greater than or equal, otherwise 0.
index¶
Find the position of the second string in the first.
Usage:
Parameters:
Returns the position in sp[0] starting at 1 if found, 0 if not found.
int¶
Returns a value truncated towards zero..
Usage:
Parameters:
- sp[0]
- is the value
Returns the result in sp[0].
jmain¶
Go from BEGIN code to MAIN code.
Usage:
Parameters:
jmp¶
Jump to a new byte-code position, by a given number of bytes.
Usage:
Parameters:
- cdp[0]
- holds the (signed) number of bytes by which to jump.
jnz¶
Jump to a new byte-code position if sp[0] is nonzero, by a given number of bytes.
Usage:
Parameters:
jz¶
Jump to a new byte-code position if sp[0] is zero, by a given number of bytes.
Usage:
Parameters:
l_pusha¶
Push a local address onto the evaluation stack.
Usage:
Parameters:
- cdp[0]
-
holds the offset from the frame pointer fp.
Returns the address in sp[0].
l_pushi¶
Push contents of a local variable onto the evaluation stack.
Usage:
Parameters:
- cdp[0]
-
holds the offset from the frame pointer fp.
Returns the contents of the local variable in sp[0].
la_pusha¶
Pushes a reference to an array onto the evaluation stack.
Usage:
Parameters:
- cdp[0]
-
holds the offset from the frame pointer fp of a reference to an array.
Returns a reference to the array in sp[0].
lae_pusha¶
Pushes a reference to a given array cell onto the evaluation stack.
Usage:
Parameters:
Returns a reference to the specified array cell in sp[0].
lae_pushi¶
Pushes the contents of a given array cell onto the evaluation stack.
Usage:
Parameters:
Returns the contents of the specified array cell in sp[0].
length¶
Returns the length of a string or array value.
Usage:
Parameters:
- sp[0]
- is the string or array reference
Returns the length in sp[0].
ljnz¶
Special jump for logical-OR, always preceded by test.
Usage:
Parameters:
ljz¶
Special jump for logical-OR, always preceded by test.
Usage:
Parameters:
log¶
Compute the natural logarithm of a value.
Usage:
Parameters:
- sp[0]
- is the value
Returns the result in sp[0].
lt¶
Test if first value is less than the second.
Usage:
Parameters:
Returns 1 in sp[0] if the first value is less than, otherwise 0.
lte¶
Test if first value is less than or equal to the second.
Usage:
Parameters:
Returns 1 in sp[0] if the first value is less than or equal, otherwise 0.
match0¶
Test if $0 matches a given regular expression.
Usage:
Parameters:
- cdp[0]
-
holds a reference to a regular expression.
Returns 1 in sp[0] if $0 matches the regular expression, 0 otherwise.
match1¶
Test if a given expression matches a given regular expression.
Usage:
Parameters:
Returns 1 in sp[0] if the expression matches the regular expression, 0 otherwise.
match2¶
Test if an expression in sp[-1] matches the regular expression in sp[0].
Usage:
Parameters:
Returns 1 in sp[0] if the expression matches the regular expression, 0 otherwise.
mktime¶
Converts a date specification in systime format to a timestamp.
Usage:
Parameters:
- sp[0]
- holds the date-specification string
Returns the result in sp[0].
mod¶
Compute modulus/remainder with two operands.
Usage:
Parameters:
Returns the remainder in sp[0].
mod_asg¶
Assign modulus/remainder with two operands.
Usage:
Parameters:
Returns the remainder in sp[0] as well as replacing the first value.
mul¶
Compute product with two operands.
Usage:
Parameters:
Returns the product in sp[0].
mul_asg¶
Assign product with two operands.
Usage:
Parameters:
Returns the product in sp[0] as well as replacing the first value.
neq¶
Compare two values.
Usage:
Parameters:
Returns 1 in sp[0] if the values are not equal, otherwise 0.
next¶
Read the next record, restart pattern testing.
Usage:
Parameters:
nextfile¶
Begin processing the next file listed on the command line.
Usage:
Parameters:
nf_pushi¶
Push the number of fields (NF) onto the evaluation stack.
Usage:
Parameters:
not¶
Compute a logical negation.
Usage:
Parameters:
- sp[0]
- holds a value to negate.
Returns the result on the evaluation stack, i.e., 0 if the value is nonzero and 1 otherwise.
ol_gl¶
Read into $0 using getline.
Usage:
Parameters:
ol_gl_nr¶
Read into $0 using getline, updating NR and FNR.
Usage:
Parameters:
omain¶
Start executing the main section of the script (between BEGIN and END).
Usage:
Parameters:
pop¶
Pop the evaluation stack, discarding the value.
Usage:
Parameters:
pop_al¶
Finish an array “in” loop, deallocating the state information.
Usage:
Parameters:
post_dec¶
Post-decrement a value.
Usage:
Parameters:
- sp[0]
- holds the value to decrement
Returns the updated value in sp[0].
post_inc¶
Post-increment a value.
Usage:
Parameters:
- sp[0]
- holds the value to increment
Returns the updated value in sp[0].
pow¶
Compute the first value raised to the power of the second value.
Usage:
Parameters:
Returns the result in sp[0].
pow_asg¶
Assign the first value raised to the power of the second value.
Usage:
Parameters:
pre_dec¶
Pre-decrement a value.
Usage:
Parameters:
- sp[0]
- holds the value to decrement.
Returns the updated value in sp[0];.
pre_inc¶
Pre-increment a value.
Usage:
Parameters:
- sp[0]
- holds the value to decrement.
Returns the updated value in sp[0];.
pusha¶
Push array address onto stack.
Usage:
Parameters:
- cdp[0]
- array reference follows the command.
Returns the array in sp[0].
pushc¶
Push a data cell onto the evaluation stack.
Usage:
Parameters:
- cdp[0]
- is a reference to the data to push
Returns a reference to the result in sp[0].
pushd¶
Push a double floating value onto the evaluation stack.
Usage:
Parameters:
- cdp[0]
- is a reference to the data to push
Returns a reference to the result in sp[0].
pushi¶
Push contents of next referenced variable onto the evaluation stack.
Usage:
Parameters:
- cdp[0]
- is a reference to the data cell to copy.
Returns a reference to the result in sp[0].
pushint¶
Reserve the next slot on the evaluation stack, setting its type.
Usage:
Parameters:
- cdp[0]
- holds the type to set in the new slot, e.g., for data via I/O redirection
Returns a reference to the result in sp[0].
pushs¶
Push a reference to a string value onto the evaluation stack.
Usage:
Parameters:
- cdp[0]
- holds a reference to the string value
Returns a reference to the result in sp[0].
rand¶
Returns a random number between zero and one..
Usage:
Parameters:
Returns the result in sp[0].
range¶
Test a range pattern: pat1, pat2 { action }.
Usage:
Parameters:
ret¶
Return a function value.
Usage:
Parameters:
- sp[0]
- holds the return value
When calling a function, mawk saves the current stack, creating a new one. On return, mawk restores the previous stack and returns the function value in sp[0].
ret0¶
Return from a function without providing a return-value.
Usage:
Parameters:
- sp[0]
- is modified to make the value uninitialized.
As in the ret operation, mawk restores the previous stack. After the return, sp[0] is an uninitialized value.
set_al¶
Begin an array “in” loop.
Usage:
Parameters:
Mawk pushes a new entry onto the array loop stack, and updates cdp to point to the statement to execute.
sin¶
Compute the sine of a value in radians.
Usage:
Parameters:
- sp[0]
- holds the value
Returns the result in sp[0].
sprintf¶
Returns a string constructed from expression-list according to format.
Usage:
Parameters:
- sp[0]
- is the last parameter value; there can be up to 255.
sqrt¶
Returns the square root of a value.
Usage:
Parameters:
- sp[0]
- is the value
Returns the result in sp[0].
srand¶
Seeds the random number generator.
Usage:
srand( )
Parameters:
- sp[0]
- is the seed value, which may be uninitialized
Returns the previous seed value in sp[0].
stop¶
Finish a range pattern.
Usage:
Parameters:
strftime¶
Formats the given timestamp using the given format.
Usage:
strftime( format , timestamp )
strftime( format )
strftime( )
Parameters:
Zero to three parameters may be on the stack. If all three are used, they are as follows:
Returns the result in sp[0].
sub¶
Subtract the second value from the first.
Usage:
Parameters:
sub_asg¶
Assign the difference of two values to a variable.
Usage:
Parameters:
Stores the difference in the target, leaving sp[0] pointing to the target.
substr¶
eturns the substring of string s, starting at index i, of length n.
Usage:
substr(s,i)
Parameters:
system¶
Executes a command, returning the wait-status.
Usage:
Parameters:
- sp[0]
- is the command to execute
Returns the wait-status in sp[0].
systime¶
Returns the current time of day as the number of seconds since the Epoch.
Usage:
Parameters:
Returns the result in sp[0].
test¶
Test a logical expression.
Usage:
Parameters:
- sp[0]
- holds a value to test.
Returns the result on the evaluation stack, i.e., 1 if the value is nonzero and 0 otherwise.
tolower¶
Copy a string, converting to lowercase.
Usage:
Parameters:
- sp[0]
- is the value to convert
Returns the result in sp[0].
toupper¶
Copy a string, converting to uppercase.
Usage:
Parameters:
- sp[0]
- is the value to convert
Returns the result in sp[0].
uminus¶
Unitary minus.
Usage:
Parameters:
- sp[0]
- contains a value to negate. As a side-effect, if the value is a string, it is cast to double floating point.
Returns the result in sp[0].
uplus¶
Unitary plus.
Usage:
Parameters:
- sp[0]
- contains a value to use. As a side-effect, if the value is a string, it is cast to double floating point.
Returns the result in sp[0].
REGULAR EXPRESSIONS¶
M_1J¶
mandatory jump
M_2JA¶
optional (undesirable) jump
M_2JB¶
optional (desirable) jump
M_2JC¶
pop pos'n, optional jump if advanced
M_ACCEPT¶
end of match
M_ANY¶
arbitrary character (.)
M_CLASS¶
character class
M_END¶
end of string ($)
M_SAVE_POS¶
push position onto stack
M_START¶
start of string (^)
M_STR¶
matching a literal string
M_U¶
arbitrary string (.*)
2024-01-23 | Version 1.3.4 |