9  Instruction Reference

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.

9.1 ADD

Add values

Instruction summary
value
Name ADD
Value 44
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.1.1 ADD Bytecode Assembly Example

code <- r"(
# 1 + 2
LDCONST 1
LDCONST 2
ADD
RETURN
)"

asm(code) |> eval()
[1] 3

9.1.2 Example R code producing ADD bytecode

x + y
GETVAR x
GETVAR y
ADD 
RETURN 

9.2 AND

Vector logical AND

Instruction summary
value
Name AND
Value 57
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.2.1 AND Bytecode Assembly Example

code <- r"(
LDCONST c(TRUE, TRUE, FALSE, FALSE)
LDCONST c(FALSE, TRUE, FALSE, TRUE)
AND
RETURN
)"

asm(code) |> eval()
[1] FALSE  TRUE FALSE FALSE

9.2.2 Example R code producing AND bytecode

x & y
GETVAR x
GETVAR y
AND 
RETURN 

9.3 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.

Instruction summary
value
Name AND1ST
Value 88
Number of Args 1
Has expr index TRUE
Stack Pop 1
Stack Push 1
Argument summary
Argument Type Description
1 label Location to jump to if first logical value is FALSE

9.3.1 AND1ST Bytecode Assembly Example

code <- r"(
# TRUE && FALSE
LDTRUE
AND1ST @label1
LDFALSE
AND2ND
@label1
RETURN
)"

asm(code) |> eval()
[1] FALSE

9.3.2 Example R code producing AND1ST bytecode

x && y
GETVAR x
AND1ST @label1
GETVAR y
AND2ND 
@label1 
RETURN 

9.4 AND2ND

Scalar logical AND (Part 2)

See the AND1ST instruction Section 9.3

Instruction summary
value
Name AND2ND
Value 89
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 1

9.4.1 AND2ND Bytecode Assembly Example

code <- r"(
LDTRUE
AND1ST @label1
LDFALSE
AND2ND
@label1
RETURN
)"

asm(code) |> eval()
[1] FALSE

9.4.2 Example R code producing AND2ND bytecode

x && y
GETVAR x
AND1ST @label1
GETVAR y
AND2ND 
@label1 
RETURN 

9.5 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.

9.5.1 Hypothesis

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.

Instruction summary
value
Name BASEGUARD
Value 123
Number of Args 1
Has expr index TRUE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location to jump to if function is not valid

9.5.2 BASEGUARD Bytecode Assembly Example

code <- r"(
BASEGUARD @label1
GETBUILTIN list
PUSHCONSTARG 1
PUSHCONSTARG 2
CALLBUILTIN
@label1
RETURN
)"

asm(code) |> eval()
[[1]]
[1] 1

[[2]]
[1] 2

9.5.3 Example R code producing BASEGUARD bytecode

list(a, b, c)
BASEGUARD @label1
GETBUILTIN list
GETVAR a
PUSHARG 
GETVAR b
PUSHARG 
GETVAR c
PUSHARG 
CALLBUILTIN 
@label1 
RETURN 

9.6 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.

Instruction summary
value
Name BCMISMATCH
Value 0
Number of Args 0
Has expr index FALSE
Stack Pop 0
Stack Push 0

9.7 BRIFNOT

Branch if not TRUE

Note: There is no instruction for “Branch if TRUE”

Instruction summary
value
Name BRIFNOT
Value 3
Number of Args 1
Has expr index TRUE
Stack Pop 1
Stack Push 0
Argument summary
Argument Type Description
1 label Location to jump to if value popped off stack is FALSE

9.7.1 BRIFNOT Bytecode Assembly Example

code <- r"(
LDFALSE
BRIFNOT @label1
LDCONST 1
RETURN
@label1
LDCONST 2
RETURN
)"

asm(code) |> eval()
[1] 2

9.7.2 Example R code producing BRIFNOT bytecode

if (x > 5) print('hello')
GETVAR x
LDCONST 5
GT 
BRIFNOT @label1
GETFUN print
PUSHCONSTARG "hello"
CALL 
RETURN 
@label1 
LDNULL 
INVISIBLE 
RETURN 

9.8 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.

Instruction summary
value
Name CALL
Value 38
Number of Args 0
Has expr index TRUE
Stack Pop 0
Stack Push 1

9.8.1 CALL Bytecode Assembly Example

code <- r"(
GETFUN print
PUSHCONSTARG "hello"
CALL
RETURN
)"

asm(code) |> eval()
[1] "hello"

9.8.2 Example R code producing CALL bytecode

runif(3)
GETFUN runif
PUSHCONSTARG 3
CALL 
RETURN 

9.9 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.

Instruction summary
value
Name CALLBUILTIN
Value 39
Number of Args 0
Has expr index TRUE
Stack Pop 0
Stack Push 1

9.9.1 CALLBUILTIN Bytecode Assembly Example

code <- r"(
GETBUILTIN list
PUSHCONSTARG 1
PUSHCONSTARG 2
CALLBUILTIN
RETURN
)"

asm(code) |> eval()
[[1]]
[1] 1

[[2]]
[1] 2

9.9.2 Example R code producing CALLBUILTIN bytecode

c(a, b, c)
BASEGUARD @label1
GETBUILTIN c
GETVAR a
PUSHARG 
GETVAR b
PUSHARG 
GETVAR c
PUSHARG 
CALLBUILTIN 
@label1 
RETURN 

9.10 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.

Instruction summary
value
Name CALLSPECIAL
Value 40
Number of Args 1
Has expr index FALSE
Stack Pop 0
Stack Push 1
Argument summary
Argument Type Description
1 asis Character string which parses to a valid expression calling a “special” function.

See Section 11.2 for more details. |

9.10.1 CALLSPECIAL Bytecode Assembly Example

code <- r"(
CALLSPECIAL rep(1, 3)
RETURN
)"

asm(code) |> eval()
[1] 1 1 1

9.10.2 Example R code producing CALLSPECIAL bytecode

rep(1, 3)
BASEGUARD @label1
CALLSPECIAL rep(1, 3)
@label1 
RETURN 

9.11 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.

Instruction summary
value
Name CHECKFUN
Value 28
Number of Args 0
Has expr index FALSE
Stack Pop ?
Stack Push ?

9.11.1 Example R code producing CHECKFUN bytecode

get('list')(10)
GETFUN get
PUSHCONSTARG "list"
CALL 
CHECKFUN 
PUSHCONSTARG 10
CALL 
RETURN 

9.12 COLON

Colon operator e.g. 1:5

Instruction summary
value
Name COLON
Value 120
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.12.1 COLON Bytecode Assembly Example

code <- r"(
LDCONST 1
LDCONST 5
COLON
RETURN
)"

asm(code) |> eval()
[1] 1 2 3 4 5

9.12.2 Example R code producing COLON bytecode

x:y
GETVAR x
GETVAR y
COLON 
RETURN 

9.13 DDVAL

Get a double-dot value

Instruction summary
value
Name DDVAL
Value 21
Number of Args 1
Has expr index FALSE
Stack Pop
Stack Push
Argument summary
Argument Type Description
1 name Name of value to fetch

9.13.1 Example R code producing DDVAL bytecode

function(...) print(..3)
MAKECLOSURE ...
  GETFUN print
  MAKEPROM 
    DDVAL ..3
    RETURN 
  ENDMAKEPROM 
  CALL 
  RETURN 
ENDMAKECLOSURE 
RETURN 

9.14 DDVAL_MISSOK

Get a double-dot value. OK if it is missing

Instruction summary
value
Name DDVAL_MISSOK
Value 93
Number of Args 1
Has expr index FALSE
Stack Pop
Stack Push
Argument summary
Argument Type Description
1 name Name of value to fetch

9.15 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.

Instruction summary
value
Name DECLNK
Value 125
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.16 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.

Instruction summary
value
Name DECLNK_N
Value 126
Number of Args 1
Has expr index FALSE
Stack Pop
Stack Push
Argument summary
Argument Type Description
1 const Integer count of items in the stack on which to decrease the link count.

9.17 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.

Instruction summary
value
Name DECLNKSTK
Value 128
Number of Args 0
Has expr index FALSE
Stack Pop
Stack Push

9.18 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.

Instruction summary
value
Name DFLTC
Value 68
Number of Args 0
Has expr index FALSE
Stack Pop NA
Stack Push NA

9.19 DFLTSUBASSIGN

Default subassignment with []

Instruction summary
value
Name DFLTSUBASSIGN
Value 66
Number of Args 0
Has expr index FALSE
Stack Pop
Stack Push

9.19.1 Example R code producing DFLTSUBASSIGN bytecode

a[] <- 1
LDCONST 1
STARTASSIGN a
STARTSUBASSIGN @label1
DOMISSING 
DFLTSUBASSIGN 
@label1 
ENDASSIGN a
INVISIBLE 
RETURN 

9.20 DFLTSUBASSIGN2

Default subassignment with [[]]

Instruction summary
value
Name DFLTSUBASSIGN2
Value 72
Number of Args 0
Has expr index FALSE
Stack Pop
Stack Push

9.20.1 Example R code producing DFLTSUBASSIGN2 bytecode

a[[]] <- 1
LDCONST 1
STARTASSIGN a
STARTSUBASSIGN2 @label1
DOMISSING 
DFLTSUBASSIGN2 
@label1 
ENDASSIGN a
INVISIBLE 
RETURN 

9.21 DFLTSUBSET

Default subset with []

Instruction summary
value
Name DFLTSUBSET
Value 64
Number of Args 0
Has expr index FALSE
Stack Pop
Stack Push

9.21.1 Example R code producing DFLTSUBSET bytecode

a[]
GETVAR a
STARTSUBSET @label1
DOMISSING 
DFLTSUBSET 
@label1 
RETURN 

9.22 DFLTSUBSET2

Default subset with [[]]

Instruction summary
value
Name DFLTSUBSET2
Value 70
Number of Args 0
Has expr index FALSE
Stack Pop
Stack Push

9.22.1 Example R code producing DFLTSUBSET2 bytecode

a[[]]
GETVAR a
STARTSUBSET2 @label1
DOMISSING 
DFLTSUBSET2 
@label1 
RETURN 

9.23 DIV

Division

Instruction summary
value
Name DIV
Value 47
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.23.1 DIV Bytecode Assembly Example

code <- r"(
LDCONST 1
LDCONST 2
DIV
RETURN
)"

asm(code) |> eval()
[1] 0.5

9.23.2 Example R code producing DIV bytecode

x / y
GETVAR x
GETVAR y
DIV 
RETURN 

9.24 DODOTS

Process ...

Instruction summary
value
Name DODOTS
Value 32
Number of Args 0
Has expr index FALSE
Stack Pop
Stack Push

9.25 DOLLAR

$operator when used to fetch a value

Instruction summary
value
Name DOLLAR
Value 73
Number of Args 1
Has expr index TRUE
Stack Pop 1
Stack Push 1
Argument summary
Argument Type Description
1 name RHS name for $. LHS is popped from stack.

9.25.1 Example R code producing DOLLAR bytecode

x$y
GETVAR x
DOLLAR y
RETURN 

9.26 DOLLARGETS

$ operator when used to set a value

Instruction summary
value
Name DOLLARGETS
Value 74
Number of Args 1
Has expr index TRUE
Stack Pop
Stack Push
Argument summary
Argument Type Description
1 name RHS name for $. LHS is popped from stack.

9.26.1 Example R code producing DOLLARGETS bytecode

a$b <- 3
LDCONST 3
STARTASSIGN a
DOLLARGETS b
ENDASSIGN a
INVISIBLE 
RETURN 

9.27 DOLOOPBREAK

Purpose currently unknown.

Help needed: do not currently know what this bytecode is for or how to generate it from R code compilation.

Instruction summary
value
Name DOLOOPBREAK
Value 10
Number of Args 0
Has expr index FALSE
Stack Pop
Stack Push

9.28 DOLOOPNEXT

Purpose currently unknown.

Help needed: do not currently know what this bytecode is for or how to generate it from R code compilation.

Instruction summary
value
Name DOLOOPNEXT
Value 9
Number of Args 0
Has expr index FALSE
Stack Pop
Stack Push

9.29 DOMISSING

Handle missing arguments

Handling for missing arguments when function arguments being assessed at time of call

Instruction summary
value
Name DOMISSING
Value 30
Number of Args 0
Has expr index FALSE
Stack Pop
Stack Push

9.29.1 Example R code producing DOMISSING bytecode

f(x = )
GETFUN f
DOMISSING 
SETTAG x
CALL 
RETURN 

9.30 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.

Instruction summary
value
Name DOTCALL
Value 119
Number of Args 1
Has expr index TRUE
Stack Pop
Stack Push
Argument summary
Argument Type Description
1 value Number of arguments to this call.

9.30.1 Example R code producing DOTCALL bytecode

.Call(hello, x, y, z)
BASEGUARD @label1
GETVAR hello
GETVAR x
GETVAR y
GETVAR z
DOTCALL 3
@label1 
RETURN 

9.31 DOTSERR

Trigger error when ... used out of context

Instruction summary
value
Name DOTSERR
Value 60
Number of Args 0
Has expr index FALSE
Stack Pop
Stack Push

9.31.1 DOTSERR Bytecode Assembly Example

code <- r"(
DOTSERR
RETURN
)"

asm(code) |> eval()
Error in stop("{rbytecode}"): '...' used in an incorrect context

9.32 DUP

Duplicate the top value in the stack to make it the first two values in the stack.

Instruction summary
value
Name DUP
Value 5
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 2

9.32.1 DUP Bytecode Assembly Example

code <- r"(
LDCONST 1
DUP
ADD
RETURN
)"

asm(code) |> eval()
[1] 2

9.33 DUP2ND

Duplicate the second value in the stack to push it onto the stack (so it is the first item)

Instruction summary
value
Name DUP2ND
Value 101
Number of Args 0
Has expr index FALSE
Stack Pop 2
Stack Push 3

9.33.1 DUP2ND Bytecode Assembly Example

code <- r"(
LDCONST 10
LDCONST 20
DUP2ND
RETURN
)"

asm(code) |> eval()
[1] 10

9.34 ENDASSIGN

Mark the end of an assignment operation started with STARTASSIGN

Instruction summary
value
Name ENDASSIGN
Value 62
Number of Args 1
Has expr index FALSE
Stack Pop
Stack Push
Argument summary
Argument Type Description
1 name Name of variable into which value is being assigned

9.34.1 Example R code producing ENDASSIGN bytecode

a[1] <- 2
LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN 
@label1 
ENDASSIGN a
INVISIBLE 
RETURN 

9.35 ENDASSIGN2

Mark the end of an assignment operation started with STARTASSIGN2

Instruction summary
value
Name ENDASSIGN2
Value 97
Number of Args 1
Has expr index FALSE
Stack Pop
Stack Push
Argument summary
Argument Type Description
1 name Name of variable into which value is being assigned

9.36 ENDFOR

Signify end of for loop.

See also STEPFOR Section 9.115 and STARTFOR Section 9.105.

Instruction summary
value
Name ENDFOR
Value 13
Number of Args 0
Has expr index FALSE
Stack Pop
Stack Push

9.36.1 Example R code producing ENDFOR bytecode

for(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 

9.37 ENDLOOPCNTXT

End loop context

See STARTLOOPCNTXT (Section 9.106)

Instruction summary
value
Name ENDLOOPCNTXT
Value 8
Number of Args 0
Has expr index TRUE
Stack Pop
Stack Push

9.38 EQ

Test equality

Instruction summary
value
Name EQ
Value 51
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.38.1 EQ Bytecode Assembly Example

code <- r"(
LDCONST 2
LDCONST 2
EQ
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.38.2 Example R code producing EQ bytecode

x == 4
GETVAR x
LDCONST 4
EQ 
RETURN 

9.39 EXP

Exponential

Instruction summary
value
Name EXP
Value 50
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 1

9.39.1 EXP Bytecode Assembly Example

code <- r"(
LDCONST 2
EXP
RETURN
)"

asm(code) |> eval()
[1] 7.389056

9.39.2 Example R code producing EXP bytecode

exp(x)
BASEGUARD @label1
GETVAR x
EXP 
@label1 
RETURN 

9.40 EXPT

Exponent.

Instruction summary
value
Name EXPT
Value 48
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.40.1 EXPT Bytecode Assembly Example

code <- r"(
LDCONST 2
LDCONST 3
EXPT
RETURN
)"

asm(code) |> eval()
[1] 8

9.40.2 Example R code producing EXPT bytecode

x^2
GETVAR x
LDCONST 2
EXPT 
RETURN 

9.41 GE

Test greater than or equal to

Instruction summary
value
Name GE
Value 55
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.41.1 GE Bytecode Assembly Example

code <- r"(
LDCONST 7
LDCONST 5
GE
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.41.2 Example R code producing GE bytecode

x >= 5
GETVAR x
LDCONST 5
GE 
RETURN 

9.42 GETBUILTIN

Get a built-in function

Instruction summary
value
Name GETBUILTIN
Value 26
Number of Args 1
Has expr index FALSE
Stack Pop 0
Stack Push 1
Argument summary
Argument Type Description
1 name Name of builtin function. See Section 11.1 for more details.

9.42.1 GETBUILTIN Bytecode Assembly Example

code <- r"(
GETBUILTIN list
PUSHCONSTARG 1.23
CALLBUILTIN
RETURN
)"

asm(code) |> eval()
[[1]]
[1] 1.23

9.42.2 Example R code producing GETBUILTIN bytecode

list(1, x)
BASEGUARD @label1
GETBUILTIN list
PUSHCONSTARG 1
GETVAR x
PUSHARG 
CALLBUILTIN 
@label1 
RETURN 

9.43 GETFUN

Get a named function

Instruction summary
value
Name GETFUN
Value 23
Number of Args 1
Has expr index FALSE
Stack Pop 0
Stack Push 1
Argument summary
Argument Type Description
1 name Name of function

9.43.1 GETFUN Bytecode Assembly Example

code <- r"(
GETFUN runif
PUSHCONSTARG 3
CALL
RETURN
)"

asm(code) |> eval()
[1] 0.01726767 0.25755519 0.46669281

9.43.2 Example R code producing GETFUN bytecode

fn(1)
GETFUN fn
PUSHCONSTARG 1
CALL 
RETURN 

9.44 GETGLOBFUN

Get a named function from the global environment (Unconfirmed)

Help needed: R code which uses this instruction.

Instruction summary
value
Name GETGLOBFUN
Value 24
Number of Args 1
Has expr index FALSE
Stack Pop
Stack Push
Argument summary
Argument Type Description
1 name Name of function

9.45 GETINTLBUILTIN

Get an internal function

Instruction summary
value
Name GETINTLBUILTIN
Value 27
Number of Args 1
Has expr index FALSE
Stack Pop
Stack Push
Argument summary
Argument Type Description
1 name Name of function

9.45.1 Example R code producing GETINTLBUILTIN bytecode

.Internal(disassemble(asm("RETURN")))
BASEGUARD @label1
GETINTLBUILTIN disassemble
GETFUN asm
PUSHCONSTARG "RETURN"
CALL 
PUSHARG 
CALLBUILTIN 
@label1 
RETURN 

9.46 GETSYMFUN

Get a function by its symbol (Unconfirmed)

Help needed: R code which uses this instruction.

Instruction summary
value
Name GETSYMFUN
Value 25
Number of Args 1
Has expr index FALSE
Stack Pop
Stack Push
Argument summary
Argument Type Description
1 name Name of function

9.47 GETTER_CALL

Used in complex assignment expressions

Help needed: R code which uses this instruction.

Instruction summary
value
Name GETTER_CALL
Value 99
Number of Args 0
Has expr index TRUE
Stack Pop
Stack Push

9.48 GETVAR

Get a named variable

Instruction summary
value
Name GETVAR
Value 20
Number of Args 1
Has expr index FALSE
Stack Pop 0
Stack Push 1
Argument summary
Argument Type Description
1 name Name of variable

9.48.1 GETVAR Bytecode Assembly Example

code <- r"(
LDCONST 1
SETVAR x
POP
GETBUILTIN list
GETVAR x
PUSHARG
CALLBUILTIN
RETURN
)"

asm(code) |> eval()
[[1]]
[1] 1

9.48.2 Example R code producing GETVAR bytecode

1 + x
LDCONST 1
GETVAR x
ADD 
RETURN 

9.49 GETVAR_MISSOK

Get a named variable. Missing values allowed.

Instruction summary
value
Name GETVAR_MISSOK
Value 92
Number of Args 1
Has expr index FALSE
Stack Pop
Stack Push
Argument summary
Argument Type Description
1 name Name of variable

9.49.1 Example R code producing GETVAR_MISSOK bytecode

a[i]
GETVAR a
STARTSUBSET_N @label1
GETVAR_MISSOK i
VECSUBSET 
@label1 
RETURN 

9.50 GOTO

Jump to the labelled location

Instruction summary
value
Name GOTO
Value 2
Number of Args 1
Has expr index FALSE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location to jump to

9.50.1 GOTO Bytecode Assembly Example

code <- r"(
  LDCONST 5
  LDCONST 4
  GE
  BRIFNOT @label1
  LDCONST 66
  GOTO @label2
  @label1
  LDCONST 99
  RETURN
  @label2
  RETURN
)"

asm(code) |> eval()
[1] 66

9.50.2 Example R code producing GOTO bytecode

while(TRUE) print('hello')
@label2 
LDTRUE 
BRIFNOT @label1
GETFUN print
PUSHCONSTARG "hello"
CALL 
POP 
GOTO @label2
@label1 
LDNULL 
INVISIBLE 
RETURN 

9.51 GT

Test greater than

Instruction summary
value
Name GT
Value 56
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.51.1 GT Bytecode Assembly Example

code <- r"(
LDCONST 7
LDCONST 5
GT
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.51.2 Example R code producing GT bytecode

x > 5
GETVAR x
LDCONST 5
GT 
RETURN 

9.52 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.

Instruction summary
value
Name INCLNK
Value 124
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.53 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.

Instruction summary
value
Name INCLNKSTK
Value 127
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.54 INVISIBLE

Mark a value as invisible.

A bytecode version of the invisible() function.

Instruction summary
value
Name INVISIBLE
Value 15
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.54.1 INVISIBLE Bytecode Assembly Example

code <- r"(
LDCONST 1
INVISIBLE
RETURN
)"

asm(code) |> eval()

9.55 ISCHARACTER

Test is character

Instruction summary
value
Name ISCHARACTER
Value 80
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.55.1 ISCHARACTER Bytecode Assembly Example

code <- r"(
LDCONST "a"
ISCHARACTER
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.55.2 Example R code producing ISCHARACTER bytecode

is.character(x)
BASEGUARD @label1
GETVAR x
ISCHARACTER 
@label1 
RETURN 

9.56 ISCOMPLEX

Test is complex

Instruction summary
value
Name ISCOMPLEX
Value 79
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.56.1 ISCOMPLEX Bytecode Assembly Example

code <- r"(
LDCONST 1i
ISCOMPLEX
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.56.2 Example R code producing ISCOMPLEX bytecode

is.complex(x)
BASEGUARD @label1
GETVAR x
ISCOMPLEX 
@label1 
RETURN 

9.57 ISDOUBLE

Test is double

Instruction summary
value
Name ISDOUBLE
Value 78
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.57.1 ISDOUBLE Bytecode Assembly Example

code <- r"(
LDCONST 1.23
ISDOUBLE
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.57.2 Example R code producing ISDOUBLE bytecode

is.double(x)
BASEGUARD @label1
GETVAR x
ISDOUBLE 
@label1 
RETURN 

9.58 ISINTEGER

Test is integer

Instruction summary
value
Name ISINTEGER
Value 77
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.58.1 ISINTEGER Bytecode Assembly Example

code <- r"(
LDCONST 1L
ISINTEGER
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.58.2 Example R code producing ISINTEGER bytecode

is.integer(x)
BASEGUARD @label1
GETVAR x
ISINTEGER 
@label1 
RETURN 

9.59 ISLOGICAL

Test is logical

Instruction summary
value
Name ISLOGICAL
Value 76
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.59.1 ISLOGICAL Bytecode Assembly Example

code <- r"(
LDCONST TRUE
ISLOGICAL
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.59.2 Example R code producing ISLOGICAL bytecode

is.logical(x)
BASEGUARD @label1
GETVAR x
ISLOGICAL 
@label1 
RETURN 

9.60 ISNULL

Test is NULL

Instruction summary
value
Name ISNULL
Value 75
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.60.1 ISNULL Bytecode Assembly Example

code <- r"(
LDNULL
ISNULL
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.60.2 Example R code producing ISNULL bytecode

is.null(x)
BASEGUARD @label1
GETVAR x
ISNULL 
@label1 
RETURN 

9.61 ISNUMERIC

Test is numeric

Instruction summary
value
Name ISNUMERIC
Value 83
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.61.1 ISNUMERIC Bytecode Assembly Example

code <- r"(
LDCONST 1
ISNUMERIC
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.62 ISOBJECT

Test is object

Instruction summary
value
Name ISOBJECT
Value 82
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.62.1 ISOBJECT Bytecode Assembly Example

code <- r"(
LDCONST "a"
ISOBJECT
RETURN
)"

asm(code) |> eval()
[1] FALSE

9.62.2 Example R code producing ISOBJECT bytecode

is.object(x)
BASEGUARD @label1
GETVAR x
ISOBJECT 
@label1 
RETURN 

9.63 ISSYMBOL

Test is symbol

Instruction summary
value
Name ISSYMBOL
Value 81
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.63.1 ISSYMBOL Bytecode Assembly Example

code <- r"(
LDCONST 1.23
ISSYMBOL
RETURN
)"

asm(code) |> eval()
[1] FALSE

9.63.2 Example R code producing ISSYMBOL bytecode

is.symbol(x)
BASEGUARD @label1
GETVAR x
ISSYMBOL 
@label1 
RETURN 

9.64 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.

LDCONST runif(3)
RETURN
Instruction summary
value
Name LDCONST
Value 16
Number of Args 1
Has expr index FALSE
Stack Pop 0
Stack Push 1
Argument summary
Argument Type Description
1 const Value or expression

9.64.1 LDCONST Bytecode Assembly Example

code <- r"(
LDCONST 1.23
RETURN
)"

asm(code) |> eval()
[1] 1.23

9.64.2 Example R code producing LDCONST bytecode

1 + x
LDCONST 1
GETVAR x
ADD 
RETURN 

9.65 LDFALSE

Load FALSE onto the stack

Instruction summary
value
Name LDFALSE
Value 19
Number of Args 0
Has expr index FALSE
Stack Pop 0
Stack Push 1

9.65.1 LDFALSE Bytecode Assembly Example

code <- r"(
LDFALSE
RETURN
)"

asm(code) |> eval()
[1] FALSE

9.65.2 Example R code producing LDFALSE bytecode

x & FALSE
GETVAR x
LDFALSE 
AND 
RETURN 

9.66 LDNULL

Load NULL onto the stack

Instruction summary
value
Name LDNULL
Value 17
Number of Args 0
Has expr index FALSE
Stack Pop 0
Stack Push 1

9.66.1 LDNULL Bytecode Assembly Example

code <- r"(
LDNULL
RETURN
)"

asm(code) |> eval()
NULL

9.66.2 Example R code producing LDNULL bytecode

NULL > x
LDNULL 
GETVAR x
GT 
RETURN 

9.67 LDTRUE

Load TRUE onto the stack

Instruction summary
value
Name LDTRUE
Value 18
Number of Args 0
Has expr index FALSE
Stack Pop 0
Stack Push 1

9.67.1 LDTRUE Bytecode Assembly Example

code <- r"(
LDTRUE
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.67.2 Example R code producing LDTRUE bytecode

x & TRUE
GETVAR x
LDTRUE 
AND 
RETURN 

9.68 LE

Test less than or equal to

Instruction summary
value
Name LE
Value 54
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.68.1 LE Bytecode Assembly Example

code <- r"(
LDCONST 7
LDCONST 5
LE
RETURN
)"

asm(code) |> eval()
[1] FALSE

9.68.2 Example R code producing LE bytecode

x <= 5
GETVAR x
LDCONST 5
LE 
RETURN 

9.69 LOG

Log (base e)

Instruction summary
value
Name LOG
Value 116
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 1

9.69.1 LOG Bytecode Assembly Example

code <- r"(
LDCONST 2.71
LOG
RETURN
)"

asm(code) |> eval()
[1] 0.9969486

9.69.2 Example R code producing LOG bytecode

log(x)
BASEGUARD @label1
GETVAR x
LOG 
@label1 
RETURN 

9.70 LOGBASE

Log

Instruction summary
value
Name LOGBASE
Value 117
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.70.1 LOGBASE Bytecode Assembly Example

code <- r"(
LDCONST 10
LDCONST 2
LOGBASE
RETURN
)"

asm(code) |> eval()
[1] 3.321928

9.70.2 Example R code producing LOGBASE bytecode

log(100, 10)
BASEGUARD @label1
LDCONST 100
LDCONST 10
LOGBASE 
@label1 
RETURN 

9.71 LT

Test less than

Instruction summary
value
Name LT
Value 53
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.71.1 LT Bytecode Assembly Example

code <- r"(
LDCONST 7
LDCONST 5
LT
RETURN
)"

asm(code) |> eval()
[1] FALSE

9.71.2 Example R code producing LT bytecode

x < 5
GETVAR x
LDCONST 5
LT 
RETURN 

9.72 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.

Instruction summary
value
Name MAKECLOSURE
Value 41
Number of Args 1
Has expr index FALSE
Stack Pop 0
Stack Push 1
Argument summary
Argument Type Description
1 closure Sequence of arguments to closure separated by semi-colons.

9.72.1 Example R code producing MAKECLOSURE bytecode

function(x) {x + 1}
MAKECLOSURE x
  GETVAR x
  LDCONST 1
  ADD 
  RETURN 
ENDMAKECLOSURE 
RETURN 

9.73 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.

Instruction summary
value
Name MAKEPROM
Value 29
Number of Args 1
Has expr index FALSE
Stack Pop 0
Stack Push 1
Argument summary
Argument Type Description
1 promise Special handling for promises in {rbytecode} means that the argument is automatically inferred from the instructions within MAKEPROM/ENDMAKEPROM

9.73.1 MAKEPROM Bytecode Assembly Example

code <- 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

9.73.2 Example R code producing MAKEPROM bytecode

runif(n = 3, min = x)
GETFUN runif
PUSHCONSTARG 3
SETTAG n
MAKEPROM 
  GETVAR x
  RETURN 
ENDMAKEPROM 
SETTAG min
CALL 
RETURN 

9.74 MATH1

Perform 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"   
Instruction summary
value
Name MATH1
Value 118
Number of Args 1
Has expr index TRUE
Stack Pop 1
Stack Push 1
Argument summary
Argument Type Description
1 math1name Name of valued math operation. See Section 11.3

9.74.1 MATH1 Bytecode Assembly Example

code <- r"(
LDCONST 1:5
MATH1 sin
RETURN
)"

asm(code) |> eval()
[1]  0.8414710  0.9092974  0.1411200 -0.7568025 -0.9589243

9.74.2 Example R code producing MATH1 bytecode

floor(x)
BASEGUARD @label1
GETVAR x
MATH1 floor
@label1 
RETURN 

9.75 MATSUBASSIGN

Assign into matrix with [

Instruction summary
value
Name MATSUBASSIGN
Value 87
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 0

9.75.1 Example R code producing MATSUBASSIGN bytecode

m[1,2] <- 1
LDCONST 1
STARTASSIGN m
STARTSUBASSIGN_N @label1
LDCONST 1
LDCONST 2
MATSUBASSIGN 
@label1 
ENDASSIGN m
INVISIBLE 
RETURN 

9.76 MATSUBASSIGN2

Assign into matrix with [[

Instruction summary
value
Name MATSUBASSIGN2
Value 109
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 0

9.76.1 Example R code producing MATSUBASSIGN2 bytecode

m[[1,2]] <- 1
LDCONST 1
STARTASSIGN m
STARTSUBASSIGN2_N @label1
LDCONST 1
LDCONST 2
MATSUBASSIGN2 
@label1 
ENDASSIGN m
INVISIBLE 
RETURN 

9.77 MATSUBSET

Subset matrix with [

Instruction summary
value
Name MATSUBSET
Value 85
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 0

9.77.1 Example R code producing MATSUBSET bytecode

m[1,2]
GETVAR m
STARTSUBSET_N @label1
LDCONST 1
LDCONST 2
MATSUBSET 
@label1 
RETURN 

9.78 MATSUBSET2

Subset matrix with [[

Instruction summary
value
Name MATSUBSET2
Value 107
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 0

9.78.1 Example R code producing MATSUBSET2 bytecode

m[[1,2]]
GETVAR m
STARTSUBSET2_N @label1
LDCONST 1
LDCONST 2
MATSUBSET2 
@label1 
RETURN 

9.79 MUL

Multiply

Instruction summary
value
Name MUL
Value 46
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.79.1 MUL Bytecode Assembly Example

code <- r"(
LDCONST 1
LDCONST 2
MUL
RETURN
)"

asm(code) |> eval()
[1] 2

9.79.2 Example R code producing MUL bytecode

x * y
GETVAR x
GETVAR y
MUL 
RETURN 

9.80 NE

Test not equal to

Instruction summary
value
Name NE
Value 52
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.80.1 NE Bytecode Assembly Example

code <- r"(
LDCONST 2
LDCONST 3
NE
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.80.2 Example R code producing NE bytecode

x != 3
GETVAR x
LDCONST 3
NE 
RETURN 

9.81 NOT

Logical NOT operation

Instruction summary
value
Name NOT
Value 59
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 1

9.81.1 NOT Bytecode Assembly Example

code <- r"(
LDTRUE
NOT
RETURN
)"

asm(code) |> eval()
[1] FALSE

9.81.2 Example R code producing NOT bytecode

!x
GETVAR x
NOT 
RETURN 

9.82 OR

Vector logical OR

Instruction summary
value
Name OR
Value 58
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.82.1 OR Bytecode Assembly Example

code <- r"(
LDCONST c(TRUE, TRUE)
LDCONST c(TRUE, FALSE)
OR
RETURN
)"

asm(code) |> eval()
[1] TRUE TRUE

9.82.2 Example R code producing OR bytecode

x | y
GETVAR x
GETVAR y
OR 
RETURN 

9.83 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.

Instruction summary
value
Name OR1ST
Value 90
Number of Args 1
Has expr index TRUE
Stack Pop 1
Stack Push 1
Argument summary
Argument Type Description
1 label Location to jump to if first logical value is TRUE

9.83.1 OR1ST Bytecode Assembly Example

code <- r"(
LDFALSE
OR1ST @label1
LDFALSE
OR2ND
@label1
RETURN
)"

asm(code) |> eval()
[1] FALSE

9.83.2 Example R code producing OR1ST bytecode

x || y
GETVAR x
OR1ST @label1
GETVAR y
OR2ND 
@label1 
RETURN 

9.84 OR2ND

Scalar logical OR (Part 2)

See the OR1ST instruction Section 9.83

Instruction summary
value
Name OR2ND
Value 91
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 1

9.84.1 Example R code producing OR2ND bytecode

x || y
GETVAR x
OR1ST @label1
GETVAR y
OR2ND 
@label1 
RETURN 

9.85 POP

Pop a value off the stack (and discard)

Instruction summary
value
Name POP
Value 4
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 0

9.85.1 POP Bytecode Assembly Example

code <- r"(
LDCONST 1
LDCONST 2
POP
RETURN
)"

asm(code) |> eval()
[1] 1

9.86 PRINTVALUE

Purpose currently unknown.

Help needed: do not currently know what this bytecode is for or how to generate it from R code compilation.

Instruction summary
value
Name PRINTVALUE
Value 6
Number of Args 0
Has expr index FALSE
Stack Pop ?
Stack Push ?

9.87 PUSHARG

Push an value from the stack into the list of arguments for a call

Instruction summary
value
Name PUSHARG
Value 33
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 0

9.87.1 PUSHARG Bytecode Assembly Example

code <- r"(
LDCONST 1
SETVAR x
POP
GETBUILTIN list
GETVAR x
PUSHARG
CALLBUILTIN
RETURN
)"

asm(code) |> eval()
[[1]]
[1] 1

9.87.2 Example R code producing PUSHARG bytecode

list(1, x)
BASEGUARD @label1
GETBUILTIN list
PUSHCONSTARG 1
GETVAR x
PUSHARG 
CALLBUILTIN 
@label1 
RETURN 

9.88 PUSHCONSTARG

Push a constant value into the list of arguments for a call.

Instruction summary
value
Name PUSHCONSTARG
Value 34
Number of Args 1
Has expr index FALSE
Stack Pop 1
Stack Push 0
Argument summary
Argument Type Description
1 const Value or expression to add to list of arguments for a function call

9.88.1 PUSHCONSTARG Bytecode Assembly Example

code <- r"(
GETFUN runif
PUSHCONSTARG 3
CALL
RETURN
)"

asm(code) |> eval()
[1] 0.002539779 0.725551877 0.514050746

9.88.2 Example R code producing PUSHCONSTARG bytecode

list(1, x)
BASEGUARD @label1
GETBUILTIN list
PUSHCONSTARG 1
GETVAR x
PUSHARG 
CALLBUILTIN 
@label1 
RETURN 

9.89 PUSHFALSEARG

Push FALSE into the list of arguments for a call

Instruction summary
value
Name PUSHFALSEARG
Value 37
Number of Args 0
Has expr index FALSE
Stack Pop 0
Stack Push 0

9.89.1 PUSHFALSEARG Bytecode Assembly Example

code <- r"(
GETFUN identity
PUSHFALSEARG
CALL
RETURN
)"

asm(code) |> eval()
[1] FALSE

9.89.2 Example R code producing PUSHFALSEARG bytecode

f(1, NULL, TRUE, FALSE)
GETFUN f
PUSHCONSTARG 1
PUSHNULLARG 
PUSHTRUEARG 
PUSHFALSEARG 
CALL 
RETURN 

9.90 PUSHNULLARG

Push NULL into the list of arguments for a call

Instruction summary
value
Name PUSHNULLARG
Value 35
Number of Args 0
Has expr index FALSE
Stack Pop 0
Stack Push 0

9.90.1 PUSHNULLARG Bytecode Assembly Example

code <- r"(
GETFUN identity
PUSHNULLARG
CALL
RETURN
)"

asm(code) |> eval()
NULL

9.90.2 Example R code producing PUSHNULLARG bytecode

f(1, NULL, TRUE, FALSE)
GETFUN f
PUSHCONSTARG 1
PUSHNULLARG 
PUSHTRUEARG 
PUSHFALSEARG 
CALL 
RETURN 

9.91 PUSHTRUEARG

Push TRUE into the list of arguments for a call.

Instruction summary
value
Name PUSHTRUEARG
Value 36
Number of Args 0
Has expr index FALSE
Stack Pop 0
Stack Push 0

9.91.1 PUSHTRUEARG Bytecode Assembly Example

code <- r"(
GETFUN identity
PUSHTRUEARG
CALL
RETURN
)"

asm(code) |> eval()
[1] TRUE

9.91.2 Example R code producing PUSHTRUEARG bytecode

f(1, NULL, TRUE, FALSE)
GETFUN f
PUSHCONSTARG 1
PUSHNULLARG 
PUSHTRUEARG 
PUSHFALSEARG 
CALL 
RETURN 

9.92 RETURN

Return control to the caller

Instruction summary
value
Name RETURN
Value 1
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 0

9.92.1 RETURN Bytecode Assembly Example

code <- r"(
LDCONST 1
LDCONST 2 
ADD
RETURN
)"

asm(code) |> eval()
[1] 3

9.92.2 Example R code producing RETURN bytecode

a + 1
GETVAR a
LDCONST 1
ADD 
RETURN 

9.93 RETURNJMP

Return control to the caller via a “longjmp”

It’s unclear on exactly when this instruction is generated.

Instruction summary
value
Name RETURNJMP
Value 103
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 0

9.94 SEQALONG

Create an integer sequence the same length as that next value on the stack.

Instruction summary
value
Name SEQALONG
Value 121
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 1

9.94.1 SEQALONG Bytecode Assembly Example

code <- r"(
LDCONST c(10, 20, 30)
SEQALONG
RETURN
)"

asm(code) |> eval()
[1] 1 2 3

9.94.2 Example R code producing SEQALONG bytecode

seq_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 

9.95 SEQLEN

Create an integer sequence of the given length

Instruction summary
value
Name SEQLEN
Value 122
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 1

9.95.1 SEQLEN Bytecode Assembly Example

code <- r"(
LDCONST 5
SEQLEN
RETURN
)"

asm(code) |> eval()
[1] 1 2 3 4 5

9.95.2 Example R code producing SEQLEN bytecode

seq_len(x)
BASEGUARD @label1
GETVAR x
SEQLEN 
@label1 
RETURN 

9.96 SETLOOPVAL

Purpose currently unknown.

Help needed: do not currently know what this bytecode is for or how to generate it from R code compilation.

Instruction summary
value
Name SETLOOPVAL
Value 14
Number of Args 0
Has expr index FALSE
Stack Pop ?
Stack Push ?

9.97 SETTAG

Set the name of an argument to a function

Instruction summary
value
Name SETTAG
Value 31
Number of Args 1
Has expr index FALSE
Stack Pop 1
Stack Push 1
Argument summary
Argument Type Description
1 name Name to set for most recent argument for a function call

9.97.1 SETTAG Bytecode Assembly Example

code <- 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

9.97.2 Example R code producing SETTAG bytecode

c(a = 1)
BASEGUARD @label1
GETBUILTIN c
PUSHCONSTARG 1
SETTAG a
CALLBUILTIN 
@label1 
RETURN 

9.98 SETTER_CALL

Assignment via a <- method

Instruction summary
value
Name SETTER_CALL
Value 98
Number of Args 1
Has expr index TRUE
Stack Pop 1
Stack Push 1
Argument summary
Argument Type Description
1 const Unknown

9.98.1 Example R code producing SETTER_CALL bytecode

names(x) <- 'hello'
LDCONST "hello"
STARTASSIGN x
GETFUN names<-
PUSHNULLARG 
SETTER_CALL "hello"
ENDASSIGN x
INVISIBLE 
RETURN 

9.99 SETVAR

Set the value of a variable

Instruction summary
value
Name SETVAR
Value 22
Number of Args 1
Has expr index FALSE
Stack Pop 1
Stack Push 1
Argument summary
Argument Type Description
1 name Name of variable

9.99.1 SETVAR Bytecode Assembly Example

code <- r"(
LDCONST 1
SETVAR y
GETVAR y
RETURN
)"

asm(code) |> eval()
[1] 1

9.99.2 Example R code producing SETVAR bytecode

x <- y
GETVAR y
SETVAR x
INVISIBLE 
RETURN 

9.100 SETVAR2

Use superassignment to set the value of a variable

Instruction summary
value
Name SETVAR2
Value 95
Number of Args 1
Has expr index FALSE
Stack Pop 1
Stack Push 1
Argument summary
Argument Type Description
1 name Name of variable

9.100.1 Example R code producing SETVAR2 bytecode

x <<- y
GETVAR y
SETVAR2 x
INVISIBLE 
RETURN 

9.101 SQRT

Square root

Instruction summary
value
Name SQRT
Value 49
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 1

9.101.1 SQRT Bytecode Assembly Example

code <- r"(
LDCONST 2
SQRT
RETURN
)"

asm(code) |> eval()
[1] 1.414214

9.101.2 Example R code producing SQRT bytecode

sqrt(x)
BASEGUARD @label1
GETVAR x
SQRT 
@label1 
RETURN 

9.102 STARTASSIGN

Start an assignment operation.

This instruction be paired with closing ENDASSIGN instruction.

Instruction summary
value
Name STARTASSIGN
Value 61
Number of Args 1
Has expr index FALSE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 name Name of variable into which value is being assigned

9.102.1 Example R code producing STARTASSIGN bytecode

a[1] <- 2
LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN 
@label1 
ENDASSIGN a
INVISIBLE 
RETURN 

9.103 STARTASSIGN2

Start an assignment operation.

This instruction be paired with closing ENDASSIGN2 instruction.

Help needed: R code example which uses this instruction

Instruction summary
value
Name STARTASSIGN2
Value 96
Number of Args 1
Has expr index FALSE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 name Name of variable into which value is being assigned

9.104 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.

Instruction summary
value
Name STARTC
Value 67
Number of Args 1
Has expr index TRUE
Stack Pop NA
Stack Push NA
Argument summary
Argument Type Description
1 label Deprecated

9.105 STARTFOR

Initiate a for loop

See also STEPFOR Section 9.115 and ENDFOR Section 9.36.

Instruction summary
value
Name STARTFOR
Value 11
Number of Args 2
Has expr index TRUE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 name Name of loop variable
2 label Location of matching STEPFOR instruction

9.105.1 Example R code producing STARTFOR bytecode

for(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 

9.106 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)

Instruction summary
value
Name STARTLOOPCNTXT
Value 7
Number of Args 1
Has expr index TRUE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.106.1 Example R code producing STARTLOOPCNTXT bytecode

repeat {
  eval("hello")
  break
}
STARTLOOPCNTXT @label1
@label2 
GETFUN eval
PUSHCONSTARG "hello"
CALL 
POP 
GOTO @label1
POP 
GOTO @label2
@label1 
ENDLOOPCNTXT 
LDNULL 
INVISIBLE 
RETURN 

9.107 STARTSUBASSIGN

An assignment operation into vector via an empty index

Help needed: Details of when this is used

Instruction summary
value
Name STARTSUBASSIGN
Value 65
Number of Args 1
Has expr index TRUE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.107.1 Example R code producing STARTSUBASSIGN bytecode

a[] <- 1
LDCONST 1
STARTASSIGN a
STARTSUBASSIGN @label1
DOMISSING 
DFLTSUBASSIGN 
@label1 
ENDASSIGN a
INVISIBLE 
RETURN 

9.108 STARTSUBASSIGN_N

Start an assignment operation into a vector.

This instruction must be paired with a closing VECSUBASSIGN instruction.

Instruction summary
value
Name STARTSUBASSIGN_N
Value 105
Number of Args 1
Has expr index TRUE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.108.1 Example R code producing STARTSUBASSIGN_N bytecode

a[1] <- 2
LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN 
@label1 
ENDASSIGN a
INVISIBLE 
RETURN 

9.109 STARTSUBASSIGN2

Start an assignment operation

Instruction summary
value
Name STARTSUBASSIGN2
Value 71
Number of Args 1
Has expr index TRUE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.109.1 Example R code producing STARTSUBASSIGN2 bytecode

m[[,,]] <- 1
LDCONST 1
STARTASSIGN m
STARTSUBASSIGN2 @label1
DOMISSING 
DOMISSING 
DOMISSING 
DFLTSUBASSIGN2 
@label1 
ENDASSIGN m
INVISIBLE 
RETURN 

9.110 STARTSUBASSIGN2_N

Start an assignment operation into a vector.

This instruction must be paired with a closing SUBASSIGN2_N instruction.

Instruction summary
value
Name STARTSUBASSIGN2_N
Value 111
Number of Args 1
Has expr index TRUE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.110.1 Example R code producing STARTSUBASSIGN2_N bytecode

m[[1,2,3]] <- 1
LDCONST 1
@label2 
STARTASSIGN m
STARTSUBASSIGN2_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBASSIGN2_N @label2
@label1 
ENDASSIGN m
INVISIBLE 
RETURN 

9.111 STARTSUBSET

Start vector subset with []

Help needed: R code example which uses this instruction

Instruction summary
value
Name STARTSUBSET
Value 63
Number of Args 1
Has expr index TRUE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.111.1 Example R code producing STARTSUBSET bytecode

a[]
GETVAR a
STARTSUBSET @label1
DOMISSING 
DFLTSUBSET 
@label1 
RETURN 

9.112 STARTSUBSET_N

Start vector subset

x[y] - label points to after matching VECSUBSET

Instruction summary
value
Name STARTSUBSET_N
Value 104
Number of Args 1
Has expr index TRUE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.112.1 Example R code producing STARTSUBSET_N bytecode

a[1]
GETVAR a
STARTSUBSET_N @label1
LDCONST 1
VECSUBSET 
@label1 
RETURN 

9.113 STARTSUBSET2

Array subset

This appears to be a vector subset instruction.

Help needed: R code example which uses this instruction

Instruction summary
value
Name STARTSUBSET2
Value 69
Number of Args 1
Has expr index TRUE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.113.1 Example R code producing STARTSUBSET2 bytecode

m[[,,]]
GETVAR m
STARTSUBSET2 @label1
DOMISSING 
DOMISSING 
DOMISSING 
DFLTSUBSET2 
@label1 
RETURN 

9.114 STARTSUBSET2_N

Start vector subset with [[]]

x[[y]] - label points to after matching VECSUBSET

Instruction summary
value
Name STARTSUBSET2_N
Value 110
Number of Args 1
Has expr index TRUE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.114.1 Example R code producing STARTSUBSET2_N bytecode

a[[1]]
GETVAR a
STARTSUBSET2_N @label1
LDCONST 1
VECSUBSET2 
@label1 
RETURN 

9.115 STEPFOR

Advance to the next element in a for loop

See also ENDFOR Section 9.36 and STARTFOR Section 9.105.

Instruction summary
value
Name STEPFOR
Value 12
Number of Args 1
Has expr index FALSE
Stack Pop 0
Stack Push 0
Argument summary
Argument Type Description
1 label Location of matching STARTFOR

9.115.1 Example R code producing STEPFOR bytecode

for(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 

9.116 SUB

Subtraction

Instruction summary
value
Name SUB
Value 45
Number of Args 0
Has expr index TRUE
Stack Pop 2
Stack Push 1

9.116.1 SUB Bytecode Assembly Example

code <- r"(
LDCONST 1
LDCONST 2
SUB
RETURN
)"

asm(code) |> eval()
[1] -1

9.116.2 Example R code producing SUB bytecode

x - y
GETVAR x
GETVAR y
SUB 
RETURN 

9.117 SUBASSIGN_N

Assignment into a subset of an object

Instruction summary
value
Name SUBASSIGN_N
Value 114
Number of Args 1
Has expr index TRUE
Stack Pop ?
Stack Push ?
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.117.1 Example R code producing SUBASSIGN_N bytecode

m[1,2,3] <- 1
LDCONST 1
@label2 
STARTASSIGN m
STARTSUBASSIGN_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBASSIGN_N @label2
@label1 
ENDASSIGN m
INVISIBLE 
RETURN 

9.118 SUBASSIGN2_N

Assignment into a subset of an object

Instruction summary
value
Name SUBASSIGN2_N
Value 115
Number of Args 1
Has expr index TRUE
Stack Pop ?
Stack Push ?
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.118.1 Example R code producing SUBASSIGN2_N bytecode

m[[1, 2, 3]] <- 1
LDCONST 1
@label2 
STARTASSIGN m
STARTSUBASSIGN2_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBASSIGN2_N @label2
@label1 
ENDASSIGN m
INVISIBLE 
RETURN 

9.119 SUBSET_N

Subset of an object

Instruction summary
value
Name SUBSET_N
Value 112
Number of Args 1
Has expr index TRUE
Stack Pop ?
Stack Push ?
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.119.1 Example R code producing SUBSET_N bytecode

m[1,2,3]
GETVAR m
@label2 
STARTSUBSET_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBSET_N @label2
@label1 
RETURN 

9.120 SUBSET2_N

Subset of an object

Instruction summary
value
Name SUBSET2_N
Value 113
Number of Args 1
Has expr index TRUE
Stack Pop ?
Stack Push ?
Argument summary
Argument Type Description
1 label Location of matching END* instruction

9.120.1 Example R code producing SUBSET2_N bytecode

m[[1,2,3]]
GETVAR m
@label2 
STARTSUBSET2_N @label1
LDCONST 1
LDCONST 2
LDCONST 3
SUBSET2_N @label2
@label1 
RETURN 

9.121 SWAP

Swap the top two items on the stack

Instruction summary
value
Name SWAP
Value 100
Number of Args 0
Has expr index FALSE
Stack Pop 2
Stack Push 2

9.121.1 SWAP Bytecode Assembly Example

code <- r"(
LDCONST "apple"
LDCONST "banana"
SWAP
RETURN
)"

asm(code) |> eval()
[1] "apple"

9.122 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:

  1. expridx
  2. A character vector of labels for the choices. This may be NULL
  3. A vector of labels matching the character vector. This may be NULL
  4. A vector of labels matching the locations to jump to if numeric argument is given as first argument to switch()

9.122.1 Note

There is not yet support for compiling this op in the {asmr} package.

Instruction summary
value
Name SWITCH
Value 102
Number of Args 3
Has expr index TRUE
Stack Pop 1
Stack Push 1
Argument summary
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

9.122.2 Example R code producing SWITCH bytecode

switch(x, 10, 20)
GETVAR x
SWITCH NULL; c("@label1", "@label2", "@label3")
@label3 
LDNULL 
INVISIBLE 
RETURN 
@label1 
LDCONST 10
RETURN 
@label2 
LDCONST 20
RETURN 

9.123 UMINUS

Unary minus

Instruction summary
value
Name UMINUS
Value 42
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 1

9.123.1 UMINUS Bytecode Assembly Example

code <- r"(
LDCONST 1
UMINUS
RETURN
)"

asm(code) |> eval()
[1] -1

9.123.2 Example R code producing UMINUS bytecode

-x + 1
GETVAR x
UMINUS 
LDCONST 1
ADD 
RETURN 

9.124 UPLUS

Unary plus

Instruction summary
value
Name UPLUS
Value 43
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 1

9.124.1 UPLUS Bytecode Assembly Example

code <- r"(
LDCONST 1
UPLUS
RETURN
)"

asm(code) |> eval()
[1] 1

9.124.2 Example R code producing UPLUS bytecode

+x + 1
GETVAR x
UPLUS 
LDCONST 1
ADD 
RETURN 

9.125 VECSUBASSIGN

End an assignment operation into the subset of a vector

Assignment must have been started with STARTSUBASSIGN_N instruction.

Instruction summary
value
Name VECSUBASSIGN
Value 86
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 0

9.125.1 Example R code producing VECSUBASSIGN bytecode

a[1] <- 2
LDCONST 2
STARTASSIGN a
STARTSUBASSIGN_N @label1
LDCONST 1
VECSUBASSIGN 
@label1 
ENDASSIGN a
INVISIBLE 
RETURN 

9.126 VECSUBASSIGN2

End an assignment operation into the subset of a vector

Assignment must have been started with STARTSUBASSIGN2_N instruction.

Instruction summary
value
Name VECSUBASSIGN2
Value 108
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 0

9.126.1 Example R code producing VECSUBASSIGN2 bytecode

a[[1]] <- 2
LDCONST 2
STARTASSIGN a
STARTSUBASSIGN2_N @label1
LDCONST 1
VECSUBASSIGN2 
@label1 
ENDASSIGN a
INVISIBLE 
RETURN 

9.127 VECSUBSET

Vector subset with []

This instruction marks the end of a set of instructions which start with STARTSUBSET_N

Instruction summary
value
Name VECSUBSET
Value 84
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 0

9.127.1 Example R code producing VECSUBSET bytecode

a[1]
GETVAR a
STARTSUBSET_N @label1
LDCONST 1
VECSUBSET 
@label1 
RETURN 

9.128 VECSUBSET2

Vector subset with [[]]

This instruction marks the end of a set of instructions which start with STARTSUBSET2_N

Instruction summary
value
Name VECSUBSET2
Value 106
Number of Args 0
Has expr index TRUE
Stack Pop 1
Stack Push 0

9.128.1 Example R code producing VECSUBSET2 bytecode

a[[1]]
GETVAR a
STARTSUBSET2_N @label1
LDCONST 1
VECSUBSET2 
@label1 
RETURN 

9.129 VISIBLE

Make an invisible object visible again.

There is no direct analogue of this op in R.

Instruction summary
value
Name VISIBLE
Value 94
Number of Args 0
Has expr index FALSE
Stack Pop 1
Stack Push 1

9.129.1 VISIBLE Bytecode Assembly Example

code <- r"(
LDCONST 1
INVISIBLE
VISIBLE
RETURN
)"

asm(code) |> eval()
[1] 1