code <- r"(
# 1 + 2
LDCONST 1
LDCONST 2
ADD
RETURN
)"
asm(code) |> eval()[1] 3
This chapter has a complete listing of all bytecode instructions.
It includes a summary of what the bytecode does, the arguments required and an indication of the instructions stack usage.
Examples using this bytecode from bytecode assembly and R code are also included where possible.
ADDAdd values
| value | |
|---|---|
| Name | ADD |
| Value | 44 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
ADD Bytecode Assembly Examplecode <- r"(
# 1 + 2
LDCONST 1
LDCONST 2
ADD
RETURN
)"
asm(code) |> eval()[1] 3
ADD bytecodex + yGETVAR x
GETVAR y
ADD
RETURN
ANDVector logical AND
| value | |
|---|---|
| Name | AND |
| Value | 57 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
AND Bytecode Assembly Examplecode <- r"(
LDCONST c(TRUE, TRUE, FALSE, FALSE)
LDCONST c(FALSE, TRUE, FALSE, TRUE)
AND
RETURN
)"
asm(code) |> eval()[1] FALSE TRUE FALSE FALSE
AND bytecodex & yGETVAR x
GETVAR y
AND
RETURN
AND1STScalar logical AND (Part 1)
Scalar logical AND in R supports “short-circuiting” the operation i.e. if the first argument is FALSE, then the second argument is never evaluated.
The AND1ST instruction pops a value from the stack, and if FALSE jumps to the position specified in its label argument i.e. the position after the end of the trailing AND2ND statement.
Following the AND1ST instruction is the code for the right-hand side of the AND operation and which is concluded with an AND2ND statement.
| value | |
|---|---|
| Name | AND1ST |
| Value | 88 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location to jump to if first logical value is FALSE |
AND1ST Bytecode Assembly Examplecode <- r"(
# TRUE && FALSE
LDTRUE
AND1ST @label1
LDFALSE
AND2ND
@label1
RETURN
)"
asm(code) |> eval()[1] FALSE
AND1ST bytecodex && yGETVAR x
AND1ST @label1
GETVAR y
AND2ND
@label1
RETURN
AND2NDScalar logical AND (Part 2)
See the AND1ST instruction Section 9.3
| value | |
|---|---|
| Name | AND2ND |
| Value | 89 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
AND2ND Bytecode Assembly Examplecode <- r"(
LDTRUE
AND1ST @label1
LDFALSE
AND2ND
@label1
RETURN
)"
asm(code) |> eval()[1] FALSE
AND2ND bytecodex && yGETVAR x
AND1ST @label1
GETVAR y
AND2ND
@label1
RETURN
BASEGUARDGuard execution of base R functions
Baseguard guards against the scenario that the the following function is not the default function builtin to R.
If the fetched function is not identical to the builtin (because there is a user-defined function of the same name that takes precedence), then the expression (at the expridx) is evaluated in the interpreter instead.
| value | |
|---|---|
| Name | BASEGUARD |
| Value | 123 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location to jump to if function is not valid |
BASEGUARD Bytecode Assembly Examplecode <- r"(
BASEGUARD @label1
GETBUILTIN list
PUSHCONSTARG 1
PUSHCONSTARG 2
CALLBUILTIN
@label1
RETURN
)"
asm(code) |> eval()[[1]]
[1] 1
[[2]]
[1] 2
BASEGUARD bytecodelist(a, b, c)BASEGUARD @label1
GETBUILTIN list
GETVAR a
PUSHARG
GETVAR b
PUSHARG
GETVAR c
PUSHARG
CALLBUILTIN
@label1
RETURN
BCMISMATCHRaise error to indicate bytecode version mismatch
Raises an error indicating the bytecode version does not match the current bytecode engine in R.
This error could happen if bytecode compiled on an old version of R is exectuted on a newer version.
The bytecode version is stored as the first integer in the compiled bytecode.
As of R v4.3.1, bytecode is at version 12.
| value | |
|---|---|
| Name | BCMISMATCH |
| Value | 0 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 0 |
BRIFNOTBranch if not TRUE
Note: There is no instruction for “Branch if TRUE”
| value | |
|---|---|
| Name | BRIFNOT |
| Value | 3 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location to jump to if value popped off stack is FALSE |
BRIFNOT Bytecode Assembly Examplecode <- r"(
LDFALSE
BRIFNOT @label1
LDCONST 1
RETURN
@label1
LDCONST 2
RETURN
)"
asm(code) |> eval()[1] 2
BRIFNOT bytecodeif (x > 5) print('hello')GETVAR x
LDCONST 5
GT
BRIFNOT @label1
GETFUN print
PUSHCONSTARG "hello"
CALL
RETURN
@label1
LDNULL
INVISIBLE
RETURN
CALLCall function specified by GETFUN
The list of arguments (separate from the stack and the consts storage) is created by calls to PUSHARG, PUSHCONSTARG etc.
| value | |
|---|---|
| Name | CALL |
| Value | 38 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 1 |
CALL Bytecode Assembly Examplecode <- r"(
GETFUN print
PUSHCONSTARG "hello"
CALL
RETURN
)"
asm(code) |> eval()[1] "hello"
CALL bytecoderunif(3)GETFUN runif
PUSHCONSTARG 3
CALL
RETURN
CALLBUILTINCall a builtin function
The list of arguments (separate from the stack and the consts storage) is created by calls to PUSHARG, PUSHCONSTARG etc.
See Builtin Functions (Section 11.1) for background and a list of built-in functions.
| value | |
|---|---|
| Name | CALLBUILTIN |
| Value | 39 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 1 |
CALLBUILTIN Bytecode Assembly Examplecode <- r"(
GETBUILTIN list
PUSHCONSTARG 1
PUSHCONSTARG 2
CALLBUILTIN
RETURN
)"
asm(code) |> eval()[[1]]
[1] 1
[[2]]
[1] 2
CALLBUILTIN bytecodec(a, b, c)BASEGUARD @label1
GETBUILTIN c
GETVAR a
PUSHARG
GETVAR b
PUSHARG
GETVAR c
PUSHARG
CALLBUILTIN
@label1
RETURN
CALLSPECIALCall a special function
See Special Functions (Section 11.2) for background and a list of special functions.
Note that CALLSPECIAL takes a single argument that is the full expression of the function to be called including the arguments.
| value | |
|---|---|
| Name | CALLSPECIAL |
| Value | 40 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | asis | Character string which parses to a valid expression calling a “special” function. |
See Section 11.2 for more details. |
CALLSPECIAL Bytecode Assembly Examplecode <- r"(
CALLSPECIAL rep(1, 3)
RETURN
)"
asm(code) |> eval()[1] 1 1 1
CALLSPECIAL bytecoderep(1, 3)BASEGUARD @label1
CALLSPECIAL rep(1, 3)
@label1
RETURN
CHECKFUNCheck a function call is valid
This instruction checks that the value on top of the stack is a function. This is only needed when the function is referenced by something other than a symbol. E.g. list(10) does not generate this instruction, but get('list')(10) does.
| value | |
|---|---|
| Name | CHECKFUN |
| Value | 28 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | ? |
| Stack Push | ? |
CHECKFUN bytecodeget('list')(10)GETFUN get
PUSHCONSTARG "list"
CALL
CHECKFUN
PUSHCONSTARG 10
CALL
RETURN
COLONColon operator e.g. 1:5
| value | |
|---|---|
| Name | COLON |
| Value | 120 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
COLON Bytecode Assembly Examplecode <- r"(
LDCONST 1
LDCONST 5
COLON
RETURN
)"
asm(code) |> eval()[1] 1 2 3 4 5
COLON bytecodex:yGETVAR x
GETVAR y
COLON
RETURN
DDVALGet a double-dot value
| value | |
|---|---|
| Name | DDVAL |
| Value | 21 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of value to fetch |
DDVAL bytecodefunction(...) print(..3)MAKECLOSURE ...
GETFUN print
MAKEPROM
DDVAL ..3
RETURN
ENDMAKEPROM
CALL
RETURN
ENDMAKECLOSURE
RETURN
DDVAL_MISSOKGet a double-dot value. OK if it is missing
| value | |
|---|---|
| Name | DDVAL_MISSOK |
| Value | 93 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of value to fetch |
DECLNKDecrease link count on next stack item
The INCLNK and DECLNK instructions are used to protect evaluated arguents on the stack from modifications during evaluation of subsequent arguments.
Help needed: R code example which uses this instruction.
| value | |
|---|---|
| Name | DECLNK |
| Value | 125 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
DECLNK_NDecrease link count on N stack items
Same as DECLNK for for n values?
Help needed: R code example which uses this instruciton.
| value | |
|---|---|
| Name | DECLNK_N |
| Value | 126 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
| Argument | Type | Description |
|---|---|---|
| 1 | const | Integer count of items in the stack on which to decrease the link count. |
DECLNKSTKDecrease link count on the stack istelf after not-top-level complex assignment
Unprotect stack after non-top-level complex assignment. This instruction pairs with INCLNKSTK.
Help needed: R code example which uses this instruction.
| value | |
|---|---|
| Name | DECLNKSTK |
| Value | 128 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
DFLTCDeprecated instruction
This is a vestigal instruction that used to be paired with an opening STARTC to peform the equivalent of c(...).
Now that c() is a builtin function, use GETBUILTIN and CALLBUILTIN instead.
See also R source main/eval.c where comments indicate this OP is no longer used.
| value | |
|---|---|
| Name | DFLTC |
| Value | 68 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | NA |
| Stack Push | NA |
DFLTSUBASSIGNDefault subassignment with []
| value | |
|---|---|
| Name | DFLTSUBASSIGN |
| Value | 66 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
DFLTSUBASSIGN bytecodea[] <- 1LDCONST 1
STARTASSIGN a
STARTSUBASSIGN @label1
DOMISSING
DFLTSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
DFLTSUBASSIGN2Default subassignment with [[]]
| value | |
|---|---|
| Name | DFLTSUBASSIGN2 |
| Value | 72 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
DFLTSUBASSIGN2 bytecodea[[]] <- 1LDCONST 1
STARTASSIGN a
STARTSUBASSIGN2 @label1
DOMISSING
DFLTSUBASSIGN2
@label1
ENDASSIGN a
INVISIBLE
RETURN
DFLTSUBSETDefault subset with []
| value | |
|---|---|
| Name | DFLTSUBSET |
| Value | 64 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
DFLTSUBSET bytecodea[]GETVAR a
STARTSUBSET @label1
DOMISSING
DFLTSUBSET
@label1
RETURN
DFLTSUBSET2Default subset with [[]]
| value | |
|---|---|
| Name | DFLTSUBSET2 |
| Value | 70 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
DFLTSUBSET2 bytecodea[[]]GETVAR a
STARTSUBSET2 @label1
DOMISSING
DFLTSUBSET2
@label1
RETURN
DIVDivision
| value | |
|---|---|
| Name | DIV |
| Value | 47 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
DIV Bytecode Assembly Examplecode <- r"(
LDCONST 1
LDCONST 2
DIV
RETURN
)"
asm(code) |> eval()[1] 0.5
DIV bytecodex / yGETVAR x
GETVAR y
DIV
RETURN
DODOTSProcess ...
| value | |
|---|---|
| Name | DODOTS |
| Value | 32 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
DOLLAR$operator when used to fetch a value
| value | |
|---|---|
| Name | DOLLAR |
| Value | 73 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | name | RHS name for $. LHS is popped from stack. |
DOLLAR bytecodex$yGETVAR x
DOLLAR y
RETURN
DOLLARGETS$ operator when used to set a value
| value | |
|---|---|
| Name | DOLLARGETS |
| Value | 74 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | |
| Stack Push |
| Argument | Type | Description |
|---|---|---|
| 1 | name | RHS name for $. LHS is popped from stack. |
DOLLARGETS bytecodea$b <- 3LDCONST 3
STARTASSIGN a
DOLLARGETS b
ENDASSIGN a
INVISIBLE
RETURN
DOLOOPBREAKPurpose currently unknown.
Help needed: do not currently know what this bytecode is for or how to generate it from R code compilation.
| value | |
|---|---|
| Name | DOLOOPBREAK |
| Value | 10 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
DOLOOPNEXTPurpose currently unknown.
Help needed: do not currently know what this bytecode is for or how to generate it from R code compilation.
| value | |
|---|---|
| Name | DOLOOPNEXT |
| Value | 9 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
DOMISSINGHandle missing arguments
Handling for missing arguments when function arguments being assessed at time of call
| value | |
|---|---|
| Name | DOMISSING |
| Value | 30 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
DOMISSING bytecodef(x = )GETFUN f
DOMISSING
SETTAG x
CALL
RETURN
DOTCALLCall a C function
This instruction is a specialised call for up to 16 arguments. For 17 or more arguments, need to use CALLBUILTIN instead.
| value | |
|---|---|
| Name | DOTCALL |
| Value | 119 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | |
| Stack Push |
| Argument | Type | Description |
|---|---|---|
| 1 | value | Number of arguments to this call. |
DOTCALL bytecode.Call(hello, x, y, z)BASEGUARD @label1
GETVAR hello
GETVAR x
GETVAR y
GETVAR z
DOTCALL 3
@label1
RETURN
DOTSERRTrigger error when ... used out of context
| value | |
|---|---|
| Name | DOTSERR |
| Value | 60 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
DOTSERR Bytecode Assembly Examplecode <- r"(
DOTSERR
RETURN
)"
asm(code) |> eval()Error in stop("{rbytecode}"): '...' used in an incorrect context
DUPDuplicate the top value in the stack to make it the first two values in the stack.
| value | |
|---|---|
| Name | DUP |
| Value | 5 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 2 |
DUP Bytecode Assembly Examplecode <- r"(
LDCONST 1
DUP
ADD
RETURN
)"
asm(code) |> eval()[1] 2
DUP2NDDuplicate the second value in the stack to push it onto the stack (so it is the first item)
| value | |
|---|---|
| Name | DUP2ND |
| Value | 101 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 2 |
| Stack Push | 3 |
DUP2ND Bytecode Assembly Examplecode <- r"(
LDCONST 10
LDCONST 20
DUP2ND
RETURN
)"
asm(code) |> eval()[1] 10
ENDASSIGNMark the end of an assignment operation started with STARTASSIGN
| value | |
|---|---|
| Name | ENDASSIGN |
| Value | 62 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of variable into which value is being assigned |
ENDASSIGN bytecodea[1] <- 2LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
ENDASSIGN2Mark the end of an assignment operation started with STARTASSIGN2
| value | |
|---|---|
| Name | ENDASSIGN2 |
| Value | 97 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of variable into which value is being assigned |
ENDFORSignify end of for loop.
See also STEPFOR Section 9.115 and STARTFOR Section 9.105.
| value | |
|---|---|
| Name | ENDFOR |
| Value | 13 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
ENDFOR bytecodefor(i in 1:3) {print(i)}LDCONST 1:3
STARTFOR i @label1
@label2
GETFUN print
MAKEPROM
GETVAR i
RETURN
ENDMAKEPROM
CALL
POP
@label1
STEPFOR @label2
ENDFOR
INVISIBLE
RETURN
ENDLOOPCNTXTEnd loop context
See STARTLOOPCNTXT (Section 9.106)
| value | |
|---|---|
| Name | ENDLOOPCNTXT |
| Value | 8 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | |
| Stack Push |
EQTest equality
| value | |
|---|---|
| Name | EQ |
| Value | 51 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
EQ Bytecode Assembly Examplecode <- r"(
LDCONST 2
LDCONST 2
EQ
RETURN
)"
asm(code) |> eval()[1] TRUE
EQ bytecodex == 4GETVAR x
LDCONST 4
EQ
RETURN
EXPExponential
| value | |
|---|---|
| Name | EXP |
| Value | 50 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
EXP Bytecode Assembly Examplecode <- r"(
LDCONST 2
EXP
RETURN
)"
asm(code) |> eval()[1] 7.389056
EXP bytecodeexp(x)BASEGUARD @label1
GETVAR x
EXP
@label1
RETURN
EXPTExponent.
| value | |
|---|---|
| Name | EXPT |
| Value | 48 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
EXPT Bytecode Assembly Examplecode <- r"(
LDCONST 2
LDCONST 3
EXPT
RETURN
)"
asm(code) |> eval()[1] 8
EXPT bytecodex^2GETVAR x
LDCONST 2
EXPT
RETURN
GETest greater than or equal to
| value | |
|---|---|
| Name | GE |
| Value | 55 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
GE Bytecode Assembly Examplecode <- r"(
LDCONST 7
LDCONST 5
GE
RETURN
)"
asm(code) |> eval()[1] TRUE
GE bytecodex >= 5GETVAR x
LDCONST 5
GE
RETURN
GETBUILTINGet a built-in function
| value | |
|---|---|
| Name | GETBUILTIN |
| Value | 26 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of builtin function. See Section 11.1 for more details. |
GETBUILTIN Bytecode Assembly Examplecode <- r"(
GETBUILTIN list
PUSHCONSTARG 1.23
CALLBUILTIN
RETURN
)"
asm(code) |> eval()[[1]]
[1] 1.23
GETBUILTIN bytecodelist(1, x)BASEGUARD @label1
GETBUILTIN list
PUSHCONSTARG 1
GETVAR x
PUSHARG
CALLBUILTIN
@label1
RETURN
GETFUNGet a named function
| value | |
|---|---|
| Name | GETFUN |
| Value | 23 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of function |
GETFUN Bytecode Assembly Examplecode <- r"(
GETFUN runif
PUSHCONSTARG 3
CALL
RETURN
)"
asm(code) |> eval()[1] 0.01726767 0.25755519 0.46669281
GETFUN bytecodefn(1)GETFUN fn
PUSHCONSTARG 1
CALL
RETURN
GETGLOBFUNGet a named function from the global environment (Unconfirmed)
Help needed: R code which uses this instruction.
| value | |
|---|---|
| Name | GETGLOBFUN |
| Value | 24 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of function |
GETINTLBUILTINGet an internal function
| value | |
|---|---|
| Name | GETINTLBUILTIN |
| Value | 27 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of function |
GETINTLBUILTIN bytecode.Internal(disassemble(asm("RETURN")))BASEGUARD @label1
GETINTLBUILTIN disassemble
GETFUN asm
PUSHCONSTARG "RETURN"
CALL
PUSHARG
CALLBUILTIN
@label1
RETURN
GETSYMFUNGet a function by its symbol (Unconfirmed)
Help needed: R code which uses this instruction.
| value | |
|---|---|
| Name | GETSYMFUN |
| Value | 25 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of function |
GETTER_CALLUsed in complex assignment expressions
Help needed: R code which uses this instruction.
| value | |
|---|---|
| Name | GETTER_CALL |
| Value | 99 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | |
| Stack Push |
GETVARGet a named variable
| value | |
|---|---|
| Name | GETVAR |
| Value | 20 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of variable |
GETVAR Bytecode Assembly Examplecode <- r"(
LDCONST 1
SETVAR x
POP
GETBUILTIN list
GETVAR x
PUSHARG
CALLBUILTIN
RETURN
)"
asm(code) |> eval()[[1]]
[1] 1
GETVAR bytecode1 + xLDCONST 1
GETVAR x
ADD
RETURN
GETVAR_MISSOKGet a named variable. Missing values allowed.
| value | |
|---|---|
| Name | GETVAR_MISSOK |
| Value | 92 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | |
| Stack Push |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of variable |
GETVAR_MISSOK bytecodea[i]GETVAR a
STARTSUBSET_N @label1
GETVAR_MISSOK i
VECSUBSET
@label1
RETURN
GOTOJump to the labelled location
| value | |
|---|---|
| Name | GOTO |
| Value | 2 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location to jump to |
GOTO Bytecode Assembly Examplecode <- r"(
LDCONST 5
LDCONST 4
GE
BRIFNOT @label1
LDCONST 66
GOTO @label2
@label1
LDCONST 99
RETURN
@label2
RETURN
)"
asm(code) |> eval()[1] 66
GOTO bytecodewhile(TRUE) print('hello')@label2
LDTRUE
BRIFNOT @label1
GETFUN print
PUSHCONSTARG "hello"
CALL
POP
GOTO @label2
@label1
LDNULL
INVISIBLE
RETURN
GTTest greater than
| value | |
|---|---|
| Name | GT |
| Value | 56 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
GT Bytecode Assembly Examplecode <- r"(
LDCONST 7
LDCONST 5
GT
RETURN
)"
asm(code) |> eval()[1] TRUE
GT bytecodex > 5GETVAR x
LDCONST 5
GT
RETURN
INCLNKProtect evaluated arguments on the stack.
The INCLNK and DECLNK instructions are used to protect evaluated arguents on the stack from modifications during evaluation of subsequent arguments.
Help needed: R code which uses this instruction.
| value | |
|---|---|
| Name | INCLNK |
| Value | 124 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
INCLNKSTKProtect evaluated arguments on the stack.
Protect stack during a non-top-level complex assignment. This instruction must be paired with DECLNKSTK.
Help needed: R code which uses this instruction.
| value | |
|---|---|
| Name | INCLNKSTK |
| Value | 127 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
INVISIBLEMark a value as invisible.
A bytecode version of the invisible() function.
| value | |
|---|---|
| Name | INVISIBLE |
| Value | 15 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
INVISIBLE Bytecode Assembly Examplecode <- r"(
LDCONST 1
INVISIBLE
RETURN
)"
asm(code) |> eval()ISCHARACTERTest is character
| value | |
|---|---|
| Name | ISCHARACTER |
| Value | 80 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
ISCHARACTER Bytecode Assembly Examplecode <- r"(
LDCONST "a"
ISCHARACTER
RETURN
)"
asm(code) |> eval()[1] TRUE
ISCHARACTER bytecodeis.character(x)BASEGUARD @label1
GETVAR x
ISCHARACTER
@label1
RETURN
ISCOMPLEXTest is complex
| value | |
|---|---|
| Name | ISCOMPLEX |
| Value | 79 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
ISCOMPLEX Bytecode Assembly Examplecode <- r"(
LDCONST 1i
ISCOMPLEX
RETURN
)"
asm(code) |> eval()[1] TRUE
ISCOMPLEX bytecodeis.complex(x)BASEGUARD @label1
GETVAR x
ISCOMPLEX
@label1
RETURN
ISDOUBLETest is double
| value | |
|---|---|
| Name | ISDOUBLE |
| Value | 78 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
ISDOUBLE Bytecode Assembly Examplecode <- r"(
LDCONST 1.23
ISDOUBLE
RETURN
)"
asm(code) |> eval()[1] TRUE
ISDOUBLE bytecodeis.double(x)BASEGUARD @label1
GETVAR x
ISDOUBLE
@label1
RETURN
ISINTEGERTest is integer
| value | |
|---|---|
| Name | ISINTEGER |
| Value | 77 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
ISINTEGER Bytecode Assembly Examplecode <- r"(
LDCONST 1L
ISINTEGER
RETURN
)"
asm(code) |> eval()[1] TRUE
ISINTEGER bytecodeis.integer(x)BASEGUARD @label1
GETVAR x
ISINTEGER
@label1
RETURN
ISLOGICALTest is logical
| value | |
|---|---|
| Name | ISLOGICAL |
| Value | 76 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
ISLOGICAL Bytecode Assembly Examplecode <- r"(
LDCONST TRUE
ISLOGICAL
RETURN
)"
asm(code) |> eval()[1] TRUE
ISLOGICAL bytecodeis.logical(x)BASEGUARD @label1
GETVAR x
ISLOGICAL
@label1
RETURN
ISNULLTest is NULL
| value | |
|---|---|
| Name | ISNULL |
| Value | 75 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
ISNULL Bytecode Assembly Examplecode <- r"(
LDNULL
ISNULL
RETURN
)"
asm(code) |> eval()[1] TRUE
ISNULL bytecodeis.null(x)BASEGUARD @label1
GETVAR x
ISNULL
@label1
RETURN
ISNUMERICTest is numeric
| value | |
|---|---|
| Name | ISNUMERIC |
| Value | 83 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
ISNUMERIC Bytecode Assembly Examplecode <- r"(
LDCONST 1
ISNUMERIC
RETURN
)"
asm(code) |> eval()[1] TRUE
ISOBJECTTest is object
| value | |
|---|---|
| Name | ISOBJECT |
| Value | 82 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
ISOBJECT Bytecode Assembly Examplecode <- r"(
LDCONST "a"
ISOBJECT
RETURN
)"
asm(code) |> eval()[1] FALSE
ISOBJECT bytecodeis.object(x)BASEGUARD @label1
GETVAR x
ISOBJECT
@label1
RETURN
ISSYMBOLTest is symbol
| value | |
|---|---|
| Name | ISSYMBOL |
| Value | 81 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
ISSYMBOL Bytecode Assembly Examplecode <- r"(
LDCONST 1.23
ISSYMBOL
RETURN
)"
asm(code) |> eval()[1] FALSE
ISSYMBOL bytecodeis.symbol(x)BASEGUARD @label1
GETVAR x
ISSYMBOL
@label1
RETURN
LDCONSTLoad a constant onto the stack
This instruction loads a value onto the stack. This can be a vector or scalar.
In the assembler in this package, and valid R expression may be given as the constant and its value will be evaluated at compile time. E.g.
LDCONST runif(3)
RETURN| value | |
|---|---|
| Name | LDCONST |
| Value | 16 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | const | Value or expression |
LDCONST Bytecode Assembly Examplecode <- r"(
LDCONST 1.23
RETURN
)"
asm(code) |> eval()[1] 1.23
LDCONST bytecode1 + xLDCONST 1
GETVAR x
ADD
RETURN
LDFALSELoad FALSE onto the stack
| value | |
|---|---|
| Name | LDFALSE |
| Value | 19 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 1 |
LDFALSE Bytecode Assembly Examplecode <- r"(
LDFALSE
RETURN
)"
asm(code) |> eval()[1] FALSE
LDFALSE bytecodex & FALSEGETVAR x
LDFALSE
AND
RETURN
LDNULLLoad NULL onto the stack
| value | |
|---|---|
| Name | LDNULL |
| Value | 17 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 1 |
LDNULL Bytecode Assembly Examplecode <- r"(
LDNULL
RETURN
)"
asm(code) |> eval()NULL
LDNULL bytecodeNULL > xLDNULL
GETVAR x
GT
RETURN
LDTRUELoad TRUE onto the stack
| value | |
|---|---|
| Name | LDTRUE |
| Value | 18 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 1 |
LDTRUE Bytecode Assembly Examplecode <- r"(
LDTRUE
RETURN
)"
asm(code) |> eval()[1] TRUE
LDTRUE bytecodex & TRUEGETVAR x
LDTRUE
AND
RETURN
LETest less than or equal to
| value | |
|---|---|
| Name | LE |
| Value | 54 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
LE Bytecode Assembly Examplecode <- r"(
LDCONST 7
LDCONST 5
LE
RETURN
)"
asm(code) |> eval()[1] FALSE
LE bytecodex <= 5GETVAR x
LDCONST 5
LE
RETURN
LOGLog (base e)
| value | |
|---|---|
| Name | LOG |
| Value | 116 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
LOG Bytecode Assembly Examplecode <- r"(
LDCONST 2.71
LOG
RETURN
)"
asm(code) |> eval()[1] 0.9969486
LOG bytecodelog(x)BASEGUARD @label1
GETVAR x
LOG
@label1
RETURN
LOGBASELog
| value | |
|---|---|
| Name | LOGBASE |
| Value | 117 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
LOGBASE Bytecode Assembly Examplecode <- r"(
LDCONST 10
LDCONST 2
LOGBASE
RETURN
)"
asm(code) |> eval()[1] 3.321928
LOGBASE bytecodelog(100, 10)BASEGUARD @label1
LDCONST 100
LDCONST 10
LOGBASE
@label1
RETURN
LTTest less than
| value | |
|---|---|
| Name | LT |
| Value | 53 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
LT Bytecode Assembly Examplecode <- r"(
LDCONST 7
LDCONST 5
LT
RETURN
)"
asm(code) |> eval()[1] FALSE
LT bytecodex < 5GETVAR x
LDCONST 5
LT
RETURN
MAKECLOSUREMake a closure
For the purposes of compiling with {asmr} this instruction must be terminated with an ENDMAKECLOSURE instruction.
ENDMAKECLOSURE is not a real instruction, and only exists as a way of instructing the compiler how to behave in the absence of higher-level R syntax to consult. See Section 6.7 for more details.
| value | |
|---|---|
| Name | MAKECLOSURE |
| Value | 41 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | closure | Sequence of arguments to closure separated by semi-colons. |
MAKECLOSURE bytecodefunction(x) {x + 1}MAKECLOSURE x
GETVAR x
LDCONST 1
ADD
RETURN
ENDMAKECLOSURE
RETURN
MAKEPROMMake a promise
For the purposes of compiling with {asmr} this instruction must be terminated with an ENDMAKEPROM instruction.
ENDMAKEPROM is not a real instruction, and only exists as a way of instructing the compiler how to behave in the absence of higher-level R syntax to consult. See Section 6.6 for more details.
| value | |
|---|---|
| Name | MAKEPROM |
| Value | 29 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | promise | Special handling for promises in {rbytecode} means that the argument is automatically inferred from the instructions within MAKEPROM/ENDMAKEPROM |
MAKEPROM Bytecode Assembly Examplecode <- r"(
GETFUN head
MAKEPROM
GETVAR mtcars
RETURN
ENDMAKEPROM
CALL
RETURN
)"
asm(code) |> eval() mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
MAKEPROM bytecoderunif(n = 3, min = x)GETFUN runif
PUSHCONSTARG 3
SETTAG n
MAKEPROM
GETVAR x
RETURN
ENDMAKEPROM
SETTAG min
CALL
RETURN
MATH1Perform a mathematical operation.
Perform one of the built-in mathematical operations.
# List of all operations
compiler:::math1funs [1] "floor" "ceiling" "sign" "expm1" "log1p" "cos"
[7] "sin" "tan" "acos" "asin" "atan" "cosh"
[13] "sinh" "tanh" "acosh" "asinh" "atanh" "lgamma"
[19] "gamma" "digamma" "trigamma" "cospi" "sinpi" "tanpi"
| value | |
|---|---|
| Name | MATH1 |
| Value | 118 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | math1name | Name of valued math operation. See Section 11.3 |
MATH1 Bytecode Assembly Examplecode <- r"(
LDCONST 1:5
MATH1 sin
RETURN
)"
asm(code) |> eval()[1] 0.8414710 0.9092974 0.1411200 -0.7568025 -0.9589243
MATH1 bytecodefloor(x)BASEGUARD @label1
GETVAR x
MATH1 floor
@label1
RETURN
MATSUBASSIGNAssign into matrix with [
| value | |
|---|---|
| Name | MATSUBASSIGN |
| Value | 87 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 0 |
MATSUBASSIGN bytecodem[1,2] <- 1LDCONST 1
STARTASSIGN m
STARTSUBASSIGN_N @label1
LDCONST 1
LDCONST 2
MATSUBASSIGN
@label1
ENDASSIGN m
INVISIBLE
RETURN
MATSUBASSIGN2Assign into matrix with [[
| value | |
|---|---|
| Name | MATSUBASSIGN2 |
| Value | 109 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 0 |
MATSUBASSIGN2 bytecodem[[1,2]] <- 1LDCONST 1
STARTASSIGN m
STARTSUBASSIGN2_N @label1
LDCONST 1
LDCONST 2
MATSUBASSIGN2
@label1
ENDASSIGN m
INVISIBLE
RETURN
MATSUBSETSubset matrix with [
| value | |
|---|---|
| Name | MATSUBSET |
| Value | 85 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 0 |
MATSUBSET bytecodem[1,2]GETVAR m
STARTSUBSET_N @label1
LDCONST 1
LDCONST 2
MATSUBSET
@label1
RETURN
MATSUBSET2Subset matrix with [[
| value | |
|---|---|
| Name | MATSUBSET2 |
| Value | 107 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 0 |
MATSUBSET2 bytecodem[[1,2]]GETVAR m
STARTSUBSET2_N @label1
LDCONST 1
LDCONST 2
MATSUBSET2
@label1
RETURN
MULMultiply
| value | |
|---|---|
| Name | MUL |
| Value | 46 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
MUL Bytecode Assembly Examplecode <- r"(
LDCONST 1
LDCONST 2
MUL
RETURN
)"
asm(code) |> eval()[1] 2
MUL bytecodex * yGETVAR x
GETVAR y
MUL
RETURN
NETest not equal to
| value | |
|---|---|
| Name | NE |
| Value | 52 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
NE Bytecode Assembly Examplecode <- r"(
LDCONST 2
LDCONST 3
NE
RETURN
)"
asm(code) |> eval()[1] TRUE
NE bytecodex != 3GETVAR x
LDCONST 3
NE
RETURN
NOTLogical NOT operation
| value | |
|---|---|
| Name | NOT |
| Value | 59 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
NOT Bytecode Assembly Examplecode <- r"(
LDTRUE
NOT
RETURN
)"
asm(code) |> eval()[1] FALSE
NOT bytecode!xGETVAR x
NOT
RETURN
ORVector logical OR
| value | |
|---|---|
| Name | OR |
| Value | 58 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
OR Bytecode Assembly Examplecode <- r"(
LDCONST c(TRUE, TRUE)
LDCONST c(TRUE, FALSE)
OR
RETURN
)"
asm(code) |> eval()[1] TRUE TRUE
OR bytecodex | yGETVAR x
GETVAR y
OR
RETURN
OR1STScalar logical OR (Part 1)
Scalar logical OR in R supports “short-circuiting” the operation i.e. if the first argument is TRUE, then the second argument is never evaluated.
The OR1ST instruction pops a value from the stack, and if TRUE jumps to the position specified in its label argument i.e. the position after the end of the trailing OR2ND statement.
Following the OR1ST instruction is the code for the right-hand side of the OR operation which is concluded with an OR2ND statement.
| value | |
|---|---|
| Name | OR1ST |
| Value | 90 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location to jump to if first logical value is TRUE |
OR1ST Bytecode Assembly Examplecode <- r"(
LDFALSE
OR1ST @label1
LDFALSE
OR2ND
@label1
RETURN
)"
asm(code) |> eval()[1] FALSE
OR1ST bytecodex || yGETVAR x
OR1ST @label1
GETVAR y
OR2ND
@label1
RETURN
OR2NDScalar logical OR (Part 2)
See the OR1ST instruction Section 9.83
| value | |
|---|---|
| Name | OR2ND |
| Value | 91 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
OR2ND bytecodex || yGETVAR x
OR1ST @label1
GETVAR y
OR2ND
@label1
RETURN
POPPop a value off the stack (and discard)
| value | |
|---|---|
| Name | POP |
| Value | 4 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 0 |
POP Bytecode Assembly Examplecode <- r"(
LDCONST 1
LDCONST 2
POP
RETURN
)"
asm(code) |> eval()[1] 1
PRINTVALUEPurpose currently unknown.
Help needed: do not currently know what this bytecode is for or how to generate it from R code compilation.
| value | |
|---|---|
| Name | PRINTVALUE |
| Value | 6 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | ? |
| Stack Push | ? |
PUSHARGPush an value from the stack into the list of arguments for a call
| value | |
|---|---|
| Name | PUSHARG |
| Value | 33 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 0 |
PUSHARG Bytecode Assembly Examplecode <- r"(
LDCONST 1
SETVAR x
POP
GETBUILTIN list
GETVAR x
PUSHARG
CALLBUILTIN
RETURN
)"
asm(code) |> eval()[[1]]
[1] 1
PUSHARG bytecodelist(1, x)BASEGUARD @label1
GETBUILTIN list
PUSHCONSTARG 1
GETVAR x
PUSHARG
CALLBUILTIN
@label1
RETURN
PUSHCONSTARGPush a constant value into the list of arguments for a call.
| value | |
|---|---|
| Name | PUSHCONSTARG |
| Value | 34 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | const | Value or expression to add to list of arguments for a function call |
PUSHCONSTARG Bytecode Assembly Examplecode <- r"(
GETFUN runif
PUSHCONSTARG 3
CALL
RETURN
)"
asm(code) |> eval()[1] 0.002539779 0.725551877 0.514050746
PUSHCONSTARG bytecodelist(1, x)BASEGUARD @label1
GETBUILTIN list
PUSHCONSTARG 1
GETVAR x
PUSHARG
CALLBUILTIN
@label1
RETURN
PUSHFALSEARGPush FALSE into the list of arguments for a call
| value | |
|---|---|
| Name | PUSHFALSEARG |
| Value | 37 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 0 |
PUSHFALSEARG Bytecode Assembly Examplecode <- r"(
GETFUN identity
PUSHFALSEARG
CALL
RETURN
)"
asm(code) |> eval()[1] FALSE
PUSHFALSEARG bytecodef(1, NULL, TRUE, FALSE)GETFUN f
PUSHCONSTARG 1
PUSHNULLARG
PUSHTRUEARG
PUSHFALSEARG
CALL
RETURN
PUSHNULLARGPush NULL into the list of arguments for a call
| value | |
|---|---|
| Name | PUSHNULLARG |
| Value | 35 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 0 |
PUSHNULLARG Bytecode Assembly Examplecode <- r"(
GETFUN identity
PUSHNULLARG
CALL
RETURN
)"
asm(code) |> eval()NULL
PUSHNULLARG bytecodef(1, NULL, TRUE, FALSE)GETFUN f
PUSHCONSTARG 1
PUSHNULLARG
PUSHTRUEARG
PUSHFALSEARG
CALL
RETURN
PUSHTRUEARGPush TRUE into the list of arguments for a call.
| value | |
|---|---|
| Name | PUSHTRUEARG |
| Value | 36 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 0 |
PUSHTRUEARG Bytecode Assembly Examplecode <- r"(
GETFUN identity
PUSHTRUEARG
CALL
RETURN
)"
asm(code) |> eval()[1] TRUE
PUSHTRUEARG bytecodef(1, NULL, TRUE, FALSE)GETFUN f
PUSHCONSTARG 1
PUSHNULLARG
PUSHTRUEARG
PUSHFALSEARG
CALL
RETURN
RETURNReturn control to the caller
| value | |
|---|---|
| Name | RETURN |
| Value | 1 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 0 |
RETURN Bytecode Assembly Examplecode <- r"(
LDCONST 1
LDCONST 2
ADD
RETURN
)"
asm(code) |> eval()[1] 3
RETURN bytecodea + 1GETVAR a
LDCONST 1
ADD
RETURN
RETURNJMPReturn control to the caller via a “longjmp”
It’s unclear on exactly when this instruction is generated.
| value | |
|---|---|
| Name | RETURNJMP |
| Value | 103 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 0 |
SEQALONGCreate an integer sequence the same length as that next value on the stack.
| value | |
|---|---|
| Name | SEQALONG |
| Value | 121 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
SEQALONG Bytecode Assembly Examplecode <- r"(
LDCONST c(10, 20, 30)
SEQALONG
RETURN
)"
asm(code) |> eval()[1] 1 2 3
SEQALONG bytecodeseq_along(c(x, y, z))BASEGUARD @label1
BASEGUARD @label2
GETBUILTIN c
GETVAR x
PUSHARG
GETVAR y
PUSHARG
GETVAR z
PUSHARG
CALLBUILTIN
@label2
SEQALONG
@label1
RETURN
SEQLENCreate an integer sequence of the given length
| value | |
|---|---|
| Name | SEQLEN |
| Value | 122 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
SEQLEN Bytecode Assembly Examplecode <- r"(
LDCONST 5
SEQLEN
RETURN
)"
asm(code) |> eval()[1] 1 2 3 4 5
SEQLEN bytecodeseq_len(x)BASEGUARD @label1
GETVAR x
SEQLEN
@label1
RETURN
SETLOOPVALPurpose currently unknown.
Help needed: do not currently know what this bytecode is for or how to generate it from R code compilation.
| value | |
|---|---|
| Name | SETLOOPVAL |
| Value | 14 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | ? |
| Stack Push | ? |
SETTAGSet the name of an argument to a function
| value | |
|---|---|
| Name | SETTAG |
| Value | 31 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name to set for most recent argument for a function call |
SETTAG Bytecode Assembly Examplecode <- r"(
GETBUILTIN max
PUSHCONSTARG NA
PUSHTRUEARG
SETTAG na.rm
CALLBUILTIN
RETURN
)"
asm(code) |> eval()Warning in stop(op = "CALLBUILTIN", row = 5L, line = 6L, depth = 0L): no
non-missing arguments to max; returning -Inf
[1] -Inf
SETTAG bytecodec(a = 1)BASEGUARD @label1
GETBUILTIN c
PUSHCONSTARG 1
SETTAG a
CALLBUILTIN
@label1
RETURN
SETTER_CALLAssignment via a <- method
| value | |
|---|---|
| Name | SETTER_CALL |
| Value | 98 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | const | Unknown |
SETTER_CALL bytecodenames(x) <- 'hello'LDCONST "hello"
STARTASSIGN x
GETFUN names<-
PUSHNULLARG
SETTER_CALL "hello"
ENDASSIGN x
INVISIBLE
RETURN
SETVARSet the value of a variable
| value | |
|---|---|
| Name | SETVAR |
| Value | 22 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of variable |
SETVAR Bytecode Assembly Examplecode <- r"(
LDCONST 1
SETVAR y
GETVAR y
RETURN
)"
asm(code) |> eval()[1] 1
SETVAR bytecodex <- yGETVAR y
SETVAR x
INVISIBLE
RETURN
SETVAR2Use superassignment to set the value of a variable
| value | |
|---|---|
| Name | SETVAR2 |
| Value | 95 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of variable |
SETVAR2 bytecodex <<- yGETVAR y
SETVAR2 x
INVISIBLE
RETURN
SQRTSquare root
| value | |
|---|---|
| Name | SQRT |
| Value | 49 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
SQRT Bytecode Assembly Examplecode <- r"(
LDCONST 2
SQRT
RETURN
)"
asm(code) |> eval()[1] 1.414214
SQRT bytecodesqrt(x)BASEGUARD @label1
GETVAR x
SQRT
@label1
RETURN
STARTASSIGNStart an assignment operation.
This instruction be paired with closing ENDASSIGN instruction.
| value | |
|---|---|
| Name | STARTASSIGN |
| Value | 61 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of variable into which value is being assigned |
STARTASSIGN bytecodea[1] <- 2LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
STARTASSIGN2Start an assignment operation.
This instruction be paired with closing ENDASSIGN2 instruction.
Help needed: R code example which uses this instruction
| value | |
|---|---|
| Name | STARTASSIGN2 |
| Value | 96 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of variable into which value is being assigned |
STARTCDeprecated instruction
This is a vestigal instruction that used to be paired with an ending DFLTC to peform the equivalent of c(...).
Now that c() is a builtin function, use GETBUILTIN and CALLBUILTIN instead.
See also R source main/eval.c where comments indicate this OP is no longer used.
| value | |
|---|---|
| Name | STARTC |
| Value | 67 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | NA |
| Stack Push | NA |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Deprecated |
STARTFORInitiate a for loop
See also STEPFOR Section 9.115 and ENDFOR Section 9.36.
| value | |
|---|---|
| Name | STARTFOR |
| Value | 11 |
| Number of Args | 2 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | name | Name of loop variable |
| 2 | label | Location of matching STEPFOR instruction |
STARTFOR bytecodefor(i in 1:3) {print(i)}LDCONST 1:3
STARTFOR i @label1
@label2
GETFUN print
MAKEPROM
GETVAR i
RETURN
ENDMAKEPROM
CALL
POP
@label1
STEPFOR @label2
ENDFOR
INVISIBLE
RETURN
STARTLOOPCNTXTStart loop context
When complex things happen inside a repeat, while() or for() loop, it can no longer use simple BRIFNOT and GOTO. And eval() inside a loop is one such occasion.
See also ENDLOOPCNTXT (Section 9.37)
| value | |
|---|---|
| Name | STARTLOOPCNTXT |
| Value | 7 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
STARTLOOPCNTXT bytecoderepeat {
eval("hello")
break
}STARTLOOPCNTXT @label1
@label2
GETFUN eval
PUSHCONSTARG "hello"
CALL
POP
GOTO @label1
POP
GOTO @label2
@label1
ENDLOOPCNTXT
LDNULL
INVISIBLE
RETURN
STARTSUBASSIGNAn assignment operation into vector via an empty index
Help needed: Details of when this is used
| value | |
|---|---|
| Name | STARTSUBASSIGN |
| Value | 65 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
STARTSUBASSIGN bytecodea[] <- 1LDCONST 1
STARTASSIGN a
STARTSUBASSIGN @label1
DOMISSING
DFLTSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
STARTSUBASSIGN_NStart an assignment operation into a vector.
This instruction must be paired with a closing VECSUBASSIGN instruction.
| value | |
|---|---|
| Name | STARTSUBASSIGN_N |
| Value | 105 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
STARTSUBASSIGN_N bytecodea[1] <- 2LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
STARTSUBASSIGN2Start an assignment operation
| value | |
|---|---|
| Name | STARTSUBASSIGN2 |
| Value | 71 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
STARTSUBASSIGN2 bytecodem[[,,]] <- 1LDCONST 1
STARTASSIGN m
STARTSUBASSIGN2 @label1
DOMISSING
DOMISSING
DOMISSING
DFLTSUBASSIGN2
@label1
ENDASSIGN m
INVISIBLE
RETURN
STARTSUBASSIGN2_NStart an assignment operation into a vector.
This instruction must be paired with a closing SUBASSIGN2_N instruction.
| value | |
|---|---|
| Name | STARTSUBASSIGN2_N |
| Value | 111 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
STARTSUBASSIGN2_N bytecodem[[1,2,3]] <- 1LDCONST 1
@label2
STARTASSIGN m
STARTSUBASSIGN2_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBASSIGN2_N @label2
@label1
ENDASSIGN m
INVISIBLE
RETURN
STARTSUBSETStart vector subset with []
Help needed: R code example which uses this instruction
| value | |
|---|---|
| Name | STARTSUBSET |
| Value | 63 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
STARTSUBSET bytecodea[]GETVAR a
STARTSUBSET @label1
DOMISSING
DFLTSUBSET
@label1
RETURN
STARTSUBSET_NStart vector subset
x[y] - label points to after matching VECSUBSET
| value | |
|---|---|
| Name | STARTSUBSET_N |
| Value | 104 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
STARTSUBSET_N bytecodea[1]GETVAR a
STARTSUBSET_N @label1
LDCONST 1
VECSUBSET
@label1
RETURN
STARTSUBSET2Array subset
This appears to be a vector subset instruction.
Help needed: R code example which uses this instruction
| value | |
|---|---|
| Name | STARTSUBSET2 |
| Value | 69 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
STARTSUBSET2 bytecodem[[,,]]GETVAR m
STARTSUBSET2 @label1
DOMISSING
DOMISSING
DOMISSING
DFLTSUBSET2
@label1
RETURN
STARTSUBSET2_NStart vector subset with [[]]
x[[y]] - label points to after matching VECSUBSET
| value | |
|---|---|
| Name | STARTSUBSET2_N |
| Value | 110 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
STARTSUBSET2_N bytecodea[[1]]GETVAR a
STARTSUBSET2_N @label1
LDCONST 1
VECSUBSET2
@label1
RETURN
STEPFORAdvance to the next element in a for loop
See also ENDFOR Section 9.36 and STARTFOR Section 9.105.
| value | |
|---|---|
| Name | STEPFOR |
| Value | 12 |
| Number of Args | 1 |
| Has expr index | FALSE |
| Stack Pop | 0 |
| Stack Push | 0 |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching STARTFOR |
STEPFOR bytecodefor(i in 1:3) {print(i)}LDCONST 1:3
STARTFOR i @label1
@label2
GETFUN print
MAKEPROM
GETVAR i
RETURN
ENDMAKEPROM
CALL
POP
@label1
STEPFOR @label2
ENDFOR
INVISIBLE
RETURN
SUBSubtraction
| value | |
|---|---|
| Name | SUB |
| Value | 45 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 2 |
| Stack Push | 1 |
SUB Bytecode Assembly Examplecode <- r"(
LDCONST 1
LDCONST 2
SUB
RETURN
)"
asm(code) |> eval()[1] -1
SUB bytecodex - yGETVAR x
GETVAR y
SUB
RETURN
SUBASSIGN_NAssignment into a subset of an object
| value | |
|---|---|
| Name | SUBASSIGN_N |
| Value | 114 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | ? |
| Stack Push | ? |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
SUBASSIGN_N bytecodem[1,2,3] <- 1LDCONST 1
@label2
STARTASSIGN m
STARTSUBASSIGN_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBASSIGN_N @label2
@label1
ENDASSIGN m
INVISIBLE
RETURN
SUBASSIGN2_NAssignment into a subset of an object
| value | |
|---|---|
| Name | SUBASSIGN2_N |
| Value | 115 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | ? |
| Stack Push | ? |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
SUBASSIGN2_N bytecodem[[1, 2, 3]] <- 1LDCONST 1
@label2
STARTASSIGN m
STARTSUBASSIGN2_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBASSIGN2_N @label2
@label1
ENDASSIGN m
INVISIBLE
RETURN
SUBSET_NSubset of an object
| value | |
|---|---|
| Name | SUBSET_N |
| Value | 112 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | ? |
| Stack Push | ? |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
SUBSET_N bytecodem[1,2,3]GETVAR m
@label2
STARTSUBSET_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBSET_N @label2
@label1
RETURN
SUBSET2_NSubset of an object
| value | |
|---|---|
| Name | SUBSET2_N |
| Value | 113 |
| Number of Args | 1 |
| Has expr index | TRUE |
| Stack Pop | ? |
| Stack Push | ? |
| Argument | Type | Description |
|---|---|---|
| 1 | label | Location of matching END* instruction |
SUBSET2_N bytecodem[[1,2,3]]GETVAR m
@label2
STARTSUBSET2_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBSET2_N @label2
@label1
RETURN
SWAPSwap the top two items on the stack
| value | |
|---|---|
| Name | SWAP |
| Value | 100 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 2 |
| Stack Push | 2 |
SWAP Bytecode Assembly Examplecode <- r"(
LDCONST "apple"
LDCONST "banana"
SWAP
RETURN
)"
asm(code) |> eval()[1] "apple"
SWITCHEquivalent to switch() statement
The switch instruction is quite convoluted due to the way the switch() statement in R handles both numeric and character arguments.
For the SWITCH instruction, four arguments are needed:
NULLNULLswitch()There is not yet support for compiling this op in the {asmr} package.
| value | |
|---|---|
| Name | SWITCH |
| Value | 102 |
| Number of Args | 3 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
| Argument | Type | Description |
|---|---|---|
| 1 | char_vec | A character vector of labels for the choices. This may be NULL |
| 2 | labels | A vector of locations matching the character vector. This may be NULL |
| 3 | labels | A vector of labels matching the locations to jump to if numeric argument is given as switching value |
SWITCH bytecodeswitch(x, 10, 20)GETVAR x
SWITCH NULL; c("@label1", "@label2", "@label3")
@label3
LDNULL
INVISIBLE
RETURN
@label1
LDCONST 10
RETURN
@label2
LDCONST 20
RETURN
UMINUSUnary minus
| value | |
|---|---|
| Name | UMINUS |
| Value | 42 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
UMINUS Bytecode Assembly Examplecode <- r"(
LDCONST 1
UMINUS
RETURN
)"
asm(code) |> eval()[1] -1
UMINUS bytecode-x + 1GETVAR x
UMINUS
LDCONST 1
ADD
RETURN
UPLUSUnary plus
| value | |
|---|---|
| Name | UPLUS |
| Value | 43 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 1 |
UPLUS Bytecode Assembly Examplecode <- r"(
LDCONST 1
UPLUS
RETURN
)"
asm(code) |> eval()[1] 1
UPLUS bytecode+x + 1GETVAR x
UPLUS
LDCONST 1
ADD
RETURN
VECSUBASSIGNEnd an assignment operation into the subset of a vector
Assignment must have been started with STARTSUBASSIGN_N instruction.
| value | |
|---|---|
| Name | VECSUBASSIGN |
| Value | 86 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 0 |
VECSUBASSIGN bytecodea[1] <- 2LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
VECSUBASSIGN2End an assignment operation into the subset of a vector
Assignment must have been started with STARTSUBASSIGN2_N instruction.
| value | |
|---|---|
| Name | VECSUBASSIGN2 |
| Value | 108 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 0 |
VECSUBASSIGN2 bytecodea[[1]] <- 2LDCONST 2
STARTASSIGN a
STARTSUBASSIGN2_N @label1
LDCONST 1
VECSUBASSIGN2
@label1
ENDASSIGN a
INVISIBLE
RETURN
VECSUBSETVector subset with []
This instruction marks the end of a set of instructions which start with STARTSUBSET_N
| value | |
|---|---|
| Name | VECSUBSET |
| Value | 84 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 0 |
VECSUBSET bytecodea[1]GETVAR a
STARTSUBSET_N @label1
LDCONST 1
VECSUBSET
@label1
RETURN
VECSUBSET2Vector subset with [[]]
This instruction marks the end of a set of instructions which start with STARTSUBSET2_N
| value | |
|---|---|
| Name | VECSUBSET2 |
| Value | 106 |
| Number of Args | 0 |
| Has expr index | TRUE |
| Stack Pop | 1 |
| Stack Push | 0 |
VECSUBSET2 bytecodea[[1]]GETVAR a
STARTSUBSET2_N @label1
LDCONST 1
VECSUBSET2
@label1
RETURN
VISIBLEMake an invisible object visible again.
There is no direct analogue of this op in R.
| value | |
|---|---|
| Name | VISIBLE |
| Value | 94 |
| Number of Args | 0 |
| Has expr index | FALSE |
| Stack Pop | 1 |
| Stack Push | 1 |
VISIBLE Bytecode Assembly Examplecode <- r"(
LDCONST 1
INVISIBLE
VISIBLE
RETURN
)"
asm(code) |> eval()[1] 1