# HG changeset patch # User Nobuyasu Oshiro # Date 1339572221 -32400 # Node ID 2016fd4e0191444a1e0eec345452edd99e149f15 # Parent a9c4eb2b29b8b7acecab1bdd82fe828f17c487e3 write explanation of CbC diff -r a9c4eb2b29b8 -r 2016fd4e0191 paper/aplas2012.tex --- a/paper/aplas2012.tex Tue Jun 12 12:38:48 2012 +0900 +++ b/paper/aplas2012.tex Wed Jun 13 16:23:41 2012 +0900 @@ -36,63 +36,139 @@ \section{Introduce} - -\subsection{subsection} - -\subsubsection{sub-subsection} \paragraph{paragraph} \section{Continuation based C} +CbC's basic programming unit is a code segment. It is not a subroutine, but it +looks like a function, because it has input and output. We can use C struct +as input and output interfaces. -\begin{figure}[htpb] - \begin{center} -\scalebox{0.35}{\includegraphics{figure/codesegment.pdf}} - \end{center} - \caption{} - \label{fig:codesegment} +{\small +\begin{verbatim} + struct interface1 { int i; }; + struct interface2 { int o; }; + + __code f(struct interface1 a) { + struct interface2 b; b.o=a.i; + goto g(b); + } + +\end{verbatim} +} + + +In this example, a code segment +\verb+f+ has \verb+input a+ and sends \verb+output b+ to a code segment \verb+g+. +There is no return from code segment \verb+b+, \verb+b+ should call another +continuation using \verb+goto+. Any control structure in C is allowed in CwC +language, but in case of CbC, we restrict ourselves to use \verb+if+ statement +only, because it is sufficient to implement C to CbC translation. In this case, +code segment has one input interface and several output interfaces (fig.\ref{code}). + +\begin{figure}[htb] +\begin{center} +\includegraphics[width=6cm]{figure/code.pdf} +\caption{code} +\end{center} +\label{code} \end{figure} +\verb+__code+ and parameterized global goto statement is an extension of +Continuation based C. Unlike \verb+C--+ \cite{cminusminus}'s parameterized goto, +we cannot goto into normal C function. + +\subsection{ Intermix with C} + +In CwC, we can go to a code segment from a C function and we can call C functions +in a code segment. So we don't have to shift completely from C to CbC. The later +one is straight forward, but the former one needs further extensions. + +{\small +\begin{verbatim} + void *env; + __code (*exit)(int); + + __code h(char *s) { + printf(s); + goto (*exit)(0),env; + } + + int main() { + env = __environment; + exit = __return; + goto h("hello World\n"); + } + +\end{verbatim} +} + +In this hello world example, the environment of \verb+main()+ +and its continuation is kept in global variables. The environment +and the continuation can be get using \verb+__environment+, +and \verb+__return+. Arbitrary mixture of code segments and functions +are allowed (in CwC). The continuation of \verb+goto+ statement +never returns to original function, but it goes to caller of original +function. In this case, it returns result 0 to the operating system. + + + + + + +%\begin{figure}[htpb] +% \begin{center} +%\scalebox{0.35}{\includegraphics{figure/codesegment.pdf}} +% \end{center} +% \caption{} +% \label{fig:codesegment} +%\end{figure} + +\newpage + \section{recursive type syntax} We implemented \verb+__rectype+ syntax in GCC. \verb+__rectype+ syntax is declare a recursive type. -This example is using \verb+__rectype+. +This example is using \verb+__rectype+ in CbC. -\begin{lstlisting} +\begin{figure}[htpb] +\begin{verbatim} __code csA( __rectype *p) { goto p(csB); } -\end{lstlisting} +\end{verbatim} +\caption{example using \_\_rectype} +\label{code:rectype} +\end{figure} -*p represent pointer of csA at this example. +*p represent pointer of csA at \ref{code:rectype} . p's argument type is same csA that function pointer. + +Recursive type Can not declarated in C. +Because + + + It is the same as the following. -\begin{lstlisting} +\begin{verbatim} void csA( void (*p)(void*)) { p(csB); } -\end{lstlisting} - -Type checking can be performed if this declaration. +\end{verbatim} -\subsection{What is recursive type} -Recursive type is - - - -\begin{lstlisting} +\begin{verbatim} __code csA( __code (*p)( __code (*)( __code (*)( __code )))) { goto p(csB); } -\end{lstlisting} +\end{verbatim} -This example is rectype syntax: +\subsection{Implementation of \_\_rectype in GCC} \begin{figure}[htpb] @@ -114,8 +190,9 @@ +\subsection{Method other than \_\_rectype} -\begin{lstlisting} +\begin{verbatim} struct interface { __code (*next)(struct interface); }; @@ -130,19 +207,19 @@ goto csA(ds); return 0; } -\end{lstlisting} +\end{verbatim} -\begin{lstlisting} +\begin{verbatim} __code fibonacci(__rectype *p, int num, int count, int result, int prev) { -\end{lstlisting} +\end{verbatim} - +\section{conclusion} \begin{table}[htpb] diff -r a9c4eb2b29b8 -r 2016fd4e0191 paper/figure/code.pdf Binary file paper/figure/code.pdf has changed diff -r a9c4eb2b29b8 -r 2016fd4e0191 paper/figure/code.xbb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paper/figure/code.xbb Wed Jun 13 16:23:41 2012 +0900 @@ -0,0 +1,8 @@ +%%Title: ./code.pdf +%%Creator: extractbb 20110311 +%%BoundingBox: 0 0 614 303 +%%HiResBoundingBox: 0.000000 0.000000 613.500000 303.000000 +%%PDFVersion: 1.4 +%%Pages: 1 +%%CreationDate: Wed Jun 13 16:16:48 2012 + diff -r a9c4eb2b29b8 -r 2016fd4e0191 paper/figure/codesegment.pdf Binary file paper/figure/codesegment.pdf has changed diff -r a9c4eb2b29b8 -r 2016fd4e0191 paper/figure/codesegment.xbb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paper/figure/codesegment.xbb Wed Jun 13 16:23:41 2012 +0900 @@ -0,0 +1,8 @@ +%%Title: ./codesegment.pdf +%%Creator: extractbb 20110311 +%%BoundingBox: 0 0 611 302 +%%HiResBoundingBox: 0.000000 0.000000 610.500000 301.500000 +%%PDFVersion: 1.3 +%%Pages: 1 +%%CreationDate: Tue Jun 12 01:19:20 2012 + diff -r a9c4eb2b29b8 -r 2016fd4e0191 paper/figure/compare.pdf Binary file paper/figure/compare.pdf has changed diff -r a9c4eb2b29b8 -r 2016fd4e0191 paper/figure/compare.xbb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paper/figure/compare.xbb Wed Jun 13 16:23:41 2012 +0900 @@ -0,0 +1,8 @@ +%%Title: ./compare.pdf +%%Creator: extractbb 20110311 +%%BoundingBox: 0 0 468 243 +%%HiResBoundingBox: 0.000000 0.000000 468.000000 243.000000 +%%PDFVersion: 1.3 +%%Pages: 1 +%%CreationDate: Thu Jun 7 19:32:39 2012 +