IMCC - syntax


0.1 initial


This document describes the IMCC syntax.


Comments and empty lines ^

Comments start with # and last until the following newline. These and empty lines are ignored.

Statements ^

A valid imcc program consists of a sequence of statements. A statement is terminated by a newline (<NL>).

General statement format ^

  [label:] [instruction] <NL>

Labels ^

Optional label for the given instruction, can stand on its own line. Global labels start with an underscore, local labels shouldn't. A label must conform to the syntax of identifier described below.


Terms used here ^


Start with a letter or underscore, then may contain additionally digits and ::.



int, float, string, pmc or a valid parrot PMC type like PerlArray.


A PASM register I0..I31, S0..S31, N0..N31, P0..P31, or a IMCC temporary register $In, $Sn, $Nn, $Pn, where n consists of digit(s) only. The parrot register P31 is reserved for spilling and should not be used in complex code sections, which might need spilling (see operation.pod).


A local identifier or a reg or a constant (when allowed).

Constants ^

"string constants"

Are delimited by ". A " inside a string must be escaped by \". Only 7-bit ASCII is accepted in string constants; to use characters outside thar range, specify an encoding in the way below.

charset:"string constant"

Like above with a chracter set attached to the string. Valid character sets are currently: ascii (the default), binary, unicode (with UTF-8 as the default encoding), and iso-8859-1.

charset:encoding:"string constant"

Like above with an extra encoding attached to the string. Currently unimplemented.

'char constant'

Are delimited by '. They are taken to be ascii encoded.

numeric constants

0x and 0b denote hex and binary constants.

Directive instructions ^

.sub <identifier>


Define a compilation unit with the label identifier:.



Define a compilation unit containing PASM code.

.local <type> <identifier>

.sym <type> <identifier>

Define a local name identifier for this compilation unit and of the given type. You can define multiple identifiers of the same type by separating them with commas: .sym int i, j

.const <type> <identifier> = <const>

Define a named constant of style type and value const.

.namespace <identifier>

.endnamespace <identifier>

Defines the range of a namespace. Local variables inside a namespace are mangled as <namespaceidentifier::varidentifier>.

.param <type> <identifier>

Like .local and generates PASM restore identifier.

.param <reg>

.result <var>

restore from stack.

.arg <var>

.return <var>

save on stack.


Directives used for Parrot Calling Conventions.

Instructions ^

Instructions may be a valid PASM instruction or anything listed here below:

call <identifier>

bsr <identifier>.

goto <identifier>

branch <identifier>.

if <var> goto <identifier>

unless <var> goto <identifier>

Translate to if x, identifier or unless ...

if <var> <relop> <var> goto <identifier>

The relop <, <=, ==, != >= > translate to the PASM opcodes lt, le, eq, ne, ge or gt var, var, identifier.

unless <var> <relop> <var> goto <identifier>

Like above, but branch if condition isn't met.

<var> = <var>

set var, var

<var> = <unary> <var>

The unarys !, - and ~ generate not, neg and bnot ops.

<var> = <var> <binary> <var>

The binarys +, -, *, /, % and ** generate add, sub, mul, div, mod and pow arithmetic ops. binary . is concat and valid for string arguments.

<< and >> are arithmetic shifts shl and shr. >>> is the logical shift lsr.

&&, || and ~~ are logic and, or and xor.

&, | and ~ are binary band, bor and bxor.

<var> = <var> [ <var> ]

This generates either a keyed set operation or substr var, var, var, 1 for string arguments and an integer key.

<var> [ <var> ] = <var>

A keyed set operation or the assign substr op with a length of 1.

<var> = new <type>

new var, .type

<var> = new <type>, <var>

new var, .type, var

<var> = defined <var>

defined var, var

<var> = defined <var> [ <var> ]

defined var, var[var] the keyed op.

global "string" = <var>

store_global "string", var

<var> = global "string"

find_global var, "string"

<var> = clone <var>

clone var, var

<var> = addr <var>

set_addr var, var


parsing.pod, calling_conventions.pod


imcc.l, imcc.y


Leopold Toetsch <>