annotate README @ 935:7672a37e7545 default tip

Raspbery PI ARM support begin
author kono
date Sat, 24 Dec 2016 03:02:57 +0000
parents c005a392e27e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
1 C with Continuation (CwC) and Continuation based C (CbC)
607
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
2
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
3 Shinji Kono
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
4 University of the Ryukyus
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
5
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
6 0. What is this.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
7
861
c005a392e27e fix for Marvaricks
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 637
diff changeset
8 We have gcc and LLVM version. You should use these.
c005a392e27e fix for Marvaricks
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 637
diff changeset
9
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
10 This is a extension of C ( and a subset of C ). It has a
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
11 programming unit which is called code segment. Code
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
12 segment can be communicate with so called light weight continuation.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
13
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
14
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
15 #include <stdio.h>
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
16
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
17 code factorial(int n,int result,int orig,
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
18 code(*print)(),code(*exit1)(), void *exit1env)
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
19 {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
20 if (n<0) {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
21 printf("err %d!\n",n);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
22 goto (*exit1)(0),exit1env;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
23 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
24 if (n==0)
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
25 goto (*print)(n,result,orig,print,exit1,exit1env);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
26 else {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
27 result *= n;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
28 n--;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
29 goto factorial(n,result,orig,print,exit1,exit1env);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
30 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
31 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
32
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
33 int main( int ac, char *av[])
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
34 {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
35 int n;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
36 n = 10;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
37 goto factorial(n,1,n,print,return,environment);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
38 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
39
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
40 code print(int n,int result,int orig,code(*print)(),(*exit1)(),void*exit1env)
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
41 {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
42 printf("%d! = %d\n",orig, result);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
43 goto (*exit1)(0),exit1env;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
44 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
45
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
46 If you don't use function call, this language becomes subset of C.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
47 It is called Continuation based C. Actually it can be a lower layer of
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
48 C language. Normal C program can be compiled into CbC.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
49
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
50 CbC is a kind of architecture independent assembler language.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
51
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
52 1. Syntax
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
53
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
54 code code_segment_name(interfaces) {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
55 body;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
56 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
57
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
58 code is a type for code segment. A code segment has no return
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
59 statements.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
60
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
61 Interfaces are arguments. It can be struts. or unions. Some
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
62 part of interfaces are mapped into registers. No
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
63 references are allowed in register interface variables.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
64
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
65 Goto statements transfer the control from a segment
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
66 to a segment.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
67 goto segment_name(interfaces);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
68 If two code segments has a same interfaces, transfer cost is very
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
69 small. It us usually a single jump instruction.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
70 If there are differences, some parallel assignment is performed.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
71
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
72 2. Interaction between function and code segment.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
73
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
74 In CwC, you can call C function at any time in code segments.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
75 If you want to call code segment from C and want to do some
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
76 return, explicit handling of function environment.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
77
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
78 goto factorial(n,1,n,print,return,environment);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
79
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
80 return and environment is a special variable which contains
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
81 return point. An environment variable is something like jumpbuf
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
82 in setjump, but it is a simple pointer. Unlike jumpbuf,
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
83 there is no way to allocate are for environment.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
84 void *environment;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
85
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
86 A return variable is a continuation with environment of
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
87 original function. It's type is varied for called function.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
88
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
89 code (*return)(int return_value);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
90
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
91 To go to the continuation, use goto with environment.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
92
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
93 goto (*exit1)(0),exit1env;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
94
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
95 3. How to use
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
96
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
97 mc-powerpc, mc-ia32 is a compiler. It generates assembler
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
98 source code .s from C source code.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
99
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
100 mc-powerpc source.c
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
101 gcc source.s
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
102 generates a.out.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
103 mc-powerpc source.c
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
104 gcc -c sources.s
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
105 generates sources.o
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
106
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
107 -s comments in assembler source.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
108 -c check only.
538
f9c6976ba270 *** empty log message ***
kono
parents: 339
diff changeset
109 -v report memory usage
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
110 -oname output file names
538
f9c6976ba270 *** empty log message ***
kono
parents: 339
diff changeset
111 -Dname define name
f9c6976ba270 *** empty log message ***
kono
parents: 339
diff changeset
112 -Dname=value define name as value
f9c6976ba270 *** empty log message ***
kono
parents: 339
diff changeset
113 '-Dname(a)=a+1' define macro function with args
f9c6976ba270 *** empty log message ***
kono
parents: 339
diff changeset
114 -Idir/ add library include directory. / is necessary.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
115
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
116 Some examples can be fond in test directory.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
117
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
118 3. Unimplemented lists
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
119
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
120 Mips version is not ready.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
121
245
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
122 64bit long long is now supported
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
123 // long long, long double, unsigned long long can be used as type,
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
124 // but no operation (including assignment) are no allowed.
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
125 // Long long value (0LL) can be used but it gives long value.
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
126 // Long is equal to an int and a pointer (32bit).
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
127
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
128 Only Mac OS X and Red hat Linux is supported.
637
140b65f8ff03 ARRAY argument in fuction
kono
parents: 607
diff changeset
129 Intel Mac is supported.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
130
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
131 Inline directive is ignored and gives normal function definition.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
132
245
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
133 Register float is supported in Power PC
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
134 // Register float arguments does no accepts assignment operation such as
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
135 // *=, /=, +=.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
136
326
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
137 //No built-in alloca.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
138
326
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
139 // No varargs.
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
140
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
141 Use stdarg
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
142
326
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
143 // Switch statements is implemented as series of compare and branch,
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
144 // no tables.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
145
326
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
146 // Some operations such as concatenation are not implemented in macro
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
147 // processor.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
148
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
149 Macro processor is a coroutine in this compiler, slightly different
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
150 from cpp.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
151
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
152 No -g support.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
153
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
154 No runtime driver for CbC.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
155
245
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
156 // #include does not search, sources current directory.
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
157 #include does search, sources current directory.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
158
339
375d21a2b845 emit_data
kono
parents: 326
diff changeset
159 bit-field is supported, but no global initialization of bit-field.
607
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
160
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
161
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
162 /************************************************************************
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
163 ** Copyright (C) 2006 Shinji Kono
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
164 ** 連絡先: 琉球大学情報工学科 河野 真治
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
165 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
166 **
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
167 ** このソースのいかなる複写,改変,修正も許諾します。ただし、
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
168 ** その際には、誰が貢献したを示すこの部分を残すこと。
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
169 ** 再配布や雑誌の付録などの問い合わせも必要ありません。
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
170 ** 営利利用も上記に反しない範囲で許可します。
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
171 ** バイナリの配布の際にはversion messageを保存することを条件とします。
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
172 ** このプログラムについては特に何の保証もしない、悪しからず。
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
173 **
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
174 ** Everyone is permitted to do anything on this program
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
175 ** including copying, modifying, improving,
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
176 ** as long as you don't try to pretend that you wrote it.
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
177 ** i.e., the above copyright notice has to appear in all copies.
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
178 ** Binary distribution requires original version messages.
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
179 ** You don't have to ask before copying, redistribution or publishing.
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
180 ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
181 ***********************************************************************/
e055df7c1082 *** empty log message ***
kono
parents: 538
diff changeset
182