annotate README @ 192:b0d6a6940cb7

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