Created: 21st December 2019

In second year at Imperial, there is a group project to make an implementation of an ARM compiler for a programming language called WACC. My group produced an implementation that met the specification, and provided additional features including object-oriented programming constructs, an optimising stage using an SSA-based intermediate representation and x86 architecture support.

Here’s an example program in WACC:

  bool neg(bool b) is
    return !b 
  bool b = true ;
  println b ;
  b = call neg(b) ;
  println b

Here’s how our support for classes looked like:

  class Owner {
    string name;
    Dog dog; 
    Dog[] dogs;

  class Dog {
    string name;
    bool hasBone;
    Owner owner;
    int uniqueCode;

    void changeOwner(Owner owner) is
      this.owner = owner

  class Havanese : Dog {
    string furColour;

    override void changeOwner(Owner owner) is
      Owner jack = newclass(Owner);
      jack.name = "Jack";
      this.owner = jack

  Owner owner = newclass(Owner);
  Owner newOwner = newclass(Owner);
  newOwner.name = "Steve";
  Dog dog = newclass(Dog);
  dog.owner = owner;
  owner.dog = dog;
  owner.name = "Bob";
  dog.hasBone = false;
  if !dog.hasBone then
    print dog.owner.name;
    println " is a bad owner";
    call dog.changeOwner(newOwner);
    print dog.owner.name;
    println " is the new good owner"

  Dog[] dogs = newarray(Dog, 3);
  for int i = 0; i < len dogs; i = i + 1 do
    dogs[i] = newclass(Dog);
    dogs[i].uniqueCode = i;
    call dogs[i].changeOwner(newOwner)
  dogs[0].name = "good boy 1";
  dogs[1].name = "good boy 2";
  dogs[2].name = "good boy 3";
  newOwner.dogs = dogs;
  for int j = 0; j < len newOwner.dogs; j = j + 1 do
    print newOwner.name;
    print " owns ";
    println newOwner.dogs[j].name

  Havanese boomer = newclass(Havanese);
  boomer.name = "Boomer";
  call boomer.changeOwner(null);
  print boomer.name;
  print " is owned by ";
  println boomer.owner.name