Mercurial > hg > CbC > old > device
view README @ 935:7672a37e7545 default tip
Raspbery PI ARM support begin
author | kono |
---|---|
date | Sat, 24 Dec 2016 03:02:57 +0000 |
parents | c005a392e27e |
children |
line wrap: on
line source
C with Continuation (CwC) and Continuation based C (CbC) Shinji Kono University of the Ryukyus 0. What is this. We have gcc and LLVM version. You should use these. This is a extension of C ( and a subset of C ). It has a programming unit which is called code segment. Code segment can be communicate with so called light weight continuation. #include <stdio.h> code factorial(int n,int result,int orig, code(*print)(),code(*exit1)(), void *exit1env) { if (n<0) { printf("err %d!\n",n); goto (*exit1)(0),exit1env; } if (n==0) goto (*print)(n,result,orig,print,exit1,exit1env); else { result *= n; n--; goto factorial(n,result,orig,print,exit1,exit1env); } } int main( int ac, char *av[]) { int n; n = 10; goto factorial(n,1,n,print,return,environment); } code print(int n,int result,int orig,code(*print)(),(*exit1)(),void*exit1env) { printf("%d! = %d\n",orig, result); goto (*exit1)(0),exit1env; } If you don't use function call, this language becomes subset of C. It is called Continuation based C. Actually it can be a lower layer of C language. Normal C program can be compiled into CbC. CbC is a kind of architecture independent assembler language. 1. Syntax code code_segment_name(interfaces) { body; } code is a type for code segment. A code segment has no return statements. Interfaces are arguments. It can be struts. or unions. Some part of interfaces are mapped into registers. No references are allowed in register interface variables. Goto statements transfer the control from a segment to a segment. goto segment_name(interfaces); If two code segments has a same interfaces, transfer cost is very small. It us usually a single jump instruction. If there are differences, some parallel assignment is performed. 2. Interaction between function and code segment. In CwC, you can call C function at any time in code segments. If you want to call code segment from C and want to do some return, explicit handling of function environment. goto factorial(n,1,n,print,return,environment); return and environment is a special variable which contains return point. An environment variable is something like jumpbuf in setjump, but it is a simple pointer. Unlike jumpbuf, there is no way to allocate are for environment. void *environment; A return variable is a continuation with environment of original function. It's type is varied for called function. code (*return)(int return_value); To go to the continuation, use goto with environment. goto (*exit1)(0),exit1env; 3. How to use mc-powerpc, mc-ia32 is a compiler. It generates assembler source code .s from C source code. mc-powerpc source.c gcc source.s generates a.out. mc-powerpc source.c gcc -c sources.s generates sources.o -s comments in assembler source. -c check only. -v report memory usage -oname output file names -Dname define name -Dname=value define name as value '-Dname(a)=a+1' define macro function with args -Idir/ add library include directory. / is necessary. Some examples can be fond in test directory. 3. Unimplemented lists Mips version is not ready. 64bit long long is now supported // long long, long double, unsigned long long can be used as type, // but no operation (including assignment) are no allowed. // Long long value (0LL) can be used but it gives long value. // Long is equal to an int and a pointer (32bit). Only Mac OS X and Red hat Linux is supported. Intel Mac is supported. Inline directive is ignored and gives normal function definition. Register float is supported in Power PC // Register float arguments does no accepts assignment operation such as // *=, /=, +=. //No built-in alloca. // No varargs. Use stdarg // Switch statements is implemented as series of compare and branch, // no tables. // Some operations such as concatenation are not implemented in macro // processor. Macro processor is a coroutine in this compiler, slightly different from cpp. No -g support. No runtime driver for CbC. // #include does not search, sources current directory. #include does search, sources current directory. bit-field is supported, but no global initialization of bit-field. /************************************************************************ ** Copyright (C) 2006 Shinji Kono ** 連絡先: 琉球大学情報工学科 河野 真治 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp) ** ** このソースのいかなる複写,改変,修正も許諾します。ただし、 ** その際には、誰が貢献したを示すこの部分を残すこと。 ** 再配布や雑誌の付録などの問い合わせも必要ありません。 ** 営利利用も上記に反しない範囲で許可します。 ** バイナリの配布の際にはversion messageを保存することを条件とします。 ** このプログラムについては特に何の保証もしない、悪しからず。 ** ** Everyone is permitted to do anything on this program ** including copying, modifying, improving, ** as long as you don't try to pretend that you wrote it. ** i.e., the above copyright notice has to appear in all copies. ** Binary distribution requires original version messages. ** You don't have to ask before copying, redistribution or publishing. ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. ***********************************************************************/