C-- (conventionally written using hyphen-minuses but pronounced C minus minus) is a C-like programming language, designed to be generated mainly by compilers for high-level languages rather than written by human programmers. It was created by functional programming researchers Simon Peyton Jones and Norman Ramsey. Unlike many other intermediate languages, it is represented in plain ASCII text, not bytecode or another binary format. designed to ease the implementation of compilers that produce high-quality machine code. This is done by delegating low-level code-generation and program optimization to a C-- compiler. The language's syntax borrows heavily from C while omitting or changing standard C features such as variadic functions, pointer syntax, and aspects of C's type system, because they are considered to hamper essential features of C-- and ease of code-generation.

The name of the language is an in-joke, indicating that C-- is intended to be a reduced form of C, in the same way that "C++" was chosen to connote an improved version of C. (In C, <code>--</code> and <code>++</code> mean "decrement" and "increment", respectively.)

Work on C-- began in the late 1990s. Since writing a custom code generator is a challenge in itself, and the compiler backends available to researchers at that time were complex and poorly documented, several projects had written compilers which generated C code (for instance, the original Modula-3 compiler). However, C has various downsides for functional languages: it does not guarantee tail-call optimization, or support accurate garbage collection or efficient exception handling. C-- is intended as a supposedly tightly defined simpler alternative to C which supports all of these. Its most innovative feature is a run-time interface which allows writing of portable garbage collectors, exception handling systems and other run-time features which work with any C-- compiler.

The first version of C-- was released in April 1998 as a MSRA paper,

(n is received as an argument).

It demonstrates two language features:

  • Procedures can return multiple results.
  • Tail recursion is explicitly requested with the "jump" keyword.

<syntaxhighlight lang="cpp">

/* Tail recursion */

export sp;

sp(bits32 n) {

jump sp_help(n, 1, 1);

}

sp_help(bits32 n, bits32 s, bits32 p) {

if n == 1 {

return(s, p);

} else {

jump sp_help(n - 1, s + n, p * n);

}

}

</syntaxhighlight>

Implementations

The specification page of C-- lists a few implementations of C--. The "most actively developed" compiler, Quick C--, was abandoned in 2013.

GHC backends are responsible for further transforming C-- into executable code, via LLVM IR, slow C, or directly through the built-in native backend. Despite the original intention, GHC does perform many of its generic optimizations on C--. As with other compiler IRs, the C-- representation can be dumped for debugging.

  • Trampoline C-- Compiler is a C-- to C transpiler developed by Sergei Egorov in May 1999. It translates C-- code into C code, allowing it to be compiled using standard C compilers.
  • The Oregon Graduate Institute's C-- compiler (OGI C-- Compiler) is the earliest prototype C-- compiler, developed in 1997 using the ML programming language. Maintenance of the OGI C-- Compiler was discontinued once development of Quick C-- began.

See also

  • BCPL
  • LLVM
  • C Intermediate Language

References

  • Archive of old official website (cminusminus.org)
  • Quick C-- code archive (the reference implementation)