view README @ 560:d6ff45d719a5 string-shared

string sharing
author kono
date Sat, 07 Jan 2006 18:11:53 +0900
parents f9c6976ba270
children e055df7c1082
line wrap: on
line source

C with Continuation (CwC) and Continuation based C (CbC)
   $Id$
             Shinji Kono
             University of the Ryukyus

0. What is this.

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.

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.