annotate README @ 513:4c2607e72ab5

inline continue... fix function call cstring
author kono
date Mon, 26 Dec 2005 00:45:46 +0900
parents 375d21a2b845
children f9c6976ba270
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)
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
2 $Id$
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
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
8 This is a extension of C ( and a subset of C ). It has a
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
9 programming unit which is called code segment. Code
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
10 segment can be communicate with so called light weight continuation.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
11
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
12
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
13 #include <stdio.h>
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
14
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
15 code factorial(int n,int result,int orig,
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
16 code(*print)(),code(*exit1)(), void *exit1env)
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
17 {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
18 if (n<0) {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
19 printf("err %d!\n",n);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
20 goto (*exit1)(0),exit1env;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
21 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
22 if (n==0)
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
23 goto (*print)(n,result,orig,print,exit1,exit1env);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
24 else {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
25 result *= n;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
26 n--;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
27 goto factorial(n,result,orig,print,exit1,exit1env);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
28 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
29 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
30
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
31 int main( int ac, char *av[])
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
32 {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
33 int n;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
34 n = 10;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
35 goto factorial(n,1,n,print,return,environment);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
36 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
37
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
38 code print(int n,int result,int orig,code(*print)(),(*exit1)(),void*exit1env)
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
39 {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
40 printf("%d! = %d\n",orig, result);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
41 goto (*exit1)(0),exit1env;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
42 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
43
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
44 If you don't use function call, this language becomes subset of C.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
45 It is called Continuation based C. Actually it can be a lower layer of
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
46 C language. Normal C program can be compiled into CbC.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
47
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
48 CbC is a kind of architecture independent assembler language.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
49
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
50 1. Syntax
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
51
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
52 code code_segment_name(interfaces) {
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
53 body;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
54 }
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
55
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
56 code is a type for code segment. A code segment has no return
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
57 statements.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
58
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
59 Interfaces are arguments. It can be struts. or unions. Some
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
60 part of interfaces are mapped into registers. No
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
61 references are allowed in register interface variables.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
62
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
63 Goto statements transfer the control from a segment
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
64 to a segment.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
65 goto segment_name(interfaces);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
66 If two code segments has a same interfaces, transfer cost is very
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
67 small. It us usually a single jump instruction.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
68 If there are differences, some parallel assignment is performed.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
69
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
70 2. Interaction between function and code segment.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
71
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
72 In CwC, you can call C function at any time in code segments.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
73 If you want to call code segment from C and want to do some
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
74 return, explicit handling of function environment.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
75
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
76 goto factorial(n,1,n,print,return,environment);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
77
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
78 return and environment is a special variable which contains
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
79 return point. An environment variable is something like jumpbuf
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
80 in setjump, but it is a simple pointer. Unlike jumpbuf,
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
81 there is no way to allocate are for environment.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
82 void *environment;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
83
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
84 A return variable is a continuation with environment of
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
85 original function. It's type is varied for called function.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
86
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
87 code (*return)(int return_value);
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
88
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
89 To go to the continuation, use goto with environment.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
90
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
91 goto (*exit1)(0),exit1env;
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
92
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
93 3. How to use
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
94
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
95 mc-powerpc, mc-ia32 is a compiler. It generates assembler
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
96 source code .s from C source code.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
97
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
98 mc-powerpc source.c
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
99 gcc source.s
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
100 generates a.out.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
101 mc-powerpc source.c
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
102 gcc -c sources.s
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
103 generates sources.o
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
104
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
105 -s comments in assembler source.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
106 -c check only.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
107 -oname output file names
245
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
108 -Idir/ add library include directory. / is necessary
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
109
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
110 Some examples can be fond in test directory.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
111
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
112 3. Unimplemented lists
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
113
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
114 Mips version is not ready.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
115
245
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
116 64bit long long is now supported
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
117 // long long, long double, unsigned long long can be used as type,
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
118 // but no operation (including assignment) are no allowed.
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
119 // Long long value (0LL) can be used but it gives long value.
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
120 // Long is equal to an int and a pointer (32bit).
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
121
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
122 Only Mac OS X and Red hat Linux is supported.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
123
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
124 Inline directive is ignored and gives normal function definition.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
125
245
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
126 Register float is supported in Power PC
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
127 // Register float arguments does no accepts assignment operation such as
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
128 // *=, /=, +=.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
129
326
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
130 //No built-in alloca.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
131
326
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
132 // No varargs.
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
133
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
134 Use stdarg
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
135
326
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
136 // Switch statements is implemented as series of compare and branch,
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
137 // no tables.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
138
326
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
139 // Some operations such as concatenation are not implemented in macro
e5d40f8c4cce bit-field continue.
kono
parents: 245
diff changeset
140 // processor.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
141
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
142 Macro processor is a coroutine in this compiler, slightly different
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
143 from cpp.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
144
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
145 No -g support.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
146
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
147 No runtime driver for CbC.
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
148
245
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
149 // #include does not search, sources current directory.
8a72b0afccfc *** empty log message ***
kono
parents: 192
diff changeset
150 #include does search, sources current directory.
192
b0d6a6940cb7 *** empty log message ***
kono
parents:
diff changeset
151
339
375d21a2b845 emit_data
kono
parents: 326
diff changeset
152 bit-field is supported, but no global initialization of bit-field.