core.ops - Core Opcodes


Parrot's core library of ops.

Core operations are primarily flow control and interpreter introspection.

When making changes to any ops file, run make bootstrap-ops to regenerate all generated ops files.

Basic ops

These are the fundamental operations. Please note: These opcodes must not be moved; they must have exactly these opcode numbers. Opcodes ending with underscores are for internal use only; don't emit these opcodes.

Halts the current interpreter. See also exit.Note that a user-defined method currently creates its own interpreter, so end inside a method is like a return without any context. This is unspecified behaviour. Currently it is replaced by the returncc op.
Does nothing other than waste an iota of time and 32 bits of bytecode space.
Check the event queue and run event handlers if there are unhandled events. Note: This opcode is mainly for testing. It should not be necessary to ever use it explicitly.
Check the event queue and run event handlers if there are unhandled events. Note: Do not use this opcode. It is for internal use only.
load_bytecode(in STR)
Load Parrot bytecode from file $1, and search the library path to locate the file. Automatically triggers :load functions if the file found is a .pbc. If it is a .pir or a .pasm, the file is compiled first and the :init subs are triggered instead. Nothing is returned.
load_bytecode(out PMC, in STR)
Load Parrot bytecode from file $2, searching the library path to locate the file. Returns a new PackfileView in $1. Does not perform any automatic initialization. Use the PackfileView PMC interface to introspect and perform actions on it.
load_language(in STR)
Load the compiler libraries for a language $1. Search the library path to locate the main compiler file in the standard locations.

Control flow

The control flow opcodes check conditions and manage program flow.

branch(in LABEL)
Branch forward or backward by the amount in $1.
local_branch(invar PMC, in LABEL)
Go to the location specified by the label in $2. Push the current location onto the stack passed in $1 for later returning.
local_return(invar PMC)
Pop the location off the top of the call stack and go there.
jump(in LABEL)
Jump to the address held in register $1.

Conditional branch operations

These operations perform a conditional relative branch. If the condition is met, the branch happens. Otherwise control falls to the next operation.

if(invar INT, inconst LABEL)
if(invar NUM, inconst LABEL)
if(invar PMC, inconst LABEL)
if(invar STR, inconst LABEL)
Check register $1. If true, branch by $2.
unless(invar INT, inconst LABEL)
unless(invar NUM, inconst LABEL)
unless(invar PMC, inconst LABEL)
unless(invar STR, inconst LABEL)
Check register $1. If false, branch by $2.

Subroutine operations

These operations are used to generate and call subroutines and continuations.

invokecc(invar PMC)
Call the subroutine in $1 and generate a new return continuation, if needed. For example, a NCI subroutine which executes code in some C library will not create a continuation, nor will anything but the first call to a coroutine.
invoke(invar PMC, invar PMC)
Call the subroutine in $1 and use continuation $2.
Yield results from a coroutine.
tailcall(invar PMC)
Call the subroutine in $1 and use the current continuation as the subs continuation.
Return from the sub or method via the current continuation.
capture_lex(invar PMC)
Capture the current lexical state of the inner subroutine PMC.
newclosure(out PMC, invar PMC)
Create a closure of the given subroutine PMC by cloning the sub's state.

Function argument opcode

Implementations of function argument and params handling

set_args(inconst PMC /* , ... */)
Define arguments for the next function call.
get_results(inconst PMC /* , ... */)
Define return values for the next function call.
get_params(inconst PMC /* , ... */)
Define function parameters for this subroutine.
set_returns(inconst PMC /* , ... */)
Define return results for the subroutine return statement.For all of these opcodes the passed invar PMC constant is the string representation of a FixedIntegerArray with one flag word per argument. The flags are documented currently in include/parrot/enums.h only.After this argument a variable amount of arguments must follow according to the elements of the signature array.
set_result_info(in PMC)
Set result_info. See also result_info.
result_info(out PMC)
Returns the get_results signature PMC of the caller. This PMC is a FixedIntegerPMCArray. The number of elements of this PMC is equal to the number of return values that are expected. The individual bits per entry are specified in docs/pdds/pdd03_calling_conventions.pod.

Address manipulation

set_addr(out INT, inconst LABEL)
Sets register $1 to the current address plus the offset $2.
set_addr(invar PMC, inconst LABEL)
Sets PMC in register $1 to the current address plus the offset $2.
set_addr(invar PMC, invar LABEL)
Sets PMC in register $1 to the absolute address $2 obtained from get_addr.
get_addr(out INT, invar PMC)
Sets $1 to the absolute address of the Sub PMC $2.

Concurrency operations

schedule(invar PMC)
Register a task with the concurrency scheduler. Details about the task are stored within the task PMC.
schedule_local(invar PMC)
Like schedule but execute it on the current thread.
addhandler(invar PMC)
Add an event or exception handler to the concurrency scheduler. Details about the handler are stored within the handler PMC.

Exception handling

push_eh(inconst LABEL)
Create an exception handler for the given catch label and push it onto the exception handler stack.
push_eh(invar PMC)
Push an invokable PMC onto the exception handler stack.
Pop the most recently placed exception off the handler stack.
throw(invar PMC)
Throw the exception in $1 with current continuation.
throw(invar PMC, invar PMC)
Throw the exception in $1 with continuation from $2.
rethrow(invar PMC)
Only valid inside an exception handler. Rethrow the exception $1.
count_eh(out INT)
Get a count of currently active exception handlers on the stack.
die(in STR)
die(in PMC)
Die with message $1
die(in INT, in INT)
Die with severity $1 and error $2. If severity is .EXCEPT_DOOMED, call _exit($2). The latter isn't catchable.
exit(in INT)
Exit the interpreter with exit_status $1. If you want to communicate an extended exit status, create an exception with severity EXCEPT_exit and throw it.
finalize(in PMC)
Finalize exception handling, freeing any information needed to resume the handled exception, like inner runloops. $1 is the Exception handled or the ExceptionHandler that is handling it.
pop_upto_eh(in PMC)
Pops all exception handlers upto the one indicated by $1. Like with the finalize op, $1 can either be the handled Exception or the ExceptionHandler handling it. Also, you should not resume Exceptions after pop_upto_eh or finalize has been called. This limitation may be fixed in a future version of parrot. Also note that the specified exception handler is not popped.
peek_exception(out PMC)
Returns the caught exception without clearing the call object. This is currently needed because HLL authors use get_params to fetch the exception, but get_params clears the call object. So we can't use get_params in PCT to get the exception object without disturbing the HLL code. This op will be removed again when PCT offers another mechansim to get the exception and the HLLs switched to it.

Interpreter operations

These operations inspect or modify the interpreter itself, possibly affecting its subsequent operation.

debug(in INT)
If $1 is zero, turn off debugging. Otherwise turn debug flag $1 on.
bounds(in INT)
If $1 is zero, turn off byte code bounds checking. Otherwise turn it on.
profile(in INT)
If $1 is zero, turn off profiling. Otherwise turn it on.
trace(in INT)
If $1 is zero, turn off tracing. Otherwise turn trace flag $1 on.
gc_debug(in INT)
If $1 is zero, turn off GC_DEBUG. Otherwise turn it on.
Fetch some piece of information about the interpreter and put it in $1. Possible values for $2 are defined in runtime/parrot/include/interpinfo.pasm. The valid constants for each return value are (excluding the .INTERPINFO_ prefix):
interpinfo(out INT, in INT)
interpinfo(out PMC, in INT)
interpinfo(out STR, in INT)
warningson(in INT)
Turns on warnings categories. Categories already turned on will stay on. Initial setting is currently all warnings off. Include warnings.pasm to access the categories. Refer to that file for the current list of warnings available.To turn on multiple categories, OR the category numbers together.
warningsoff(in INT)
Turns off warnings categories. Categories already turned off will stay off. See the documentation for warningson for category numbers.
errorson(in INT)
Turns on error categories. Categories already turned on will stay on. To access these from PASM, include errors.pasm. The current categories are:
When performing arithmetic on Integer PMCs, throw a math overflow exception instead of promoting to BigInt. This flag does not pertain to native integers, which are never promoted. Default: off.
Throw an exception on an argument versus parameter count mismatch. Default: on.
Throw an exception on a return versus result count mismatch. Default: off.
To turn on multiple categories, OR the category numbers together.
errorsoff(in INT)
Turns off errors categories. Categories already turned off will stay off. See the documentation for errorson for category numbers.
set_runcore(in STR)
Switch the current runcore to the one with the specified name. Needs to be an op, as we need to restart the runops() call. You can get the name of the current runcore with the interpinfo op.
runinterp(invar PMC, in LABEL)
Run the code starting at offset $2 within interpreter $1.
getinterp(out PMC)
Get the current ParrotInterpreter.

Garbage Collection

Opcodes that interact with the GC subsystem.

sweep(inconst INT)
Triggers a GC run, based on the value of $1, where:
  • Trigger a GC run only if there are things that have flagged themselves as really needing to be collected.
  • 1
  • Trigger a GC run unconditionally.

Trigger a garbage collection.
Disable GC runs. (Nestable)
Re-enable GC runs.
Disable GC runs (nestable).
Re-enable GC.
needs_destroy(invar PMC)
Mark the PMC wanting destruction as soon as possible, for example when unused during the lazy sweep, triggered by sweep 0.

Native Call Interface

Opcodes for interfacing with C functions in shared libraries.

loadlib(out PMC, in STR)
loadlib(out PMC, in STR, in PMC)
Load a dynamic link library named $2 and store it in $1. $3, if provided, controls library loading and initialization; currently, we expect a bitmask accessible as an integer. Bit definitions are accessible from PASM if dlopenflags.pasm is included. The current bits are:
Make any symbols in the library accessible to other libraries loaded.
dlfunc(out PMC, invar PMC, in STR, in STR)
dlfunc(out PMC, invar PMC, in STR, invar PMC)
Look up symbol $3 in library $2 with signature $4, and put the corresponding sub object in $1. Note that you need the signature so we can build or find an appropriate thunking function.
dlvar(out PMC, invar PMC, in STR)
Look up symbol $3 in library $2. We assume that this is actually a variable address rather than a function address, and build an UnManagedStruct PMC and stick the address into its data pointer.
compreg(out PMC, in STR)
Get the compiler object for source type $2. The returned compiler object should provide a compile method for translating code in the source type. However, some Parrot compilers such as PIR and PASM currently return a sub that is to be invoked directly on the source.
compreg(in STR, invar PMC)
Register $2 as the compiler object for source type $1.
new_callback(out PMC, invar PMC, invar PMC, in STR)
Create a callback stub $1 for PASM subroutine $2 with userdata $3 and callback function signature $4. Only 2 argument signatures with signature chars U[1iscpt] or [1iscpt]U are handled currently. But these cover a lot of callback signatures. Please note that the userdata PMC U has to be handled transparently by the caller of the callback function.

Annotations operations

These operations relate to bytecode annotations.

annotations(out PMC)
Gets all bytecode annotations in effect at the current point, in a Hash. If there are none, returns an empty Hash.
annotations(out PMC, in STR)
Gets the bytecode annotation with the given name that is in effect at the current point. Returns PMCNULL if there is none.


This program is free software. It is subject to the same license as the Parrot interpreter itself.