view final_main/chapter2.tex @ 11:53114bdcb0c3

tweak
author menikon
date Sun, 09 Feb 2020 19:53:00 +0900
parents 40726bcd5272
children 14feebd2285c
line wrap: on
line source

\chapter{Continuation based C}
%\label{chap:concept}
\section{Continuation based Cの概要}
Continuation based C \cite{cbc} (以下CbC) は基本的な処理単位を CodeGear として定義し, CodeGea 間で遷移するようにプログラムを記述する C 言語と互換性のある当研究室で開発されたプログラミング言語である.図\ref{fig:codegear}はCodeGear間の継続する際の処理の流れを示している.

\begin{figure}[ht]
     \begin{center}
     \includegraphics[width=150mm]{fig/gotoCodeGear.pdf}
     \end{center}
     \caption{CodeGear間の継続}
    \label{fig:codegear}
\end{figure}

現在 CbC は C コンパイラであるGCC\cite{gcc} \cite{nobu-prosym}及びLLVM\cite{llvm} \cite{kaito-lola}をバックエンドとした clang 上で実装されている.
本研究ではこのプログラミング言語を用いて xv6 の Filesystemを書き換える.
\section{CodeGear}
CodeGear は CbCにおける基本的な処理単位である. 以下のソースコード\ref{cbcexample}は CodeGear の継続の例である.
\newpage
\lstinputlisting[label=cbcexample,  caption=CodeGearの継続の例]{src/cbc_example.cbc}
CodeGear は\_\_code CodeGear名 (引数) の形で記述される.
CodeGear は返り値を持たない為, 関数内で処理が終了すると呼び出し 元の関数に戻ることがなく別の CodeGear へ遷移する. 
ソースコード\ref{cbcexample}の5行目のgoto cg1(c); や8行目のgoto cg2(c); などがこれにあたる.図\ref{fig:goto}はソースコード\ref{cbcexample}の状態遷移を表している.

\begin{figure}[ht]
     \begin{center}
     \includegraphics[width=100mm]{fig/goto.pdf}
     \end{center}
     \caption{ソースコード\ref{cbcexample} が表しているCodeGearの状態遷移}
    \label{fig:goto}
\end{figure}

また CbC における CodeGear 間の継続にはスタックが使用されず, 呼び出し元の環境などを持たない為軽量継続と呼ぶ.
この CbC における CodeGear 間の継続にスタックが使用されない性質は信頼性の高い OS の開発に適している.
\newpage
\section{DataGear}
DataGear は CbCにおけるデータの基本的な単位である. CodeGear は  Input DataGear, Output DataGear を引数に持ち,図\ref{fig:DataGear}で示したように遷移する際に任意のInput DataGearを参照し, Output DataGearを書き出す.

\begin{figure}[ht]
     \begin{center}
     \includegraphics[width=100mm]{fig/DataGear.pdf}
     \end{center}
     \caption{CodeGearとDataGear}
    \label{fig:DataGear}
\end{figure}