分页: 1 / 2

一门很有用的编程语言:C--

发表于 : 2008-01-10 13:19
stlxv
官方网站:http://www.cminusminus.org
1 Introduction
C-- is a compiler-target language. The idea is that a compiler for a high-level language translates programs
into into C--, leaving the C-- compiler to generate native code. C--’s major goals are these:
• C-- encapsulates compilation techniques that are well understood, but difficult to implement. Such
techniques include instruction selection, register allocation, instruction scheduling, and optimization
of imperative code with loops.
• C-- is a language, rather than a library (such as gcc’s RTL back end). As such, it has a concrete syntax
that can be read by people, and a semantics that is independent of any particular implementation.
• C-- is a portable assembly language. It is, by design, as low-level as possible while still concealing
details of the particular machine architecture.
• C-- is independent of both source programming language and target architecture. Its design accom-
modates a variety of source languages and leaves room for back-end optimization, all without upcalls
from the back end to the front end.
• C-- is efficient—or at least admits efficient implementation. So C-- provides almost as much flexibility
and performance (assuming a good C-- compiler) as a custom code generator.
A client of C-- is divided into two parts. The front-end compiler generates programs written in the C--
language, which the C-- compiler translates into efficient machine code. This code interoperates with the
front-end run-time system, which implements such services as garbage collection, exception dispatch, thread
scheduling, and so on. The front-end run-time system relies on mechanisms provided by the C-- run-time
system; they interact through the C-- run-time interface. This document describes the C-- language and
run-time interface. It is intended for authors who wish to write clients of the C-- system.
The C-- team has prepared some demonstration front ends that may help you learn to use C--.
• Paul Govereau’s tigerc compiler includes a compiler for Tiger (the language of Andrew Appel’s
compiler text) as well as a small run-time system with garbage collector. The tigerc compiler is
written in Objective Caml.
• Norman Ramsey’s lcc back end works with lcc to translate C into C--. It is written in C.
• Reuben Olinsky’s interpreter, which is packaged with the Quick C-- sources, includes sample run-time
clients for garbage collection and exception dispatch.
All this code is available through the C-- web site at http://www.cminusminus.org.
1.1 What C-- is not
C-- has some important non-goals:
• C-- is not an execution platform, such as the Java Virtual Machine or the .NET Common Language
Runtime. These virtual machines are extremely high-level compared to C--. Each provides a rich type
system, garbage collector, class loader, just-in-time compiler, byte-code verifier, exception-dispatch
mechanism, debugger, massive libraries, and much more besides. These may be good things, but
they clearly involve much more than encapsulating code-generation technology, and depending on your
language model, they may impose a significant penalty in both space and time.
6
• C-- is not “write-once, run-anywhere”. It conceals most architecture-specific details, such as the
number of registers, but it exposes some. In particular, C-- exposes the word size, byte order, and
alignment properties of the target architecture, for two reasons. First, to hide these details would
require introducing a great deal of complexity, inefficiency, or both—especially when the front-end
compiler needs to control the representation of its high-level data types. Second, these details are easy
to handle in a front-end compiler. Indeed, a compiler may benefit, because it can do address arithmetic
using integers instead of symbolic constants such as FloatSize and IntSize.
一个C--的例子:
图片

发表于 : 2008-01-10 14:23
woaiwojia
呵呵,学习的好地方

发表于 : 2008-01-10 14:51
bones7456
恩,貌似不错啊...

发表于 : 2008-01-10 15:47
shellex
存在的意义是什么?
C--的定位有点窄,而且感觉不是很有必要。

发表于 : 2008-01-11 21:57
yangyuruc
学不完了哈

发表于 : 2008-01-12 0:13
njayong080108
一件玩具而已。。。

发表于 : 2008-01-12 6:58
蓝蓝
想学 而不敢学~怕被套进去- -!

发表于 : 2008-01-12 10:46
wuxb
想极力贴近汇编级,还能翻译其他的语言,着实不知其所云,这些应该都是编译器做的事情吧,写个把java编译成机器码的编译器未尝不可。只要有功夫去用c之类的实现java的庞大的类库

发表于 : 2008-01-12 11:04
ljj_jjl2008
又是一堆英文,我还是看不懂,我再哭!!
:em21 :em21 :em21 :em21 :em20 :em20 :em20 :em20 :em55 :em55 :em55 :em55

发表于 : 2008-01-12 13:09
eexpress
这不好。像汇编了。估计不比我的汇编里面定义的宏高级。
我要搞c--的。打倒这个。

发表于 : 2008-01-13 2:03
stlxv
eexpress 写了:这不好。像汇编了。估计不比我的汇编里面定义的宏高级。
我要搞c--的。打倒这个。
官方网站介绍说这其实就是一门可移植的汇编语言

发表于 : 2008-01-13 14:58
forrid
有汇编就足够了,搞那么多飞机。

我以前的,也简单。

发表于 : 2008-01-13 15:06
eexpress

代码: 全选

	Cmp	Temp
	Beq	_Cpyid		;校验和正确
	Bra	_Errid
_Newid	Lcall	Getsum,#Nc,#8	;保存校验和到EE
	Sta	Temp
	Sta	Temp+1
	Lcall	E.Write,#Ee_Nc_Sum,#Temp,#2
_Cpyid	Lcall	Copy,#Nc,#Ucode,#8	;第一次读入编号
Chkend	Bclr	Error,Status
	Rts

发表于 : 2008-01-17 17:14
ghosTM55
.......................
什么时候有c+-

发表于 : 2008-01-23 10:56
peigen
减减,汗~~~

这帮死老外