<- r"(
code # 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.
ADD
Add values
value | |
---|---|
Name | ADD |
Value | 44 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 1 |
ADD
Bytecode Assembly Example<- r"(
code # 1 + 2
LDCONST 1
LDCONST 2
ADD
RETURN
)"
asm(code) |> eval()
[1] 3
ADD
bytecode+ y x
GETVAR x
GETVAR y
ADD
RETURN
AND
Vector logical AND
value | |
---|---|
Name | AND |
Value | 57 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 1 |
AND
Bytecode Assembly Example<- r"(
code LDCONST c(TRUE, TRUE, FALSE, FALSE)
LDCONST c(FALSE, TRUE, FALSE, TRUE)
AND
RETURN
)"
asm(code) |> eval()
[1] FALSE TRUE FALSE FALSE
AND
bytecode& y x
GETVAR x
GETVAR y
AND
RETURN
AND1ST
Scalar 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 Example<- r"(
code # TRUE && FALSE
LDTRUE
AND1ST @label1
LDFALSE
AND2ND
@label1
RETURN
)"
asm(code) |> eval()
[1] FALSE
AND1ST
bytecode&& y x
GETVAR x
AND1ST @label1
GETVAR y
AND2ND
@label1
RETURN
AND2ND
Scalar 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 Example<- r"(
code LDTRUE
AND1ST @label1
LDFALSE
AND2ND
@label1
RETURN
)"
asm(code) |> eval()
[1] FALSE
AND2ND
bytecode&& y x
GETVAR x
AND1ST @label1
GETVAR y
AND2ND
@label1
RETURN
BASEGUARD
Guard 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 Example<- r"(
code 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
BCMISMATCH
Raise 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 |
BRIFNOT
Branch 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 Example<- r"(
code 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
CALL
Call 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 Example<- r"(
code GETFUN print
PUSHCONSTARG "hello"
CALL
RETURN
)"
asm(code) |> eval()
[1] "hello"
CALL
bytecoderunif(3)
GETFUN runif
PUSHCONSTARG 3
CALL
RETURN
CALLBUILTIN
Call 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 Example<- r"(
code 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
CALLSPECIAL
Call 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 Example<- r"(
code CALLSPECIAL rep(1, 3)
RETURN
)"
asm(code) |> eval()
[1] 1 1 1
CALLSPECIAL
bytecoderep(1, 3)
BASEGUARD @label1
CALLSPECIAL rep(1, 3)
@label1
RETURN
CHECKFUN
Check 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
COLON
Colon 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 Example<- r"(
code LDCONST 1
LDCONST 5
COLON
RETURN
)"
asm(code) |> eval()
[1] 1 2 3 4 5
COLON
bytecode:y x
GETVAR x
GETVAR y
COLON
RETURN
DDVAL
Get 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_MISSOK
Get 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 |
DECLNK
Decrease 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_N
Decrease 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. |
DECLNKSTK
Decrease 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 |
DFLTC
Deprecated 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 |
DFLTSUBASSIGN
Default subassignment with []
value | |
---|---|
Name | DFLTSUBASSIGN |
Value | 66 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | |
Stack Push |
DFLTSUBASSIGN
bytecode<- 1 a[]
LDCONST 1
STARTASSIGN a
STARTSUBASSIGN @label1
DOMISSING
DFLTSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
DFLTSUBASSIGN2
Default subassignment with [[]]
value | |
---|---|
Name | DFLTSUBASSIGN2 |
Value | 72 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | |
Stack Push |
DFLTSUBASSIGN2
bytecode<- 1 a[[]]
LDCONST 1
STARTASSIGN a
STARTSUBASSIGN2 @label1
DOMISSING
DFLTSUBASSIGN2
@label1
ENDASSIGN a
INVISIBLE
RETURN
DFLTSUBSET
Default subset with []
value | |
---|---|
Name | DFLTSUBSET |
Value | 64 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | |
Stack Push |
DFLTSUBSET
bytecode a[]
GETVAR a
STARTSUBSET @label1
DOMISSING
DFLTSUBSET
@label1
RETURN
DFLTSUBSET2
Default subset with [[]]
value | |
---|---|
Name | DFLTSUBSET2 |
Value | 70 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | |
Stack Push |
DFLTSUBSET2
bytecode a[[]]
GETVAR a
STARTSUBSET2 @label1
DOMISSING
DFLTSUBSET2
@label1
RETURN
DIV
Division
value | |
---|---|
Name | DIV |
Value | 47 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 1 |
DIV
Bytecode Assembly Example<- r"(
code LDCONST 1
LDCONST 2
DIV
RETURN
)"
asm(code) |> eval()
[1] 0.5
DIV
bytecode/ y x
GETVAR x
GETVAR y
DIV
RETURN
DODOTS
Process ...
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
bytecode$y x
GETVAR 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
bytecode$b <- 3 a
LDCONST 3
STARTASSIGN a
DOLLARGETS b
ENDASSIGN a
INVISIBLE
RETURN
DOLOOPBREAK
Purpose 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 |
DOLOOPNEXT
Purpose 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 |
DOMISSING
Handle 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
DOTCALL
Call 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
DOTSERR
Trigger 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 Example<- r"(
code DOTSERR
RETURN
)"
asm(code) |> eval()
Error in stop("{rbytecode}"): '...' used in an incorrect context
DUP
Duplicate 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 Example<- r"(
code LDCONST 1
DUP
ADD
RETURN
)"
asm(code) |> eval()
[1] 2
DUP2ND
Duplicate 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 Example<- r"(
code LDCONST 10
LDCONST 20
DUP2ND
RETURN
)"
asm(code) |> eval()
[1] 10
ENDASSIGN
Mark 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
bytecode1] <- 2 a[
LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
ENDASSIGN2
Mark 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 |
ENDFOR
Signify 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
ENDLOOPCNTXT
End loop context
See STARTLOOPCNTXT
(Section 9.106)
value | |
---|---|
Name | ENDLOOPCNTXT |
Value | 8 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | |
Stack Push |
EQ
Test equality
value | |
---|---|
Name | EQ |
Value | 51 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 1 |
EQ
Bytecode Assembly Example<- r"(
code LDCONST 2
LDCONST 2
EQ
RETURN
)"
asm(code) |> eval()
[1] TRUE
EQ
bytecode== 4 x
GETVAR x
LDCONST 4
EQ
RETURN
EXP
Exponential
value | |
---|---|
Name | EXP |
Value | 50 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 1 |
Stack Push | 1 |
EXP
Bytecode Assembly Example<- r"(
code LDCONST 2
EXP
RETURN
)"
asm(code) |> eval()
[1] 7.389056
EXP
bytecodeexp(x)
BASEGUARD @label1
GETVAR x
EXP
@label1
RETURN
EXPT
Exponent.
value | |
---|---|
Name | EXPT |
Value | 48 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 1 |
EXPT
Bytecode Assembly Example<- r"(
code LDCONST 2
LDCONST 3
EXPT
RETURN
)"
asm(code) |> eval()
[1] 8
EXPT
bytecode^2 x
GETVAR x
LDCONST 2
EXPT
RETURN
GE
Test 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 Example<- r"(
code LDCONST 7
LDCONST 5
GE
RETURN
)"
asm(code) |> eval()
[1] TRUE
GE
bytecode>= 5 x
GETVAR x
LDCONST 5
GE
RETURN
GETBUILTIN
Get 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 Example<- r"(
code 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
GETFUN
Get 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 Example<- r"(
code 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
GETGLOBFUN
Get 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 |
GETINTLBUILTIN
Get 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
GETSYMFUN
Get 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_CALL
Used 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 |
GETVAR
Get 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 Example<- r"(
code LDCONST 1
SETVAR x
POP
GETBUILTIN list
GETVAR x
PUSHARG
CALLBUILTIN
RETURN
)"
asm(code) |> eval()
[[1]]
[1] 1
GETVAR
bytecode1 + x
LDCONST 1
GETVAR x
ADD
RETURN
GETVAR_MISSOK
Get 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
bytecode a[i]
GETVAR a
STARTSUBSET_N @label1
GETVAR_MISSOK i
VECSUBSET
@label1
RETURN
GOTO
Jump 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 Example<- r"(
code 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
GT
Test greater than
value | |
---|---|
Name | GT |
Value | 56 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 1 |
GT
Bytecode Assembly Example<- r"(
code LDCONST 7
LDCONST 5
GT
RETURN
)"
asm(code) |> eval()
[1] TRUE
GT
bytecode> 5 x
GETVAR x
LDCONST 5
GT
RETURN
INCLNK
Protect 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 |
INCLNKSTK
Protect 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 |
INVISIBLE
Mark 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 Example<- r"(
code LDCONST 1
INVISIBLE
RETURN
)"
asm(code) |> eval()
ISCHARACTER
Test is character
value | |
---|---|
Name | ISCHARACTER |
Value | 80 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | 1 |
Stack Push | 1 |
ISCHARACTER
Bytecode Assembly Example<- r"(
code LDCONST "a"
ISCHARACTER
RETURN
)"
asm(code) |> eval()
[1] TRUE
ISCHARACTER
bytecodeis.character(x)
BASEGUARD @label1
GETVAR x
ISCHARACTER
@label1
RETURN
ISCOMPLEX
Test is complex
value | |
---|---|
Name | ISCOMPLEX |
Value | 79 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | 1 |
Stack Push | 1 |
ISCOMPLEX
Bytecode Assembly Example<- r"(
code LDCONST 1i
ISCOMPLEX
RETURN
)"
asm(code) |> eval()
[1] TRUE
ISCOMPLEX
bytecodeis.complex(x)
BASEGUARD @label1
GETVAR x
ISCOMPLEX
@label1
RETURN
ISDOUBLE
Test is double
value | |
---|---|
Name | ISDOUBLE |
Value | 78 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | 1 |
Stack Push | 1 |
ISDOUBLE
Bytecode Assembly Example<- r"(
code LDCONST 1.23
ISDOUBLE
RETURN
)"
asm(code) |> eval()
[1] TRUE
ISDOUBLE
bytecodeis.double(x)
BASEGUARD @label1
GETVAR x
ISDOUBLE
@label1
RETURN
ISINTEGER
Test is integer
value | |
---|---|
Name | ISINTEGER |
Value | 77 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | 1 |
Stack Push | 1 |
ISINTEGER
Bytecode Assembly Example<- r"(
code LDCONST 1L
ISINTEGER
RETURN
)"
asm(code) |> eval()
[1] TRUE
ISINTEGER
bytecodeis.integer(x)
BASEGUARD @label1
GETVAR x
ISINTEGER
@label1
RETURN
ISLOGICAL
Test is logical
value | |
---|---|
Name | ISLOGICAL |
Value | 76 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | 1 |
Stack Push | 1 |
ISLOGICAL
Bytecode Assembly Example<- r"(
code LDCONST TRUE
ISLOGICAL
RETURN
)"
asm(code) |> eval()
[1] TRUE
ISLOGICAL
bytecodeis.logical(x)
BASEGUARD @label1
GETVAR x
ISLOGICAL
@label1
RETURN
ISNULL
Test is NULL
value | |
---|---|
Name | ISNULL |
Value | 75 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | 1 |
Stack Push | 1 |
ISNULL
Bytecode Assembly Example<- r"(
code LDNULL
ISNULL
RETURN
)"
asm(code) |> eval()
[1] TRUE
ISNULL
bytecodeis.null(x)
BASEGUARD @label1
GETVAR x
ISNULL
@label1
RETURN
ISNUMERIC
Test is numeric
value | |
---|---|
Name | ISNUMERIC |
Value | 83 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | 1 |
Stack Push | 1 |
ISNUMERIC
Bytecode Assembly Example<- r"(
code LDCONST 1
ISNUMERIC
RETURN
)"
asm(code) |> eval()
[1] TRUE
ISOBJECT
Test is object
value | |
---|---|
Name | ISOBJECT |
Value | 82 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | 1 |
Stack Push | 1 |
ISOBJECT
Bytecode Assembly Example<- r"(
code LDCONST "a"
ISOBJECT
RETURN
)"
asm(code) |> eval()
[1] FALSE
ISOBJECT
bytecodeis.object(x)
BASEGUARD @label1
GETVAR x
ISOBJECT
@label1
RETURN
ISSYMBOL
Test is symbol
value | |
---|---|
Name | ISSYMBOL |
Value | 81 |
Number of Args | 0 |
Has expr index | FALSE |
Stack Pop | 1 |
Stack Push | 1 |
ISSYMBOL
Bytecode Assembly Example<- r"(
code LDCONST 1.23
ISSYMBOL
RETURN
)"
asm(code) |> eval()
[1] FALSE
ISSYMBOL
bytecodeis.symbol(x)
BASEGUARD @label1
GETVAR x
ISSYMBOL
@label1
RETURN
LDCONST
Load 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.
runif(3)
LDCONST 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 Example<- r"(
code LDCONST 1.23
RETURN
)"
asm(code) |> eval()
[1] 1.23
LDCONST
bytecode1 + x
LDCONST 1
GETVAR x
ADD
RETURN
LDFALSE
Load 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 Example<- r"(
code LDFALSE
RETURN
)"
asm(code) |> eval()
[1] FALSE
LDFALSE
bytecode& FALSE x
GETVAR x
LDFALSE
AND
RETURN
LDNULL
Load 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 Example<- r"(
code LDNULL
RETURN
)"
asm(code) |> eval()
NULL
LDNULL
bytecodeNULL > x
LDNULL
GETVAR x
GT
RETURN
LDTRUE
Load 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 Example<- r"(
code LDTRUE
RETURN
)"
asm(code) |> eval()
[1] TRUE
LDTRUE
bytecode& TRUE x
GETVAR x
LDTRUE
AND
RETURN
LE
Test 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 Example<- r"(
code LDCONST 7
LDCONST 5
LE
RETURN
)"
asm(code) |> eval()
[1] FALSE
LE
bytecode<= 5 x
GETVAR x
LDCONST 5
LE
RETURN
LOG
Log (base e)
value | |
---|---|
Name | LOG |
Value | 116 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 1 |
Stack Push | 1 |
LOG
Bytecode Assembly Example<- r"(
code LDCONST 2.71
LOG
RETURN
)"
asm(code) |> eval()
[1] 0.9969486
LOG
bytecodelog(x)
BASEGUARD @label1
GETVAR x
LOG
@label1
RETURN
LOGBASE
Log
value | |
---|---|
Name | LOGBASE |
Value | 117 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 1 |
LOGBASE
Bytecode Assembly Example<- r"(
code 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
LT
Test less than
value | |
---|---|
Name | LT |
Value | 53 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 1 |
LT
Bytecode Assembly Example<- r"(
code LDCONST 7
LDCONST 5
LT
RETURN
)"
asm(code) |> eval()
[1] FALSE
LT
bytecode< 5 x
GETVAR x
LDCONST 5
LT
RETURN
MAKECLOSURE
Make 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
MAKEPROM
Make 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 Example<- r"(
code 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
MATH1
Perform a mathematical operation.
Perform one of the built-in mathematical operations.
# List of all operations
:::math1funs compiler
[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 Example<- r"(
code 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
MATSUBASSIGN
Assign into matrix with [
value | |
---|---|
Name | MATSUBASSIGN |
Value | 87 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 0 |
MATSUBASSIGN
bytecode1,2] <- 1 m[
LDCONST 1
STARTASSIGN m
STARTSUBASSIGN_N @label1
LDCONST 1
LDCONST 2
MATSUBASSIGN
@label1
ENDASSIGN m
INVISIBLE
RETURN
MATSUBASSIGN2
Assign into matrix with [[
value | |
---|---|
Name | MATSUBASSIGN2 |
Value | 109 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 0 |
MATSUBASSIGN2
bytecode1,2]] <- 1 m[[
LDCONST 1
STARTASSIGN m
STARTSUBASSIGN2_N @label1
LDCONST 1
LDCONST 2
MATSUBASSIGN2
@label1
ENDASSIGN m
INVISIBLE
RETURN
MATSUBSET
Subset matrix with [
value | |
---|---|
Name | MATSUBSET |
Value | 85 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 0 |
MATSUBSET
bytecode1,2] m[
GETVAR m
STARTSUBSET_N @label1
LDCONST 1
LDCONST 2
MATSUBSET
@label1
RETURN
MATSUBSET2
Subset matrix with [[
value | |
---|---|
Name | MATSUBSET2 |
Value | 107 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 0 |
MATSUBSET2
bytecode1,2]] m[[
GETVAR m
STARTSUBSET2_N @label1
LDCONST 1
LDCONST 2
MATSUBSET2
@label1
RETURN
MUL
Multiply
value | |
---|---|
Name | MUL |
Value | 46 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 1 |
MUL
Bytecode Assembly Example<- r"(
code LDCONST 1
LDCONST 2
MUL
RETURN
)"
asm(code) |> eval()
[1] 2
MUL
bytecode* y x
GETVAR x
GETVAR y
MUL
RETURN
NE
Test 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 Example<- r"(
code LDCONST 2
LDCONST 3
NE
RETURN
)"
asm(code) |> eval()
[1] TRUE
NE
bytecode!= 3 x
GETVAR x
LDCONST 3
NE
RETURN
NOT
Logical NOT operation
value | |
---|---|
Name | NOT |
Value | 59 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 1 |
Stack Push | 1 |
NOT
Bytecode Assembly Example<- r"(
code LDTRUE
NOT
RETURN
)"
asm(code) |> eval()
[1] FALSE
NOT
bytecode!x
GETVAR x
NOT
RETURN
OR
Vector logical OR
value | |
---|---|
Name | OR |
Value | 58 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 1 |
OR
Bytecode Assembly Example<- r"(
code LDCONST c(TRUE, TRUE)
LDCONST c(TRUE, FALSE)
OR
RETURN
)"
asm(code) |> eval()
[1] TRUE TRUE
OR
bytecode| y x
GETVAR x
GETVAR y
OR
RETURN
OR1ST
Scalar 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 Example<- r"(
code LDFALSE
OR1ST @label1
LDFALSE
OR2ND
@label1
RETURN
)"
asm(code) |> eval()
[1] FALSE
OR1ST
bytecode|| y x
GETVAR x
OR1ST @label1
GETVAR y
OR2ND
@label1
RETURN
OR2ND
Scalar 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
bytecode|| y x
GETVAR x
OR1ST @label1
GETVAR y
OR2ND
@label1
RETURN
POP
Pop 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 Example<- r"(
code LDCONST 1
LDCONST 2
POP
RETURN
)"
asm(code) |> eval()
[1] 1
PRINTVALUE
Purpose 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 | ? |
PUSHARG
Push 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 Example<- r"(
code 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
PUSHCONSTARG
Push 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 Example<- r"(
code 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
PUSHFALSEARG
Push 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 Example<- r"(
code 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
PUSHNULLARG
Push 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 Example<- r"(
code GETFUN identity
PUSHNULLARG
CALL
RETURN
)"
asm(code) |> eval()
NULL
PUSHNULLARG
bytecodef(1, NULL, TRUE, FALSE)
GETFUN f
PUSHCONSTARG 1
PUSHNULLARG
PUSHTRUEARG
PUSHFALSEARG
CALL
RETURN
PUSHTRUEARG
Push 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 Example<- r"(
code 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
RETURN
Return 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 Example<- r"(
code LDCONST 1
LDCONST 2
ADD
RETURN
)"
asm(code) |> eval()
[1] 3
RETURN
bytecode+ 1 a
GETVAR a
LDCONST 1
ADD
RETURN
RETURNJMP
Return 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 |
SEQALONG
Create 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 Example<- r"(
code 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
SEQLEN
Create 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 Example<- r"(
code LDCONST 5
SEQLEN
RETURN
)"
asm(code) |> eval()
[1] 1 2 3 4 5
SEQLEN
bytecodeseq_len(x)
BASEGUARD @label1
GETVAR x
SEQLEN
@label1
RETURN
SETLOOPVAL
Purpose 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 | ? |
SETTAG
Set 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 Example<- r"(
code 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_CALL
Assignment 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
SETVAR
Set 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 Example<- r"(
code LDCONST 1
SETVAR y
GETVAR y
RETURN
)"
asm(code) |> eval()
[1] 1
SETVAR
bytecode<- y x
GETVAR y
SETVAR x
INVISIBLE
RETURN
SETVAR2
Use 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
bytecode<<- y x
GETVAR y
SETVAR2 x
INVISIBLE
RETURN
SQRT
Square root
value | |
---|---|
Name | SQRT |
Value | 49 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 1 |
Stack Push | 1 |
SQRT
Bytecode Assembly Example<- r"(
code LDCONST 2
SQRT
RETURN
)"
asm(code) |> eval()
[1] 1.414214
SQRT
bytecodesqrt(x)
BASEGUARD @label1
GETVAR x
SQRT
@label1
RETURN
STARTASSIGN
Start 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
bytecode1] <- 2 a[
LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
STARTASSIGN2
Start 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 |
STARTC
Deprecated 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 |
STARTFOR
Initiate 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
STARTLOOPCNTXT
Start 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
STARTSUBASSIGN
An 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
bytecode<- 1 a[]
LDCONST 1
STARTASSIGN a
STARTSUBASSIGN @label1
DOMISSING
DFLTSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
STARTSUBASSIGN_N
Start 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
bytecode1] <- 2 a[
LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
STARTSUBASSIGN2
Start 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
bytecode<- 1 m[[,,]]
LDCONST 1
STARTASSIGN m
STARTSUBASSIGN2 @label1
DOMISSING
DOMISSING
DOMISSING
DFLTSUBASSIGN2
@label1
ENDASSIGN m
INVISIBLE
RETURN
STARTSUBASSIGN2_N
Start 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
bytecode1,2,3]] <- 1 m[[
LDCONST 1
@label2
STARTASSIGN m
STARTSUBASSIGN2_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBASSIGN2_N @label2
@label1
ENDASSIGN m
INVISIBLE
RETURN
STARTSUBSET
Start 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
bytecode a[]
GETVAR a
STARTSUBSET @label1
DOMISSING
DFLTSUBSET
@label1
RETURN
STARTSUBSET_N
Start 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
bytecode1] a[
GETVAR a
STARTSUBSET_N @label1
LDCONST 1
VECSUBSET
@label1
RETURN
STARTSUBSET2
Array 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
bytecode m[[,,]]
GETVAR m
STARTSUBSET2 @label1
DOMISSING
DOMISSING
DOMISSING
DFLTSUBSET2
@label1
RETURN
STARTSUBSET2_N
Start 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
bytecode1]] a[[
GETVAR a
STARTSUBSET2_N @label1
LDCONST 1
VECSUBSET2
@label1
RETURN
STEPFOR
Advance 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
SUB
Subtraction
value | |
---|---|
Name | SUB |
Value | 45 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 2 |
Stack Push | 1 |
SUB
Bytecode Assembly Example<- r"(
code LDCONST 1
LDCONST 2
SUB
RETURN
)"
asm(code) |> eval()
[1] -1
SUB
bytecode- y x
GETVAR x
GETVAR y
SUB
RETURN
SUBASSIGN_N
Assignment 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
bytecode1,2,3] <- 1 m[
LDCONST 1
@label2
STARTASSIGN m
STARTSUBASSIGN_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBASSIGN_N @label2
@label1
ENDASSIGN m
INVISIBLE
RETURN
SUBASSIGN2_N
Assignment 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
bytecode1, 2, 3]] <- 1 m[[
LDCONST 1
@label2
STARTASSIGN m
STARTSUBASSIGN2_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBASSIGN2_N @label2
@label1
ENDASSIGN m
INVISIBLE
RETURN
SUBSET_N
Subset 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
bytecode1,2,3] m[
GETVAR m
@label2
STARTSUBSET_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBSET_N @label2
@label1
RETURN
SUBSET2_N
Subset 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
bytecode1,2,3]] m[[
GETVAR m
@label2
STARTSUBSET2_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBSET2_N @label2
@label1
RETURN
SWAP
Swap 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 Example<- r"(
code LDCONST "apple"
LDCONST "banana"
SWAP
RETURN
)"
asm(code) |> eval()
[1] "apple"
SWITCH
Equivalent 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:
NULL
NULL
switch()
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
UMINUS
Unary minus
value | |
---|---|
Name | UMINUS |
Value | 42 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 1 |
Stack Push | 1 |
UMINUS
Bytecode Assembly Example<- r"(
code LDCONST 1
UMINUS
RETURN
)"
asm(code) |> eval()
[1] -1
UMINUS
bytecode-x + 1
GETVAR x
UMINUS
LDCONST 1
ADD
RETURN
UPLUS
Unary plus
value | |
---|---|
Name | UPLUS |
Value | 43 |
Number of Args | 0 |
Has expr index | TRUE |
Stack Pop | 1 |
Stack Push | 1 |
UPLUS
Bytecode Assembly Example<- r"(
code LDCONST 1
UPLUS
RETURN
)"
asm(code) |> eval()
[1] 1
UPLUS
bytecode+x + 1
GETVAR x
UPLUS
LDCONST 1
ADD
RETURN
VECSUBASSIGN
End 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
bytecode1] <- 2 a[
LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN
@label1
ENDASSIGN a
INVISIBLE
RETURN
VECSUBASSIGN2
End 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
bytecode1]] <- 2 a[[
LDCONST 2
STARTASSIGN a
STARTSUBASSIGN2_N @label1
LDCONST 1
VECSUBASSIGN2
@label1
ENDASSIGN a
INVISIBLE
RETURN
VECSUBSET
Vector 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
bytecode1] a[
GETVAR a
STARTSUBSET_N @label1
LDCONST 1
VECSUBSET
@label1
RETURN
VECSUBSET2
Vector 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
bytecode1]] a[[
GETVAR a
STARTSUBSET2_N @label1
LDCONST 1
VECSUBSET2
@label1
RETURN
VISIBLE
Make 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 Example<- r"(
code LDCONST 1
INVISIBLE
VISIBLE
RETURN
)"
asm(code) |> eval()
[1] 1