Team LiB   Previous Section   Next Section

6.9 PASM Quick Reference

This is a condensed list of PASM opcodes, sorted alphabetically for easy reference. For complete details on each opcode and the latest changes, read docs/core_ops.pod, or look at all the .ops files in the main Parrot source directory. We've followed a few conventions. DEST is always the register where the result of the operation is stored. Sometimes the original value of DEST is one of the source values. VAL indicates that the actual value might be a literal integer, float, or string, or a register containing an integer, float, string, or PMC. See core.ops for the combinations allowed with a particular operation.

abs

abs DEST
abs DEST, VAL

Return the absolute value of a number. If VAL is left out, DEST gets the absolute value of itself.

acos

acos DEST, VAL

The arc cosine of VAL in radians.

add

add DEST, VAL
add DEST, VAL, VAL

Add two values and return the sum. If only one VAL, add VAL to DEST.

and

and DEST, VAL1, VAL2

Logical AND. Return VAL1 if it's false, VAL2 if VAL1 is true.

asin

asin DEST, VAL

The arc sine of VAL in radians.

asec

asec DEST, VAL

The arc secant of VAL in radians.

assign

assign DEST, VAL

Assign a value to a PMC.

atan

atan DEST, VAL
atan DEST, VAL1, VAL2

The arc tangent of VAL1 / VAL2 in radians (sign significant). If no VAL2, the arc tangent of VAL.

band

band DEST, VAL
band DEST, VAL, VAL

Bitwise AND on two values. If only one VAL, bitwise AND on DEST and VAL.

bnot

bnot DEST, VAL

Bitwise NOT on VAL.

bor

bor DEST, VAL, VAL

Bitwise OR on two values. If only one VAL, bitwise OR on DEST and VAL.

bounds

bounds INT

Toggle bytecode bounds checking in the interpreter (0 for off, 1 for on).

branch

branch LABEL

Branch to a label. The label is calculated as a relative offset.

branch_cs

branch_cs FIXUP_ENTRY

Intersegment branch to the location of the given fixup table entry.

bsr

bsr LABEL

Branch to a label, like branch, but also push the current location onto the call stack so ret can return to it.

bxor

bxor DEST, VAL
bxor DEST, VAL, VAL

Bitwise XOR on two values. If only one VAL, bitwise XOR on DEST and VAL.

chopn

chopn DEST, VAL1
chopn DEST, VAL1, VAL2

Remove VAL2 number of characters from string VAL1. If no VAL2, remove VAL number of characters from string DEST.

chr

chr DEST, INT

Return the character represented by the given number.

clearX

cleari
clearn
clearp
clears

Clear all registers of the given type ("i" = integer, "n" = float, "p" = PMC, "s" = string).

clone

clone DEST, VAL

Clone (deep copy) a string or PMC and return the result.

close

close DEST

Close the filehandle in the given register.

cmod

cmod DEST, VAL1, VAL2

C's built-in mod operator.

See also mod.

collect

collect

Trigger a garbage collection (GC) run.

collectoff

collectoff

Disable garbage collection runs (nestable).

collecton

collecton

Re-enable garbage collection runs.

compile

compile DEST, COMPILER, SOURCE

Compile a string of source code with a given compiler PMC and store the result.

compreg

compreg DEST, TYPE

Return a compiler PMC for a particular type of source code.

concat

concat DEST, VAL
concat DEST, VAL, VAL

Concatenate two strings. If only one VAL, concatenate VAL onto DEST.

cos

cos DEST, VAL

The cosine of VAL in radians.

cosh

cosh DEST, VAL

The hyperbolic cosine of VAL in radians.

debug

debug INT

Toggle debugging in the interpreter (0 for off, 1 for on).

dec

dec DEST

Decrement a value by 1.

defined

defined DEST, PMC
defined DEST, PMC[KEY]

Test a keyed PMC value for definedness. If no KEY, test a PMC for definedness.

delete

delete DEST[KEY]

Delete a keyed value from an aggregate PMC.

delprop

delprop PMC, NAME

Delete a named property from a PMC.

See also setprop and getprop.

depth

depth DEST

Return the depth of the user stack.

div

div DEST, VAL
div DEST, VAL1, VAL2

Divide VAL1 by VAL2. If VAL2 is left out, divide DEST by VAL.

dlfunc

dlfunc DEST, LIBRARY, SYMBOL, SIGNATURE

Look up a symbol in a dynamic link library PMC and create a subroutine PMC for that symbol with the given signature.

end

end

End execution within the current code segment or halt the interpreter if in the main code segment.

entrytype

entrytype DEST, INT

Return the type of an entry in the user stack, by position in the stack.

eq

eq VAL, VAL, LABEL

Jump to a label if the two values are equal.

err

err DEST

Return the system error code (INT) or message (STR).

exchange

exchange REG, REG

Exchange the contents of two registers.

exists

exists DEST, PMC[KEY]

Test a PMC key for existence.

exp

exp DEST, VAL

Base of the natural logarithm, e, to the power of VAL.

exsec

exsec DEST, VAL

The exsecant of VAL in radians.

fact

fact DEST, INT

Return the factorial of INT.

find_lex

find_lex DEST, NAME
find_lex DEST, DEPTH, NAME
find_lex DEST, DEPTH, POSITION

Return the lexical variable of the given name from a lexical scratchpad. If DEPTH is provided, only return a variable from the scratchpad at that depth. A find by position returns the variable at a particular position in the scratchpad.

See also store_lex.

find_global

find_global DEST, NAME

Return a global variable with the given name.

See also store_global.

find_method

find_method DEST, PMC, NAME

Look up a method by name in a PMC's vtable. Return a method PMC.

find_type

find_type DEST, NAME

Find the enum value for a PMC type or native Parrot datatype by name.

See also typeof.

getfile

getfile DEST

Return the name of the current file.

getline

getline DEST

Return the current line number.

getpackage

getpackage DEST

Return the current package name.

getprop

getprop DEST, NAME, PMC

Return the value of a named property on a PMC.

See also setprop and prophash.

gcd

gcd DEST, VAL, VAL

Return the greatest common divisor of two values.

gc_debug

gc_debug INT

Toggle garbage collection debugging in the interpreter (0 for off, 1 for on).

ge

ge VAL1, VAL2, LABEL

Jump to a label if VAL1 is greater than or equal to VAL2.

gt

gt VAL1, VAL2, LABEL

Jump to a label if VAL1 is greater than VAL2.

hav

hav DEST, VAL

The haversine of VAL in radians.

if

if CONDITION, LABEL

Jump to a label if the condition is a true value.

index

index DEST, STRING, SEARCH
index DEST, STRING, SEARCH, POS

Return the position of the first occurrence of SEARCH string in STRING, starting at POS. If the POS is unspecified, start at the beginning of the string.

inc

inc DEST

Increment a value by one.

intdepth

intdepth DEST

Return the depth of the integer stack.

interpinfo

interpinfo DEST, FLAG

Return information about the interpreter. An integer flag selects which information to return, as listed in Table 6-7.

Table 6-7. Interpinfo flags

Flag

Returns

1

Allocated memory, in bytes.

2

Number of DOD sweeps performed.

3

Number of GC runs performed.

4

Number of active PMCs.

5

Number of active buffers.

6

Number of allocated PMCs.

7

Number of allocated buffers.

8

Number of new PMC or buffer headers allocated since last DOD run.

9

Number of memory blocks allocated since last GC run.

10

Amount of memory copied during GC runs, in bytes.

intrestore

intrestore DEST

Restore a register from the integer stack.

intsave

intsave VAL

Save a value onto the integer stack.

invoke

invoke
invoke PMC

Call a subroutine, coroutine, or continuation stored in a PMC. If no PMC register is specified, it calls the subroutine in P0 and uses the standard calling conventions. Otherwise, no calling convention is defined. Also yield from a coroutine.

jump

jump ADDRESS

Jump to a specified absolute address.

See also set_addr.

jsr

jsr ADDRESS

Jump to an address, like jump, but also push the current location onto the call stack so ret can return to it.

lcm

lcm DEST, VAL, VAL

Return the least common multiple of two values.

le

le VAL1, VAL2, LABEL

Jump to a label if VAL1 is less than or equal to VAL2.

length

length DEST, STRING

Return the character length of a string.

ln

ln DEST, VAL

The natural logarithm of VAL.

loadlib

loadlib DEST, LIBRARY

Load a dynamic link library by name and store it in a PMC.

See also dlfunc.

log2

log2 DEST, VAL

The base 2 logarithm of VAL.

log10

log10 DEST, VAL

The base 10 logarithm of VAL.

lookback

lookback DEST, OFFSET

Retrieve an entry from the user stack by position. A positive offset counts from the top of the stack; a negative offset counts from the bottom.

lsr

lsr DEST, VAL, BITS

Logically shift a value right by a given number of bits.

lt

lt VAL1, VAL2, LABEL

Jump to a label if VAL1 is less than VAL2.

mul

mul DEST, VAL
mul DEST, VAL, VAL

Multiply two values and return the result. If only one VAL, multiply DEST by VAL.

mod

mod DEST, VAL
mod DEST, VAL1, VAL2

Divide VAL1 by VAL2 and return the remainder. If VAL2 is left off, divide DEST by VAL. The operation is defined as:

x mod y = x - y * floor(x / y)
ne

ne VAL, VAL, LABEL

Jump to a label if the two values are not equal.

neg

neg DEST
neg DEST, VAL

Return the negative of a number. If there is no VAL, DEST is the negative of itself.

new

new DEST, TYPE
new DEST, TYPE, INITIALIZE

Create a new PMC of type TYPE. INITIALIZE is an array PMC of initialization data for the new PMC.

new_pad

new_pad DEPTH
new_pad DEST, DEPTH

Create a new lexical scope pad. If a destination PMC is provided, store the pad in the PMC, otherwise push it onto the lexical scope stack. DEPTH specifies the static nesting depth for the pad (lower static depths are copied from the current static nesting).

newinterp

newinterp DEST, FLAGS

Create a new interpreter and store it in a PMC.

See also runinterp.

noop

noop

Do nothing.

not

not DEST, VAL

Logical NOT. True if VAL is false.

open

open DEST, FILENAME, MODE

Open a file in the specified mode ("<", ">", etc.) and return a filehandle.

or

or DEST, VAL1, VAL2

Logical OR. Return VAL1 if it's true, VAL2 if VAL1 is false.

ord

ord DEST, STRING
ord DEST, STRING, POS

Return the character at position POS in STRING. If POS isn't specified, return the 0th character.

peek_pad

peek_pad DEST

Store the current lexical scope pad in a PMC.

pop

pop DEST, PMC

Pop the last entry off an aggregate PMC and return it.

pop_pad

pop_pad

Pop the current lexical scope pad off the lexical scope stack.

See also peek_pad.

popX

popi
popn
popp
pops

Restore all the registers of one type from the stack ("i" = integer, "n" = float, "p" = PMC, "s" = string).

See also pushX.

pow

pow DEST, VAL1, VAL2

Return VAL1 raised to the power of VAL2.

print

print VAL
print IO, VAL

Print a value to an I/O object or file descriptor. If no IO is given, print the value to standard output.

printerr

printerr STR

Print a string to stderr.

profile

profile INT

Toggle profiling in the interpreter (0 for off, 1 for on).

prophash

prophash DEST, PMC

Return a hash containing all the properties from a PMC.

See also getprop.

push

push PMC, VAL

Push a value onto the end of an aggregate PMC.

push_pad

push_pad PAD

Push a scratchpad stored in a PMC onto the lexical scope stack.

pushX

pushi
pushn
pushp
pushs

Save all the registers of one type to the stack ("i" = integer, "n" = float, "p" = PMC, "s" = string). Restore with popX.

puts

puts VAL

Print a value to stdout.

read

read DEST, BYTES
read DEST, IO, BYTES

Read the specified number of bytes from a Parrot I/O object. Read from stdin if no IO is provided.

repeat

repeat DEST, VAL, REPEAT

Repeat a string REPEAT number of times.

restore

restore DEST

Restore a register from the user stack.

restoreall

restoreall

Restore all the registers. Does a popX for every type.

ret

ret

Go to the location on the top of the call stack (also pop it off the stack). Often used with bsr and jsr.

rotate_up

rotate_up COUNT

Rotate the top COUNT entries on the user stack. A positive number rotates up: the top entry becomes the COUNTth entry, and the others move up one (the second entry becomes first, the third becomes the second, etc.). A negative number rotates down: the COUNTth entry becomes the top, and the others move down (the first becomes second, etc.).

runinterp

runinterp PMC, OFFSET

Use an interpreter stored in PMC to run code starting at a given offset.

See also newinterp.

save

save VAL

Save a value onto the user stack.

saveall

saveall

Save all the registers. Does a pushX for every type.

savec

savec VAL

Save a clone of a value onto the user stack.

sec

sec DEST, VAL

The secant of VAL in radians.

sech

sech DEST, VAL

The hyperbolic secant of VAL in radians.

seek

seek DEST, IO, OFFSET, STARTFLAG
seek DEST, IO, UPPER32, LOWER32, STARTFLAG

Set the file position of a Parrot I/O object to a given offset from a starting position (STARTFLAG: 0 is the beginning of the file, 1 is current the position, 2 is the end of the file). DEST is the success or failure of the seek.

64-bit seek combines UPPER32 and LOWER32 to get one 64-bit OFFSET.

set

set DEST, VAL

Set a register to a value.

set DEST[KEY], VAL

A keyed set operation on a PMC.

set DEST, PMC[KEY]

A keyed get operation on a PMC.

set_addr

set_addr DEST, LABEL

Return the current address plus the offset to LABEL. Often used to calculate absolute addresses for jump or jsr.

setprop

setprop PMC, NAME, VALUE

Set the value of a named property on a PMC.

See also getprop and delprop.

shift

shift DEST, PMC

Shift a value off the front of an aggregate PMC.

shl

shl DEST, VAL, BITS

Bitwise shift a value left by a given number of bits.

shr

shr DEST, VAL, BITS

Bitwise shift a value right by a given number of bits.

sin

sin DEST, VAL

The sine of VAL in radians.

sleep

sleep SECONDS

Sleep for the given number of seconds.

splice

splice DEST, REPLACE, OFFSET, COUNT

Starting at OFFSET, replace COUNT number of values in the destination PMC with values provided in the REPLACE PMC.

sprintf

sprintf DEST, FORMAT, ARGS

Format arguments in an aggregate PMC, using format string FORMAT.

store_lex

store_lex NAME, OBJECT
store_lex DEPTH, NAME, OBJECT
store_lex DEPTH, POSITION, OBJECT

Store an object as a lexical variable with a given name. If the symbol doesn't exist, it will be created in the lexical scratchpad at the specified depth (a negative depth counts back from the current scope). If DEPTH isn't provided, the symbol must already exist. If a position is provided instead of a name, the symbol will be stored at the given position in the scratchpad.

See also find_lex.

store_global

store_global NAME, OBJECT

Store a global variable as a named symbol.

See also find_global.

stringinfo

stringinfo DEST, STRING, FLAG

Return information about a string. An integer flag selects which information to return, as listed in Table 6-8.

Table 6-8. Stringinfo arguments

Flag

Returns

1

Location of string buffer header.

2

Location of start of string memory.

3

Allocated length, in bytes.

4

String flags.

5

Used length of string buffer, in bytes.

6

String length, in characters.

sub

sub DEST, VAL
sub DEST, VAL1, VAL2

Subtract VAL2 from VAL1. If no VAL2, subtract VAL from DEST.

substr

substr DEST, STRING, OFFSET, LENGTH
substr DEST, STRING, OFFSET, LENGTH, REPLACE 
substr DEST, OFFSET, LENGTH, REPLACE

Return a substring of a string. If REPLACE is given, also replace substring in STRING. If STRING is left out, replace substring in DEST.

sweep

sweep

Trigger a dead object detection (DOD) sweep.

sweepoff

sweepoff

Disable DOD sweeps (nestable).

sweepon

sweepon

Re-enable DOD sweeps.

tan

tan DEST, VAL

The tangent of VAL in radians.

tanh

tanh DEST, VAL

The hyperbolic tangent of VAL in radians.

time

time DEST

Return the current system time.

trace

trace INT

Toggle tracing in the interpreter (0 for off, 1 for on).

typeof

typeof DEST, VAL

Return the type of a PMC or Parrot data type, either class name (to a string destination) or enum value (to an integer destination).

unless

unless CONDITION, LABEL

Jump to a label unless the condition is a true value.

unshift

unshift PMC, VAL

Unshift a value onto the front of an aggregate PMC.

valid_type

valid_type DEST, TYPE

Check whether a PMC type or native Parrot datatype is a valid one.

vers

vers DEST, VAL

The versine of VAL in radians.

warningsoff

warningsoff CATEGORY

Turn off a particular category of warnings: 1 = undef, 2 = IO, -1 = all.

warningson

warningson CATEGORY

Turn on a particular category of warnings: 1 = undef, 2 = IO, -1 = all.

xor

xor DEST, VAL1, VAL2

Logical XOR. Return VAL1 if it's true and VAL2 is false. Return VAL2 if VAL2 is true and VAL1 is false. Otherwise, return false.

    Team LiB   Previous Section   Next Section