teaser

C!

C! (“C-bang”) is a programming language designed with system programming in mind and more specifically kernel programming.

C! is greatly inspired by C, but its syntax differs in a few key points in order to suppress a few ambiguities. Moreover it extends C with constructs which aims at simplifying system programming, such as syntactic sugar for often used constructs. C! also adds object-oriented features.

C! use a compiler-to-compiler model. It does not generate machine code directly. Instead it produces C99 code using a few GNU extensions (eg. for inline assembly) which should be easily compiled using GCC or clang. It enables us to focus on the frontend, and leaves machine code optimisation to tools that are proven reliable.

C! is a few key points:

  • Rationalised syntax
  • Simplified interactions with C
  • Integer size is explicit
  • Usage of integers as bit tables
  • Basic namespace support
  • Classes and objects
  • Macro classes: Add operations on types using an object syntax
  • Many more ideas not yet implemented

A simple C! syntax example:

// A simple fibonacci function in C!

// int<+32> indicates unsigned 32bits integer
fibo(n : int<+32>) : int<+32>
{
  if (n < 2)
    return n;
  return fibo(n-1) + fibo(n-2);
}

Ad now with objects:

// Import some external module "lib"
import lib;

class Point
{
  x : float<64>; // size also for float
  y : float<64>;

  getX(): float<64> { return x; }
  getY(): float<64> { return y; }

  setX(z : float<64>) { x = z; }
  setY(z : float<64>) { y = z; }
} // no ';' required !

addPoint(a: Point, b: Point) : Point
{
  // allocation is left to the programmer
  p : Point = Point(lib::alloc(sizeof(Point)));
  // lib::alloc designates the symbol alloc in the lib namespace
  p.setX(a.getX() + b.getX());
  p.setY(a.getX() + b.getX());
  return p;
}