core.ops - Parrot Core Ops
Parrot's core library of ops.
Core operations are primarily flow control and interpreter introspection.
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.
- end()
- Halts the interpreter.
(Must be op #0,
CORE_OPS_end).
See also exit.
- noop()
- Does nothing other than waste an iota of time and 32 bits of bytecode space.
(Must be op #1,
CORE_OPS_noop)
- cpu_ret()
- Emit a cpu return instruction.
This is used to return from CGP core to JIT code.
Note: Do not use this opcode.
It is for internal use only.
(Must be op #2,
CORE_OPS_cpu_ret)
- check_events()
- 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.
(Must be op #3,
CORE_OPS_check_events).
- check_events__()
- 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.
(Must be op #4,
CORE_OPS_check_events__).
- wrapper__()
- Internal opcode to wrap unknown ops from loaded opcode libs.
Don't use.
(Must be op #5,
CORE_OPS_wrapper__).
- prederef__()
- Internal opcode to prederef opcodes on the fly.
Don't use.
(Must be op #6,
CORE_OPS_prederef__ ).
- reserved(inconst INT)
- Reserve 1 more fix entry.
- load_bytecode(in STR)
- Load Parrot bytecode from file $1,
and (TODO) search the library path,
to locate the file.
The control flow opcodes check conditions and manage program flow.
- branch(label INT)
- Branch forward or backward by the amount in $1.
- branch_cs(in STR)
- Intersegment branch to location in fixup table named $1.
- bsr(label INT)
- Branch to the location specified by $1.
Push the current location onto the call stack for later returning.
- ret()
- Pop the location off the top of the call stack and go there.
- jsr(label INT)
- Jump to the location specified by register $1.
Push the current location onto the call stack for later returning.
- jump(label INT)
- Jump to the address held in register $1.
- enternative()
- Internal opcode used to jump from normal bytecode into a JITted version.
These operations perform a conditional relative branch.
If the condition is met,
the branch happens,
otherwise control falls to the next operation.
- if(in INT,
labelconst INT)
- if(in NUM,
labelconst INT)
- if(in PMC,
labelconst INT)
- if(in STR,
labelconst INT)
- Check register $1.
If true,
branch by $2.
- unless(in INT,
labelconst INT)
- unless(in NUM,
labelconst INT)
- unless(in PMC,
labelconst INT)
- unless(in STR,
labelconst INT)
- Check register $1.
If false,
branch by $2.
These operations are used to generate and call subroutines and continuations.
- invoke()
- Call the subroutine in P0,
with Parrot calling convention as described in PDD03.
- invoke(in PMC)
- Call the subroutine in $1 with no defined calling convention or invoke a continuation for returning from a subroutine.
- invokecc()
- Call the subroutine in P0 and generate a new return continuation in P1.
- invokecc(in PMC)
- Call the subroutine in $1 and generate a new return continuation in P1.
- tailcall(in PMC)
- Call the subroutine in $1 and use the current continuation as the subs continuation.
- updatecc()
- Update the state of the return continuation in P1.
This is necessary,
when any context stuff was changed between creating the return continuation and invoke'ing it.
- returncc()
- Return from the sub or method via the current continuation.
- set_addr(out INT,
labelconst INT)
- Sets register $1 to the current address plus the offset $2.
- set_addr(in PMC,
labelconst INT)
- Sets PMC in register $1 to the current address plus the offset $2.
- set_addr(in PMC,
labelvar INT)
- Sets PMC in register $1 to the absolute address $2 obtained from get_addr.
- get_addr(out INT,
in PMC)
- Sets $1 to the absolute address of the Sub PMC $2.
- newsub(out PMC,
in INT,
labelconst INT)
- Generate a new subroutine object in $1 of class $2 and label $3.
- newsub(in INT,
in INT,
labelconst INT,
labelconst INT)
- Generate a new subroutine object in P0 of class $1 subroutine label $3 and a return continuation in P1 of class $2 and return address $4.
- push_eh(labelconst INT)
- Create an exception handler for the given catch label and push it onto the control stack.
- clear_eh()
- Clear out the most recently placed exception.
- throw(in PMC)
- Throw the exception in $1.
- rethrow(in PMC)
- Only valid inside an exception handler.
Rethrow the exception $1.
- die_hard(in INT,
in INT)
- Die with severity $1 and error $2.
- 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.
- pushmark(in INT)
- Push a mark labeled $1 onto the control stack.
- popmark(in INT)
- Pop all items off the control stack to the given mark.
- pushaction(in PMC)
- Push the given Sub PMC $1 onto the control stack.
If the control stack is unwound due to a
popmark
,
subroutine return,
or an exception,
the subroutine will be invoked.
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.
- interpinfo(out INT,
in INT)
- interpinfo(out PMC,
in INT)
- interpinfo(out STR,
in INT)
- 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.
- warningson(in INT)
- Turns on warnings categories.
Categories already turned on will stay on.
Initial setting is currently all warnings off.
Current categories are (include "warnings.pasm"):
- .PARROT_WARNINGS_UNDEF_FLAG
- .PARROT_WARNINGS_IO_FLAG
- .PARROT_WARNINGS_PLATFORM_FLAG
- .PARROT_WARNINGS_ALL_FLAG
- 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.
Current default setting is PARROT_ERRORS_GLOBALS_FLAG is on.
Current categories are (include "errors.pasm"):
- .PARROT_ERRORS_GLOBALS_FLAG
- Throw an exception,
if global doesn't exist.
- .PARROT_ERRORS_ALL_FLAG
- 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.
- runinterp(in PMC,
label INT)
- Run the code starting at offset $2 within interpreter $1.
- getinterp(out PMC)
- Get the current ParrotInterpreter.
- setline(in INT)
- Set the line number for which we're currently executing code.
- getline(out INT)
- Get the current line number.
- setfile(in STR)
- Set the name of the file for which we're currently executing code.
- getfile(out STR)
- Get the name of the current file.
- setpackage(in STR)
- Set the name of the package for which we're currently executing code.
- getpackage(out STR)
- Get the name of the current package.
Opcodes that interact with the DOD and GC subsystems.
- sweep(inconst INT)
- 0 ...
Trigger a DOD run only if there are things that have flagged themselves as really needing to be collected.
1 ...
Trigger a dead object detection (DOD) sweep unconditionally.
- collect()
- Trigger a garbage collection.
- sweepoff()
- Disable DOD sweeps.
(Nestable)
- sweepon()
- Re-enable DOD sweeps.
- collectoff()
- Disable GC runs (nestable).
- collecton()
- Re-enable GC.
- needs_destroy(in PMC)
- Mark the PMC wanting destruction as soon as possible,
i.e.
when unused during the lazy sweep,
triggered by "sweep 0".
Opcodes for handling function parameters,
validating parameters,
type and prototype checking,
and generic whatnots.
- foldup(out PMC)
- Take all the PMCs passed in as parameters and stick them into an Array PMC in $1.
Note: foldup only works for PMC arguments.
- foldup(out PMC,
in INT)
- Take all the PMCs passed in as parameters,
starting at offset $2 and stick them into an Array PMC in $1.
Note: foldup only works for PMC arguments.
Opcodes for interfacing with C functions in shared libraries.
- loadlib(out PMC,
in STR)
- Load a dynamic link library named $2 and store it in $1.
- dlfunc(out PMC,
in PMC,
in STR,
in STR)
- 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,
in 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.
- compile(out PMC,
in PMC,
in STR)
- Compile source code $3 with compiler $2 into PMC $1.
The compile opcode is just a fancy function call without the overhead of setting branch flags.
Thus the compiler PMC $2 can be a plain function returning a subroutine or a NCI PMC that wraps a compiler implemented in C.
The result has to be some invocable PMC.
- compreg(out PMC,
in STR)
- Get a compiler for source type $2.
- compreg(in STR,
in PMC)
- Register the sub $2 as a compiler for source type $1.
$2 is either a NCI PMC with signature "pIt" or a PASM Sub.
- new_callback(out PMC,
in PMC,
in PMC,
in STR)
- Create a callback stub $1 for PASM subroutine $2 with userdata $3 and function signature $4.
Copyright (C) 2001-2004 The Perl Foundation.
All rights reserved.
This program is free software.
It is subject to the same license as the Parrot interpreter itself.