parrotcode: parsing | |
Contents | IMCC |
IMCC - parsing
This document describes the basic parsing functionality of IMCC.
IMCC parses and generates code in terms of compilation units. These are self-contained blocks of code very similar to subroutines.
Code for a compilation unit is created as soon (or not earlier) as the end of the unit is reached.
program: subs
subs: statements ...
Comments start with #
, which may appear at any point on a line, and end at the end of the line.
Everything enclosed in POD markers is ignored.
=some_pod_marker in col 1
...
=cut
A POD section starts with a = in column 1 and ends with a =cut on a line on its own.
This code:
.sub name
statements
...
.end
defines a subroutine with the entry point _name
. Subroutine entry points have to start with an underscore (as do all other global labels). The statements in the subroutine must be valid PIR or PASM.
.sub name
statements
...
.end
As above, but using the Parrot calling conventions. See docs/calling_conventions.pod for more details.
This code:
.emit
_sub1:
pasm_statements
...
ret
...
.eom
defines a compilation unit containing PASM statements only. Typical usage is for language initialization and builtins code.
Any code appearing outside of a compilation unit will be ignored (if not now, then in the near future).
Nested subroutines are deprecated and will be removed in the near future.
Compilation units maintain their own symbol table containing local labels and variable symbols. This symbol table, hash
, is not visible to code in different units.
If you need global variables, please use the global opcode.
Global labels and constants are kept in the global symbol table ghash
. This allows for global constant folding beyond the scope of individual subroutines.
Local labels in different compilation units with the same name are allowed, though assembling the generated PASM doesn't work. However, running this code inside imcc is ok. This will probably change in the future so that local labels are mangled to be unique.
docs/calling_conventions.pod
imcc.y, instructions.c, t/syn/sub.t, t/imcpasm/sub.t, t/syn/scope.t
Leopold Toetsch <lt@toetsch.at>
|