C-- (pronounced C minus minus) is a C-like programming language, designed to be generated mainly by 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 data format.
There are two main branches:
The name of the language is an in-joke, indicating that C-- is a reduced form of C, in the same way that "C++" was chosen to connote an improved version of C. (In C, -- and ++ 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 is a poor choice for functional languages: it does not guarantee tail call, or support accurate garbage collection or efficient exception handling. C-- is a 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, accompanied by a January 1999 paper on garbage collection. A revised manual was posted in HTML form in May 1999. Two sets of major changes proposed in 2000 by Norman Ramsey ("Proposed Changes") and Christian Lindig ("A New Grammar") led to C-- version 2, which was finalized around 2004 and officially released in 2005.
C-- version 2 removes the distinction between bit-vector and floating-point types. These types can be annotated with a string "kind" tag to distinguish, among other things, a variable's integer vs float typing and its storage behavior (global or local). The former is useful on targets that have separate registers for integer and floating-point values. Special types for pointers and the native word were introduced, although they are mapped to a bit-vector with a target-dependent length.
sp_help(bits32 n, bits32 s, bits32 p) {
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. Target-specific optimizations are performed later by the backend.
Type system
Example code
jump sp_help(n, 1, 1);
}
if n == 1 {
return(s, p);
} else {
jump sp_help(n - 1, s + n, p * n);
}
}
Implementations
Haskell
Processing systems
See also
External links
|
|