Skip to content

Iris Compiler

Patrick Nelson edited this page Sep 9, 2015 · 3 revisions

Overview

"Iris" is a language that will look familiar to Pascal programmers. It has the following design goals:

  1. Expressive enough to write interesting programs.
  2. Language is imperative.
  3. Easy to integrate with the debugger as a sample.
  4. As simple as possible while achieving the above goals.

Disclaimers

Iris is not intended to be a production compiler and doesn't attempt to follow any standards. It also shouldn't be considered a 'best practice' example for implementing a .NET compiler.

Hello World

Learning any programming language starts with Hello World, so here is Hello World in Iris:

program HelloWorld;
begin
   writeln('Hello World');
end.

Here's a slightly more complicated program that prints the first 5 values in the Fibonacci sequence:

program Fibonacci;

function Fib(i:integer) : integer;
var
   a, b : integer;
begin
   Fib := 1;
   if i > 2 then
   begin
      a := Fib(i - 1);
      b := Fib(i - 2);
      Fib := a + b;
   end;
end

procedure Test(i:integer);
var
   result : integer;
begin
   result := Fib(i);
   writeln(str(result));
end;

begin
   Test(1);
   Test(2);
   Test(3);
   Test(4);
   Test(5);
end.

Compiler Design

Iris can be broken down into a Front End, Back End, and an Import System.

Iris Front End

The front end of the Iris compiler uses a recursive decent parser. For simplicity, the compiler only makes one pass over the source file. During parsing, the compiler does semantic analysis and outputs instructions and debug information via the Back End. The bulk of this code is in Translator.cs

Iris Back End

Iris allow interchanging back ends for emitting different types of code. Each back end is an implementation of IEmitter. There is an emitter for PE files and an emitter that writes out textual CIL code.

Import System

In order to integrate with the debugger, Iris must have the ability to import metadata into its symbol table. Iris uses System.Reflection.Metadata as the metadata reader and implements an intermediate type system to convert between the rich .NET type system and the compiler's very limited type system.

Command Line

The command line compiler for Iris is named "ic". It is built as part of Iris.sln in the Iris directory. To see the options for the compiler, run "ic" without any arguments. There is also a build.cmd file in the repo to build all ".iris" files in the Iris/Programs directory.

Clone this wiki locally