This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "C--" – news ·newspapers ·books ·scholar ·JSTOR(April 2016) (Learn how and when to remove this message) |
![]() Unofficial logo for C-- which closely resembles theC++ logo | |
Paradigm | imperative |
---|---|
Designed by | Simon Peyton Jones andNorman Ramsey |
First appeared | 1998 |
Typing discipline | static,weak |
Website | www |
Influenced by | |
C |
C-- (pronouncedC minus minus) is aC-likeprogramming language, designed to be generated mainly bycompilers forhigh-level languages rather than written by human programmers. It was created byfunctional programming researchersSimon Peyton Jones and Norman Ramsey. Unlike many other intermediate languages, it is represented in plainASCII text, notbytecode or anotherbinary format.[1][2]
There are two main branches:
C-- is a "portableassembly language",[6] designed to ease the implementation of compilers that produce high-qualitymachine code.[7] This is done by delegating low-levelcode-generation andprogram optimization to a C-- compiler. The language'ssyntax borrows heavily from C while omitting or changing standard C features such asvariadic functions,pointer syntax, and aspects of C's type system, because they hamper essential features of C-- and ease of code-generation.
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.)[8]
Work on C-- began in the late 1990s. Since writing a customcode generator is a challenge in itself, and the compilerbackends available to researchers at that time were complex and poorly documented, several projects had written compilers which generated C code (for instance, the originalModula-3 compiler). However, C is a poor choice for functional languages: it does not guaranteetail-call optimization, or support accurategarbage collection or efficientexception 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,[1] accompanied by a January 1999 paper on garbage collection.[2] A revised manual was posted in HTML form in May 1999.[9] 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.[3]
The C--type system is designed to reflect constraints imposed by hardware rather than conventions imposed by higher-level languages. A value stored in a register or memory may have only one type:bit-vector. However, bit-vector is apolymorphic type which comes in several widths, e.g.bits8,bits32, orbits64. A separate 32-or-64 bit family of floating-point types is supported. In addition to the bit-vector type, C-- provides a boolean typebool, which can be computed by expressions and used for control flow but cannot be stored in a register or memory. As in an assembly language, any higher type discipline, such as distinctions between signed, unsigned, float, and pointer, is imposed by the C-- operators or other syntactic constructs. C-- is not type-checked, nor does it enforce or check the calling convention.[3]: 28
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.[3]: 10
The following C-- code calculates the sum and product of integers 1 through n[10](n is received as an argument).It demonstrates two language features:
/* Tail recursion */exportsp;sp(bits32n){jumpsp_help(n,1,1);}sp_help(bits32n,bits32s,bits32p){ifn==1{return(s,p);}else{jumpsp_help(n-1,s+n,p*n);}}
The specification page of C-- lists a few implementations of C--. The "most actively developed" compiler, Quick C--, was abandoned in 2013.[11]
Some developers of C--, including Simon Peyton Jones, João Dias, and Norman Ramsey, work or have worked on GHC, whose development has led to extensions in the C-- language, forming theCmm dialect which uses theC preprocessor for ergonomics.[4][12]
GHC backends are responsible for further transforming C-- into executable code, viaLLVM IR, slow C, or directly through the built-in native backend.[13][14][15] 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.[16] Target-specific optimizations are performed later by the backend.
As of 2018, most processing systems are not maintained, nor is their source code released.