Team LiB   Previous Section   Next Section

7.6 IMCC Quick Reference

This is a summary of PIR directives and instructions. Any PASM opcode is valid in PIR code, so you should also look at Section 6.9. For more details and the latest changes, see languages/imcc/docs/syntax.pod or dive into the source code in languages/imcc/imcc.l and languages/imcc/imcc.y.

7.6.1 Directives

.arg

.arg VAL

Push a value onto the user stack.

.const

.const TYPE NAME = VALUE

Define a named constant.

.constant

.constant NAME VALUE

Define a named macro that expands to a given value. Macros are called as directives, so .NAME (PASM code only).

.emit

.emit

Define a compilation unit of PASM code. Always paired with .eom.

.end

.end

End a compilation unit. Always paired with .sub.

.endm

.endm

End a macro definition. Always paired with .macro.

.endnamespace

.endnamespace NAME

End a namespace. Always paired with .namespace.

.eom

.eom

End a compilation unit of PASM code. Always paired with .emit.

.include

.include " FILENAME "

Include the contents of an external file by inserting it in place.

.local

.local TYPE NAME

Define a local named variable.

.macro

.macro NAME (PARAMS)

Define a named macro with a list of parameters. The macro is called as .NAME (arg1,arg2,...). Always paired with .endm. (PASM code only.)

.namespace

.namespace NAME

Define a namespace. Always paired with .endnamespace.

.param

.param DEST

.param TYPE NAME

Pop a value off the user stack into a register or typed identifier.

.result

.result DEST

Pop a value off the user stack.

.return

.return VAL

Return a value to the calling subroutine by pushing it onto the user stack.

.sub

.sub NAME

Define a compilation unit. Always paired with .end. Names begin with "_" by convention.

.sym

.sym TYPE NAME

Same as .local.

7.6.2 Instructions

=

DEST = VAL

Assign a value to a particular register, temporary register, or named variable.

+

DEST = VAL + VAL

Add two numbers or PMCs.

-

DEST = VAL1 - VAL2

DEST = - VAL

Subtract VAL1 from VAL2. The unary "-" negates a number.

*

DEST = VAL * VAL

Multiply two numbers or PMCs.

/

DEST = VAL1 / VAL2

Divide VAL1 by VAL2.

**

DEST = VAL1 ** VAL2

Raise VAL1 to the power of VAL2.

%

DEST = VAL1 % VAL2

Divide VAL1 by VAL2 and return the (mod) remainder.

.

DEST = VAL . VAL

Concatenate two strings.

<

if VAL1 < VAL2 goto LABEL

Conditionally branch to a label if VAL1 is less than VAL2.

<=

if VAL1 <= VAL2 goto LABEL

Conditionally branch to a label if VAL1 is less than or equal to VAL2.

>

if VAL1 > VAL2 goto LABEL

Conditionally branch to a label if VAL1 is greater than VAL2.

>=

if VAL1 >= VAL2 goto LABEL

Conditionally branch to a label if VAL1 is greater than or equal to VAL2.

= =

if VAL1 =  = VAL2 goto LABEL

Conditionally branch to a label if VAL1 is equal to VAL2.

!=

if VAL1 != VAL2 goto LABEL

Conditionally branch to a label if VAL1 is not equal to VAL2.

&&

DEST = VAL1 && VAL2

Logical AND. Return VAL1 if it's false, VAL2 if VAL1 is true.

||

DEST = VAL1 || VAL2

Logical OR. Return VAL1 if it's true, VAL2 if VAL1 is false.

~~

DEST = VAL1 ~~ VAL2

Logical XOR. Return VAL1 if it's true and VAL2 is false. Return VAL2 if VAL2 is true and VAL1 is false. Otherwise, return false.

!

DEST = ! VAL

Logical NOT. Return a true value if VAL is false.

&

DEST = VAL & VAL

Bitwise AND on two values.

|

DEST = VAL | VAL

Bitwise OR on two values.

~

DEST = VAL ~ VAL

DEST = ~ VAL

Bitwise XOR on two values. The unary form is a bitwise NOT on a value.

<<

DEST = VAL1 << VAL2

Bitwise shift VAL1 left by VAL2 number of bits.

>>

DEST = VAL1 >> VAL2

Bitwise shift VAL1 right by VAL2 number of bits.

>>>

DEST = VAL1 >>> VAL2

Logically shift VAL1 right by VAL2 number of bits.

[ ]

DEST = PMC [ KEY ]

PMC [ KEY ] = VAL

Indexed access to a PMC and indexed assignment to a PMC.

DEST = STRING [ OFFSET ]

STRING [ OFFSET ]  = VAL

Access a one-character substring on a string, starting at a particular offset, or assign to that substring.

addr

DEST = addr LABEL

Return the address of a label.

call

call NAME

Call the named subroutine (a .sub label).

clone

DEST = clone VAL

Create a clone of a variable.

defined

DEST = defined VAL

Test a value or keyed value for definedness.

global

DEST = global NAME

global NAME = VAL

Access a global for read or write.

goto

goto NAME

Jump to the named identifier (label or subroutine name).

if

if EXPR goto NAME

If the value or expression evaluates as true, jump to the named identifier.

new

DEST = new TYPE

Create a new PMC of type TYPE.

unless

unless VAL goto NAME

Unless the value evaluates as true, jump to the named identifier.

    Team LiB   Previous Section   Next Section