C--
This article needs additional citations for verification. (April 2016) |
weak | |
---|---|
Website | https://www.cs.tufts.edu/~nr/c--/index.html |
Influenced by | |
C |
C-- (pronounced C minus minus) is a
There are two main branches:
- C--, the original branch, with the final version 2.0 released in May 2005[3]
- Cmm, the fork actively used as the intermediate representation (IR) in the Glasgow Haskell Compiler (GHC)[4][5]
Design
C-- is a "portable assembly language",[citation needed] 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 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.)
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 optimization, 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,[1] accompanied by a January 1999 paper on garbage collection.[2] A revised manual was posted in HTML form in May 1999.[6] 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]
Type system
The C--
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
Example code
The following C-- code calculates the sum and product of integers 1 through n[7] (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.
/* Tail recursion */
export sp2;
sp2( bits32 n ) {
jump sp2_help( n, 1, 1 );
}
sp2_help( bits32 n, bits32 s, bits32 p ) {
if n==1 {
return( s, p );
} else {
jump sp2_help( n-1, s+n, p*n );
}
}
Implementations
The specification page of C-- lists a few implementations of C--. The "most actively developed" compiler, Quick C--, was abandoned in 2013.[8]
Haskell
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 the Cmm dialect which uses the C preprocessor for ergonomics.[4]
GHC backends are responsible for further transforming C-- into executable code, via LLVM IR, slow C, or directly through the built-in native backend.[9] 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.[10] Target-specific optimizations are performed later by the backend.
Processing systems
This article has been translated from the article C-- in the Japanese Wikipedia, and requires proofreading. (November 2023) |
As of 2023, most processing systems are not maintained, including release of the source code.
- Quick C-- is a compiler developed by The Quick C-- Team. Compiles C--version 2 C-code to Intel x86 Linux machine code. Compilation to machine code for other platforms is implemented as an experimental feature. Previously, Quick C-- was developed in parallel with the development of the C-language specification, but the source code is only stored on github and development is not continuing.
- cmmc is a C-compiler implemented in the ML language by Fermin Reig. Outputs Alpha/Sparc/X86 machine code.
- Trampoline C-- Compiler is a C--to-C transpiler developed by Sergei Egorov in May 1999.
- The Oregons Graduate Institutes C-- compiler (OGI C-- Compiler) is the earliest prototype C-- compiler implemented in the ML language in 1997. Since development of Quick C-- began, maintenance has not continued.
See also
References
- ^ a b Nordin, Thomas; Jones, Simon Peyton; Iglesias, Pablo Nogueira; Oliva, Dino (1998-04-23). "The C– Language Reference Manual".
{{cite journal}}
: Cite journal requires|journal=
(help) - ^ a b Reig, Fermin; Ramsey, Norman; Jones, Simon Peyton (1999-01-01). "C–: a portable assembly language that supports garbage collection": 1–28.
{{cite journal}}
: Cite journal requires|journal=
(help) - ^ a b c d Ramsey, Norman; Jones, Simon Peyton. "The C-- Language Specification, Version 2.0" (PDF). Retrieved 11 December 2019.
- ^ a b GHC Commentary: What the hell is a .cmm file?
- ^ "An improved LLVM backend". April 2019.
- ^ Nordin, Thomas; Jones, Simon Peyton; Iglesias, Pablo Nogueira; Oliva, Dino (1999-05-23). "The C– Language Reference Manual".
- ^ Ramsey, Norman; Jones, Simon Peyton; Lindig, Christian (2005-02-23), The C-- Language Specification, version 2.0 (CVS Revision 1.128) (PDF), p. 7, retrieved 2023-06-22
- ^ "C-- Downloads". www.cs.tufts.edu. Retrieved 11 December 2019.
- ^ GHC Backends
- ^ Debugging compilers with optimization fuel
External links
- Archive of old official website (cminusminus.org)
- Quick C-- code archive (the reference implementation)