7 ms·
C--
- vezzy-fnord 13y agoThis is pretty old. I don't know if anyone else besides the GHC team use it?
- VLM 13y agoI think its part of the quaint appeal of the article, that c-- only supports i386 but the way the world moved did not require c--, FSF supported GCC supports something like 50 archs and many more not officially FSF supported. And GCC is hardly the only c compiler out there. The world just didn't move in the direction directly requiring c--. Now as for current ideas and projects similar in concept to c--, that is interesting to think about. Maybe the startup lesson is sometimes, if you try to intermediate yourself as a middleman, even if you do a good job of it, and appear to be a good idea, it just doesn't work. It would be interesting to dissect the c-- experience and figure out why.
- _delirium 13y agoGCC did already exist when the C-- project was started, so that part didn't really change. The C-- team's hypothesis was that some kinds of languages (especially functional languages) would benefit from a cross-platform layer that is a better compilation target than C, partly through being a bit more low-level. The previous two popular routes were native-code compilers and compile-via-C compilers. Native-code compilers have the disadvantage that porting them and maintaining them on N architectures is significant work, and compile-via-C compilers have the disadvantage that C isn't a very convenient compilation target for many language features, especially to efficiently compile some common FP language features. The hope was that C-- would be a nice middle ground between compiling via C and compiling to native code, producing a target that was nicer than C as a target. Imo, that hypothesis did have some legs, but people are now instead usually using LLVM in various ways to accomplish it. LLVM's intermediate representation isn't really properly cross-platform, but it can be sort of hacked to be used for that purpose.
- mattgreenrocks 13y agoDo you think LLVM IR covers this ground adequately, despite not being cross-platform?
- _delirium 13y agoI'm not really a language implementor, more of a spectator of language implementations, so someone with more experience would give a better answer. My impression is that the GHC people, at least, still think that C-- is a nicer IR than LLVM-IR for their purposes. But they are slowly moving more things to LLVM anyway, because the LLVM project as a project has, in the meantime, built up a lot more momentum and infrastructure. In the early 2000s this wasn't obvious, but in 2013 it's clear that LLVM has an ecosystem, institutional support, resources to maintain ports, etc., while C-- didn't manage to get the same traction.
- thinkmoore 13y agoFrom my personal experience, LLVM is tied a bit to closely to the C ABI, which makes it difficult to implement some FP features cleanly. One example is forgoing C's stack discipline to implement double-barreled continuations.
- elehack 13y agoOCaml also internally uses an intermediate code representation called C-- (or Cmm). I do not know if the two have any relationship.
- deleted 13y ago[deleted]
- _delirium 13y agoIt looks like OCaml's C-- predates this C--, but has had an influence on it. From Xavier Leroy, one of the lead Ocaml developers [1]: I think I'm the one who coined the name "C--" to refer to a low-level, weakly-typed intermediate code with operations corresponding roughly to machine instructions, and minimal support for exact garbage collection and exceptions. See my POPL 1992 paper describing the experimental Gallium compiler. Such an intermediate code is still in use in the ocamlopt compiler. I had many interesting discussions with Simon PJ and Norman Ramsey when they started to design their intermediate language. Simon liked the name "C--" and kindly asked permission to re-use the name. However, C-- is more general than the intermediate code used by ocamlopt, since it is designed to accommodate the needs of many source languages, and present a clean, abstract interface to the GC and run-time system. The ocamlopt intermediate code is somewhat specialized for the needs of Caml and for the particular GC we use. [1] http://article.gmane.org/gmane.comp.lang.caml.inria/9436/ http://article.gmane.org/gmane.comp.lang.caml.inria/9436/
- Radim 13y agoThe originality (and practicality!) of choosing the name "C - -" leaves me speechless.
- nrnrnr 13y agoActually, it turned out to be totally impractical: you can't register the domain c--.org, and you can't usefully Google for "C--". Live and learn.
- blueblob 13y agoI felt the same way about "C++" postincrement, returns C. This seems more like it should be a predecrement (--C) because it does not return C, rather assembly. EDIT: changed, I said decrement and meant increment.
- _delirium 13y agoPredecrement is fairly unidiomatic in C, much less commonly used than in C++. Typically it's only really used if you're doing something tricky that actually depends on the semantics of predecrementing, usually in an array reference of the x[--i] variety. It's idiomatic in C++ I'd guess because of operator overloading: postdecrement/postincrement may produce large unused object copies that not all compilers will optimize away, so using the pre- versions by default has become idiomatic in that community.
- robert_tweed 13y agoIt's actually pretty idiomatic in optimised C, for the same sort of reason (when all extra instructions count), e.g., this sort of loop: for( i=LEN-1; i>=0; --i ) {...} I've carried this into a lot of other languages, as it's equally readable to the alternatives, when ordering isn't important. In (mainly older) optimised code where ordering is important, you'll often still see this, with a second incrementing variable so that the exit condition retains the compare to zero (avoiding a variable comparison); although that part is separate from the use of the pre-decrement. I'm not sure if either of these make much difference with modern CPUs and compilers. Certainly not worth worrying about for the most part. It's untrue that this idiom started with C++. This style is preferred by K&R, which predates optimising compilers. Since then it's use among C programmers has probably been force of habit, but it is definitely idiomatic. It's use in K&R makes it about as idiomatic as it is possible to be.
- sambeau 13y agoAccording to this, C-- is still a large part of the Glasgow Haskell Compiler. It looks like (Fig 5.2) code goes into C-- before being translated to LLVM. http://www.aosabook.org/en/ghc.html http://www.aosabook.org/en/ghc.html
- gngeal 13y agoUh, I believe that the GHC C-- (Cmm) is one of the dozen different C--es that have nothing in common with this project save for the name.
- ibdknox 13y agoGiven that Simon Peyton Jones is listed as a co-author on several of the papers, I find that a bit too coincidental to be true.
- gngeal 13y agoThis thing is written in ML, not in Haskell, and the GHC docs themselves claim that Cmm (the GHC thingy) is "is rather like C--. The syntax is almost C-- (a few constructs are missing), and it is augmented with some macros that are expanded by GHC's code generator". So "GHC's Cmm/C--" sounds rather like an independent reimplementation of a superset of a subset of "this C--".
- asdasf 13y agoIt literally can't be an "independent reimplementation" if one person played a major role in both of them.
- vanderZwan 13y agoDomain specific dialect?
- carterschonwald 13y agoThe GHC C-- is a subset of the full Norman Ramsey C--
- mrcactu5 13y agothis seems really awesome, but I have no idea what it does? I know that Python compiles to C and that Clojure compiles to JVM (or even to JavaScript). My cartoon: scripting lang --> programming lang --> native code Honestly, I have never experimented with Assembly language much except for COOL (http://en.wikipedia.org/wiki/Cool_(programming_language) http://en.wikipedia.org/wiki/Cool_(programming_language)) and TOY (http://introcs.cs.princeton.edu/java/52toy/ http://introcs.cs.princeton.edu/java/52toy/).
- JulianWasTaken 13y agoPython does not compile to C. In CPython, it compiles to VM bytecode for a VM written in C (analogous to Closure compiling to JVM bytecode).
- elehack 13y agoPython does not compile to C (well, there might be such a compiler, but it is not the standard mode of operation). In CPython, Python compiles to bytecode, which is then interpreted by the Python interpreter (which itself is written in C).
- gsnedders 13y agoRPython, the Python subset that PyPy is written in, is compiled to C. (That said, it is a fairly restrictive subset, and the compiler is very much designed for interpreters and nothing else.)
- tel 13y agoWhen compiling a language you have to compile it "to" somewhere. You could pick assembly, but assembly is so low level that it changes bit by bit depending on the processor. You want a stable target that's "low level" enough to let you optimize things for the machine you'll be working with, but not so low level as to be a moving target. You could pick C, but C is actually still fairly complex and has lots of undefined behavior. You could pick JVM, but then you'll pick up the entirety of the JVM architecture which is quite large and may include many things you're not interested in. C-- is another choice. It's decidedly lower-level than C (and thus far lower than JVM), higher level than assembly, and was crafted, as far as I know, under the deep influence of how to compile the pure functional language Haskell (or more specifically, it's System FC style and STG underlying languages). In the mean time, LLVM took a similar place in this hierarchy and has probably taken off much more than C-- has. GHC, a Haskell compiler, in fact is moving its compilation pathway that way.
- m_mueller 13y agoCould someone enlighten me what's the advantage of this over LLVM-IR? Edit: Ok, I've found the following SO thread: http://stackoverflow.com/questions/3891513/how-does-c-compare-to-llvm http://stackoverflow.com/questions/3891513/how-does-c-compar...
- _delirium 13y agoIf you want to know why it exists despite LLVM-IR existing, one answer is that at the time C-- was launched, LLVM-IR didn't yet exist. As for how they compare, the answers to this question, on why Haskell didn't use LLVM (in 2009, it didn't) get into it a bit: http://stackoverflow.com/questions/815998/llvm-vs-c-how-can-llvm-fundamentally-not-be-better-for-haskell-than-c http://stackoverflow.com/questions/815998/llvm-vs-c-how-can-...
- rayiner 13y agoC-- is intended for higher-level languages than LLVM. E.g. the latter still doesn't have a modern infrastructure interfacing with garbage collectors. Also, C-- is a lot easier to read in textual form than LLVM IR. Finally, the use of C++ and templates makes the code size of LLVM absolutely enormous (20MB binary). That said, so much work goes into LLVM supporting new platforms, optimizations, etc, that it's probably easier to hack around LLVM's limitations than use C--, etc.
- gngeal 13y agoYou probably don't need LLVM to work with LLVM-IR. In fact, I imagine that there could be a market for a "low-level" IR with more compact implementation, sort of similar to Oberon "slim binaries" or something like that. The fact remains, though, that the "pragmatics" stuff around LLVM-IR (GC and other interfaces) seems still a little bit problematic. But I'm a Luddite, though; I like self-hosting native compilers and I'm not terribly fond of the idea of having to pack a 20MB blob of C++ code with my code either. (There's a lot of apps that could profit from dynamic translation at run-time, but using LLVM for that feels unnecessarily heavyweight. I wish the algorithms and passes from LLVM were available in form of some high-level DSL that you'd be able to translate into whatever language you use and automatically adapt to whatever data structures you use in your code. It doesn't sound exactly impossible.)
- peapicker 13y agoWhen I first entered college in 1988 there was a small DOS compiler floating around called C-- back then, which I got from some BBS (yes, a BBS, how antiquated!), probably in 1989. It was a mix of a subset of C and proto-assembly. I have looked for it a few times over the years, and this one isn't it, although it has some similar ideas. It makes me wonder how many other little-known C-- projects there are.
- dragonbonheur 13y agoIt was Sphinx C-- http://www.cs.utexas.edu/users/tbone/c--/ http://www.cs.utexas.edu/users/tbone/c--/
- dpcan 13y agoYES! That's the one I was thinking about too. I remember making some simple games in this as a kid and I learned a lot of assembly using this at the time also because, if I recall, you actually referenced registers and such right in with your other code - or something strange like that.
- peapicker 13y agoThank you, thank you, thank you!
- henderson101 13y agoWow - I used this one too (vividly remember the "fire" effect demo) and have looked for it a few times to no avail. Nice find :-)
- secoif 13y agoAccording to this infographic, a C-- was the influence for JavaScript. http://www.georgehernandez.com/h/xComputers/Programming/Media/tongues-cleaner.png http://www.georgehernandez.com/h/xComputers/Programming/Medi... If this has any truth (perhaps a different c--?) I'd like to know which one is being referred to.
- saljam 13y agoThat's almost certainly a different one. It's described as a scripting language and that it appeared in 92. This C-- only came around 97... It's quite an obvious name, I'd expect there to be many more called C--!
- etherealG 13y agoit mentions c-- as a scripting language, i'd guess they're different things.
- masklinn 13y ago> perhaps a different c--? Yes, the graph talks about http://sourceforge.net/projects/cmmscript/ http://sourceforge.net/projects/cmmscript/ not the C-- used in/extracted from GHC. There's at least one other C-- used in the OCaml compiler.
- brent_noorda 13y agoThat must me the Cmm we did in the early 90s. That engine became the basis for (probably) most JavaScript uses up until 10 years ago. I wrote too much about it here: http://www.brent-noorda.com/nombas/history/HistoryOfNombas.html http://www.brent-noorda.com/nombas/history/HistoryOfNombas.h...
- davebees 13y agoIs the 'minus minus' being converted into a dash throughout?
- tel 13y agoI saw it in a few places, but often it was typeset C - -
- Dewie 13y agoSay you're writing a compiler for a language in Haskell, and you want to generate machine code rather than having it be interpreted. Is C-- a natural choice on this platform? Or might LLVM be a better choice?
- carterschonwald 13y agoUse llvm-general. http://hackage.haskell.org/package/llvm-general http://hackage.haskell.org/package/llvm-general Idris uses llvm-general to have a simple llvm backend. Also llvm general is probably the nicest and most thorough llvm binding you'll find.
- ErsatzVerkehr 13y agoWhere can I find a code example?
- cylinder714 13y agoAnother take on portable assembly languages is Dan Bernstein's qhasm: http://cr.yp.to/qhasm.html http://cr.yp.to/qhasm.html An overview here: http://cr.yp.to/qhasm/20050129-portable.txt http://cr.yp.to/qhasm/20050129-portable.txt
- protomyth 13y agoI must be missing something since I see the line "The specification is available as DVI, PostScript, or PDF.", but cannot find any download link.
- burntsushi 13y agoI think you'll have better luck with this page: http://www.cs.tufts.edu/~nr/c--/ http://www.cs.tufts.edu/~nr/c--/
- carterschonwald 13y agoHey everyone, I'd like to point out that the c-- domain is no longer cminusminus.org, the historical site can be found on norman ramsey's homepage here http://www.cs.tufts.edu/~nr/c--/ http://www.cs.tufts.edu/~nr/c--/ ! It also has actual reading material / papers! The cminusminus domain is no longer valid (though it has more modern CSS), also it lacks links to all the informative papers! C-- is very similar overall to LLVM IR, though there are crucial differences, but overall you could think of them as equivalent representations you can map between trivially (albeit thats glossing over some crucial details). In fact, a few people have been mulling the idea of writing a LLVM IR frontend that would basically be a C-- variant. LLVM IR has a human readable format, but its not quite a programmer writable format! C-- is also the final rep in the ghc compiler before code gen (ie the "native" backend, the llvm backend, and the unregisterized gcc C backend). theres probably a few other things I could say, but that covers the basics. I'm also involved in GHC dev and have actually done a teeny bit of work on the c-- related bits of the compiler. relatedly: i have a few toy C-- snippets you can compile and benchmark using GHC, in a talk I gave a few months ago https://bitbucket.org/carter/who-ya-gonna-call-talk-may-2013-ny-haskell https://bitbucket.org/carter/who-ya-gonna-call-talk-may-2013... https://vimeo.com/69025829 https://vimeo.com/69025829 I should also add that C-- in GHC <= 7.6 doesn't have function arguments, but in GHC HEAD / 7.7 and soon 7.8, you can have nice function args in the C-- functions. See https://github.com/ghc/ghc/blob/master/rts/PrimOps.cmm https://github.com/ghc/ghc/blob/master/rts/PrimOps.cmm for GHC HEAD examples, vs https://github.com/ghc/ghc/blob/ghc-7.6/rts/PrimOps.cmm https://github.com/ghc/ghc/blob/ghc-7.6/rts/PrimOps.cmm for the old style.
- X4 13y agoCode examples: http://www.cs.tufts.edu/~nr/c--/download/c--exn.pdf http://www.cs.tufts.edu/~nr/c--/download/c--exn.pdf Slides: http://www.cs.tufts.edu/~nr/c--/download/c--exnslides.ps.gz http://www.cs.tufts.edu/~nr/c--/download/c--exnslides.ps.gz Audio: http://wino.eecs.harvard.edu:8080/ramgen/nr-pldi00.rm http://wino.eecs.harvard.edu:8080/ramgen/nr-pldi00.rm The Manual: http://www.cs.tufts.edu/~nr/c--/extern/man2.pdf http://www.cs.tufts.edu/~nr/c--/extern/man2.pdf The manual contains the specifications and a few code examples. It looks like it's easy to learn, but it's a little different than other languages.
- gdonelli 13y ago"As of May 2004, only the Pentium back end is as expressive as a C compiler. The Alpha and Mips back ends can run hello, world. We are working on back ends for PowerPC (Mac OS X), ARM, and IA-64. Let us know what other platforms you are interested in."
- EGreg 13y agoIf the language is called C-, how come the website is named Cminusminus?
- EGreg 13y agoHow does C- compare to CIL of .NET?
- Locke1689 13y agoAs far as I can tell, some similar features, but overall completely different. For one, I think C-- still looks a lot like C, i.e. still an imperative language. CIL is a stack language (also with a built-in object system).
- paulhodge 13y agoWould C-- be a good choice for JIT machine code generation, or is it mostly for static compilation?
- jliptzin 13y agoI own the cminusminus.com domain. Was planning on using it for a blog, mainly to post horrible c/c++ code snippets I come across. If anyone wants it, let me know.
- jloughry 13y agoIn case anyone [else] is wondering, RFC 1035 disallows domain names starting or ending with "-", so there is no registering C--.com, alas: <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ] <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str> <let-dig-hyp> ::= <let-dig> | "-" <let-dig> ::= <letter> | <digit> <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case <digit> ::= any one of the ten digits 0 through 9
- carterschonwald 13y agoHello! Very very cool. I'm involved in GHC dev (and thus incidentally c-- dev as it exists in GHC). And i may be spending a lot of time helping improve ghc's code gen over the coming year (which is essentially the most widely used c-- compiler on the planet per se) your remark intrigues me!
- jliptzin 13y agoEmail me joshliptzin at gmail dot com
- sanxiyn 13y agoFor another take on this area, I recommend reading about Pillar from Intel. http://dl.acm.org/citation.cfm?id=1433063 http://dl.acm.org/citation.cfm?id=1433063
- ohwp 13y agoWow, I was surprised by the content of the website. I think this is how a website should be. First they are talking about the problem and then they present the solution. I also like the words that are marked bold. This is how interaction design should be done (imho).
- jdc0589 13y agoCool! the first parser/compiler I wrote was for C-- (the version that is a small subset of C, not this one). Had not even heard an mention of the different C-- languages for a few years now.