IMCC - parsing


0.1 initial

0.2 lexicals

0.3 pod markers

0.4 deprecate nested subs and code outside compilation units


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.

General imcc syntax ^

        program: subs

        subs: statements ...

Comments ^

Comment start with # and end at line end.


Everything enclosed in POD markers is ignored.

        =some_pod_marker in col 1

A POD starts with a = in columns 1 and ends with =cut on its own line.

Compilation units ^

Subroutines .sub ... .end ^

        .sub _name

defines a subroutine with the entry point _name. Subroutine entry points (as all global labels) have to start with an underscore. The statements may contain valid PIR or PASM statements.

Subroutines .pcc_sub ... .end ^

        .pcc_sub _name

Like above with parrot calling conventions. Subroutines according to Parrot Calling Conventions (PCC) are described in docs/calling_conventions.pod.

Assembly blocks .emit ... .eom ^


defines a compilation unit containing PASM statements only. Typical usage is for language initialization and builtins code.

Code outside compilation units ^

Anything outside compilation units will be ignored in the near future.

Nested subs ^

Nested subroutines are deprecated and will be removed as well.

Symbols, constants and labels ^

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 subroutine scope.

Local labels in different compilation units with the same name are allowed, though assembling the generated PASM doesn't work. Running this code inside imcc is ok. This will probably change so that local labels are mangled to be unique.




imcc.y, instructions.c, t/syn/sub.t, t/imcpasm/sub.t, t/syn/scope.t


Leopold Toetsch <>