changeset 45:a737be4a6167

on going
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 16 Jun 2012 04:10:30 +0900
parents 39f6db695840
children f6b9b7648484
files paper/rectype.ind
diffstat 1 files changed, 25 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/paper/rectype.ind	Sat Jun 16 03:41:55 2012 +0900
+++ b/paper/rectype.ind	Sat Jun 16 04:10:30 2012 +0900
@@ -31,6 +31,10 @@
 is a small medication of C. It consists of a syntax to force tail-call-elimination
 and parameterized goto statement. 
 
+Continuation has long history. Usually it means full copy of compuational evironment as in Scheme\cite{scheme}. Our continuation is a simple C function without environment because we have no stack in CbC.
+Using explicit stack, we can convert normal C program into CbC using CPS transformation\cite{cps}, 
+but we commit it's detail here.
+
 C has capable of recursive functions, but we find it's type system is not enough
 to represent CbC programming. In this paper, we introduce \rectype{}
 keyword as a recursive type. To handle recursive type, conventionally tagged struct 
@@ -212,10 +216,17 @@
 
 --How to implement \rectype{}
 
-\rectype{} syntax is implemented overriding AST.
-First, \rectype{} syntax make Tree same \code(Fig.\ref{fig:tree1}).
-Second, tree was created to be rectype flag.
-Third, to override AST(Fig.\ref{fig:tree2}).
+\rectype{} syntax is implemented as a GCC's AST (Abstract Syntax Tree).
+A function type has tree lists of its argments and its return type. 
+In \verb+__code+ case, return type is void.
+When we find \rectype{}, which is as pointer to the function, a pointer type node
+is created (Fig.\ref{fig:tree1}).
+Normaly the type node has a pointer to function type, but
+we put a pointer to the parent function itself (Fig.\ref{fig:tree2}).
+
+It looks like a normal function type and works fine except type comparison, which
+falls into an infinite loop. In order to stop type loop, we introduce \rectype{} flag
+in the type node.  A type comparison was simply stopped when it met \rectype{} flag.
 
 \begin{figure}[htpb]
 \begin{minipage}{0.5\hsize}
@@ -234,35 +245,21 @@
 \end{minipage}
 \end{figure}
 
-This AST(Fig.\ref{fig:tree2}) is made by syntax of \verb+__code csA(__rectype *p)+ .
-\treelist{} have information of argument.
-First \treelist{} represent that argument is function pointer(\verb+__code (*p)()+) .
-Second \treelist{} represent that csA is Fixed-length argument.
-Third \treelist{} is connected with \pointertype.
-\pointertype{} have pointer of function(\functiontype).
-We have to override it in the pointer of csA.
-
-
-
-
---Problems with implementation of \rectype.
-
-Segmentation fault has occurred in the following program on compile.
+A type check is taken in the parametarized goto statement or function call. 
 
     __code csA(__rectype *p) {
        goto p(3);
     }
 
-The above code is the wrong argument of p.
-The p's argument is converted by GCC.
-3 of type int is converted to a pointer type of Code Segment.
-At this time, GCC looks at the type of the argument.
-p's argument is pointer of csA.
-csA's argument is p.
-GCC is also an infinite recursion happens to see the type of argument of the argument.
+In this case, {\tt 3} is not a type of \verb+__code csA(__rectype *P)+ and the compiler complains.
+But the code below does not check its argument.
 
-We Solve this problem that does not check the arguments if the \rectype{} flag is true.
-The following program become part was fixed gcc/c-family/c-pretty-print.c.
+    __code csA(__code (*p)()) {
+       goto p(3);
+    }
+
+The \rectype{} flag is implemented in  following program in
+gcc/c-family/c-pretty-print.c.
 
     static void
     pp_c_abstract_declarator (c_pretty_printer *pp, tree t)
@@ -280,43 +277,8 @@
       pp_direct_abstract_declarator (pp, t);
     }
 
+\verb+if (IS_RECTYPE(t)) return;+ prevents infinite type check.
  
-Variable t have information of p's argument.
-If t is \pointertype, t is assigned type of \pointertype(\verb+t = TREE_TYPE (t);+).
-We have added code \verb+if (IS_RECTYPE(t)) return;+
-Thereby we have solved type checking and infinite recursion problem.
-
-
-
-
---Method other than \rectype
-
-The recursively program of C's syntax can be solved using struct syntax.
-For example, if we write
-
-    struct interface {
-       __code (*next)(struct interface);
-    };
-
-    __code csA(struct interface p) {
-        struct interface ds;
-	ds.next = csB;
-        goto p.next(ds);
-    }
-
-    int main() {
-        struct interface ds;
-	ds = print;
-        goto csA(ds);
-        return 0;
-    }
-
-there is no need to write recursively.
-Because the struct syntax wrapped in a function pointer.
-Code Segment does not receive function pointer in arguments.
-Recursively program does not occur.
-
-
 --Comparison
 
 Here is CbC program that finds the Fibonacci sequence.