Parrot Reference: Chapter 11 - Perl 6 and Parrot Essentials
by Allison Randal, Dan Sugalski, Leopold TötschThis chapter contains a condensed list of PASM opcodes, PIR directives and instructions, and Parrot command-line options, sorted alphabetically for easy reference. Any PASM opcode is valid in PIR code, so if you're looking up PIR syntax, you should check Section 11.1, Section 11.2, and Section 11.3.
This excerpt is from Perl 6 and Parrot Essentials. This book is an unparalleled sneak-peek of what's coming in the widely-anticipated Perl 6. It uncovers groundbreaking new developments in Parrot--the interpreter engine that will execute code written in the new Perl 6 language and the most revolutionary change in the language itself--Apocalypse 12 on objects. It also includes expanded coverage of Apocalypse 5 (regular expressions) and Apocalypse 6 (subroutines).
For complete details on each
opcode and the latest changes, read the documentation in
docs/ops/, or look at all the
.ops files in the
ops/ 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 the
.ops files for the combinations
allowed with a particular operation.
This is a summary of PIR directives. Directives are preprocessed by the Parrot interpreter. Since PIR and PASM run on the same interpreter, many of the directives listed here are also valid in PASM code.
This section is a quick reference
to PIR instructions. For more details and the latest changes, see
imcc/docs/syntax.pod or dive into the
source code in imcc/imcc.l and
imcc/imcc.y.
Since Parrot is both an assembler
and a bytecode interpreter, it has options to control both
behaviors. Some options may have changed by the time you read this,
especially options related to debugging and optimization. The
document imcc/docs/running.pod should
have the latest details. Or just run parrot
—help.
parrot [options]file[arguments]
The file is either an
.imc (.pir) or .pasm
source file or a Parrot bytecode file. Parrot creates an
Array object to hold the command-line
arguments and stores it
in P5 on program start.
-a, --pasm-
Assume PASM input on
stdin. When Parrot runs a source file with a.pasmextension, it parses the file as pure PASM code. This switch turns on PASM parsing (instead of the default PIR parsing) when a source file is read fromstdin. -c,--pbc-
Assume PBC file on
stdin. When Parrot runs a bytecode file with a.pbcextension, it immediately executes the file. This option tells Parrot to immediately execute a bytecode file piped in onstdin. -d,--debug [hexbits]-
Turn on debugging output. The
-dswitch takes an optional argument, which is a hex value of debug bits. (The individual bits are shown in Table 11-3.) Whenhexbitsisn't specified, the default debugging level is 0001. Ifhexbitsis separated from the-dswitch by whitespace, it has to start with a number.Table 11-3. Debug bits
Description
Debug bit
DEBUG_PARROT
0001
DEBUG_LEXER
0002
DEBUG_PARSER
0004
DEBUG_IMC
0008
DEBUG_CFG
0010
DEBUG_OPT1
0020
DEBUG_OPT2
0040
DEBUG_PBC
1000
DEBUG_PBC_CONST
2000
DEBUG_PBC_FIXUP
4000
To produce a huge output on
stderr, turn on all the debugging bits:$ parrot -d 0ffff . . .
- --help-debug
-
Show debug option bits.
-h,--help-
Print a short summary of options to
stdoutand exit. -ooutputfile-
Act like an assembler. With this switch, Parrot won't run code unless it's combined with the
-rswitch. If the name ofoutputfileends with a.pbcextension, Parrot writes a Parrot bytecode file. Ifoutputfileends with a.pasmextension, Parrot writes a PASM source file, even if the input file was also PASM. This can be handy to check various optimizations when you run Parrot with the-Opswitch.If the extension is
.oor equivalent, Parrot generates an object file from the JITed program code, which can be used to create a standalone executable program. This isn't available on all platforms yet; seePLATFORMSfor which platforms support this. -r,--run-pbc-
Immediately execute bytecode. This is the default unless
-ois present. The combination of-r-ooutput.pbcwrites a bytecode file and executes the generated PBC. -v,--verbose-
One
-vswitch (imcc-v) shows which files are worked on and prints a summary of register usage and optimization statistics. Two-vswitches (imcc-v-v) also prints a line for each individual processing step. -y,--yydebug-
Turn on
yydebugforyacc/bison. -E,--pre-process-only-
Show output of macro expansions and quit.
-V,--version-
Print the program version to
stdoutand exit. -Ox-
Turn on optimizations. The flags currently implemented are shown in Table 11-4.
Table 11-4. Optimizations
Flag
Meaning
-O0No optimization (default).
-O1Optimizations without life info (e.g., branches and constants).
-O2Optimizations with life info.
-OcOptimize function call sequence.
-OpRearrange PASM registers with the most-used first.
The interpreter options are mainly for selecting which run-time core to use for interpreting bytecode. The current default is the computed goto core if it's available. Otherwise, the fast core is used.
-b,--bounds-checks-
Activate bounds checking. This also runs with the slow core as a side effect.
-f,--fast-core-
Run with the fast core.
-g,--computed-goto-core-
Run the computed goto core (CGoto).
-j,--jit-core-
Run with the JIT core if available.
-p,--profile-
Activate profiling. This prints a summary of opcode usage and execution times after the program stops. It also runs within the slow core.
-C,--CGP-core-
Run with the CGoto-Prederefed core.
-P,--predereferenced-core-
Run with the Prederefed core.
-S,--switched-core-
Run with the Switched core.
-t,--trace-
Trace execution. This also turns on the slow core.
-w,--warnings-
Turn on warnings.
-G,--no-gc-
Turn off DOD/GC. This is for debugging only.
-.,--wait-
Wait for a keypress before running.
- --leak-test,--destroy-at-end
-
Clean up allocated memory when the final interpreter is destroyed. Parrot destroys created interpreters (e.g., threads) on exit but doesn't normally free all memory for the last terminating interpreter, since the operating system will do this anyway. This can create false positives when Parrot is run with a memory leak detector. To prevent this, use this option.
-
If you enjoyed this excerpt, buy a copy of Perl 6 and Parrot Essentials
