parrotcode: parsing | |
Contents | IMCC |
IMCC - parsing
This document describes the basic parsing functionality of IMCC, the current compiler for Parrot Intermediate Representation (PIR).
Note: some information in this file is out of date. Please refer to the PIR PDD (pdd19_pir.pod).
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.
{{ Is this true? one sub calling another not-yet compiled sub would not work in that case. }}
See pdd19_pir.pod for an overview of PIR syntax.
This code:
.sub name
statements
...
.end
Defines a subroutine with the entry point _name
, using the Parrot calling conventions. See docs/calling_conventions.pod for more details.
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 get_{hll,root}_global opcodes.
Global labels and constants are kept in the global symbol table ghash
. This allows for global constant folding beyond the scope of individual subroutines.
This also means that you currently can't use the same global symbol (e.g. subroutine name) in different namespaces. The following creates invalid code:
.sub main
...
.end
.namespace ["main"]
.sub main
...
.end
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 docs/pdds/draft/pdd19_pir.pod
imcc.y, instructions.c, t/compilers/imcc/syn/sub.t, t/compilers/imcc/imcpasm/sub.t, t/compilers/imcc/syn/scope.t
Leopold Toetsch <lt@toetsch.at>
|