# HG changeset patch # User Takahiro SHIMIZU # Date 1541563104 -32400 # Node ID ed882dba29f6446701f28872f82e4e4957940413 # Parent 8580ad6c50dd87bd5a58c3c788b3b7fddc24932e add about threaded code and jlisting.sty diff -r 8580ad6c50dd -r ed882dba29f6 .hgignore --- a/.hgignore Tue Nov 06 23:22:43 2018 +0900 +++ b/.hgignore Wed Nov 07 12:58:24 2018 +0900 @@ -15,3 +15,4 @@ *.swo *.fls *.fdb_latexmk +*.synctex.gz diff -r 8580ad6c50dd -r ed882dba29f6 Paper/anatofuz.tex --- a/Paper/anatofuz.tex Tue Nov 06 23:22:43 2018 +0900 +++ b/Paper/anatofuz.tex Wed Nov 07 12:58:24 2018 +0900 @@ -90,6 +90,8 @@ \subsection{CodeSegmentとDataSegment} CbCではCの関数の代わりにCodeSegmentを導入する. CodeSegmentはCの関数宣言の型名の代わりに\_\_codeと書くことで 宣言できる. +\_\_codeはCbCコンパイラの扱いはvoidと同じ型であるが,CbCプログラミングではCodeSegmentである事を示す識別子としての意味で利用する. + \subsection{現在の実装} CbCは現在主要なCコンパイラであるgcc及びllvmをバックエンドとしたclang上の2種類の実装が存在する. @@ -103,8 +105,9 @@ 本来コンパイラ側のバグを回避するプログラミングをプログラマに要求するスタイルは好ましくない. 従ってCbCコンパイラ自身の信頼性を向上させる事も今後の課題となっている. \subsection{CbCとCの互換性} -CbCはCコンパイラ上に実装している為,CSを利用しない場合は通常のCプログラムとして動作する. -CbCコンパイラは内部的に与えられているソースコードがCbCであるかどうかを判断し,そうでない場合は通常のコンパイラとして動作する. +CbCコンパイラは内部的に与えられているソースコードがCbCであるかどうかを判断する. +この際にCodeSegmentを利用していない場合は通常のCプログラムとして動作する. +これはCbCコンパイラがCコンパイラであるgccとllvm/clang上に実装している為である. その為MoarVMのビルドにおいてもCbCで書き換えたソースコードがあるターゲットと,手を加えていないオリジナルのターゲットの2種類を同一のCbCコンパイラでビルドする事が可能である. @@ -193,6 +196,18 @@ MoarVMにおける基本ブロックはインタプリタが実行するバイトコードごとの処理に該当する. \subsection{CbCコンパイラによるバグ} +\subsection{Threaded Code} +CbCはCodeSegmentで末尾最適化(Tail call optimization)を行う. +これはCodeSegmentは必ず関数呼び出しではなくgotoで次の状態に遷移する為にスタック領域の操作が必要とならない為である. +現在のCbCコンパイラの実装ではCodeSegmentからCの関数に戻る場合は末尾最適化を切り,CodeSegment間の遷移では末尾最適化が行われる. +末尾最適化を応用することでContinuation-passingスタイルのThreaded Codeの実装が可能となる.\cite{threadedcode} + +現在のCbCMoarVMは次の命令セットのディスパッチをcbc\_nextというCodeSegmentで処理している. +これは元のMoarVMの命令ディスパッチで行われる現在のオペコードを示すcur\_opと命令列opの操作及び次のラベルに遷移するマクロに該当する. +CbCMoarVMではラベルに対しての遷移の代わりにMoarVMの命令のCodeSegmentの集合体である配列CODESにアクセスし,その要素であるCodeSegmentに対して遷移する形を取っている. +この一連の処理がオーバーヘッドになる為,今後はcbc\_fixt\_nextというCodeSegmentを導入し直接次の命令に該当するCodeSegmentへgotoする様に実装する予定である. + + \section{CbCを用いる事についての評価} Perl6処理系はまずPerl6の豊富な文法に対応する物を作成せねばならず,類似する他のプログラミング言語処理系と比較してもより複雑となっている. 実際にPerl5を始めとしたスクリプト言語とPerl6がどのような処理時間の違いが見られるかを実測する. @@ -215,8 +230,6 @@ \section{今後の課題} -\section{まとめ} - %å\subsection{MoarVMの処理流れ} %MoarVMはC言語で実装されており,Perl5で記述されたConfigure.plを diff -r 8580ad6c50dd -r ed882dba29f6 Paper/jlisting.sty --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Paper/jlisting.sty Wed Nov 07 12:58:24 2018 +0900 @@ -0,0 +1,216 @@ +\NeedsTeXFormat{LaTeX2e} +\def\filedate{2006/02/20} +\def\fileversion{0.2} +\ProvidesPackage{jlisting}[\filedate\space\fileversion\space(Thor)] +% +\newcount\lst@nextchar +\let\lst@@ProcessSpace\lst@ProcessSpace +\def\lst@ProcessSpace#1{% + \lst@check@chartype{#1}% + \lst@@ProcessSpace + \lst@whitespacetrue} +\let\lst@@ProcessLetter\lst@ProcessLetter +\def\lst@ProcessLetter#1#2{% + \lst@check@chartype{#2}% + {\lst@@ProcessLetter{#1}}% + \relax} +\let\lst@@ProcessDigit\lst@ProcessDigit +\def\lst@ProcessDigit#1#2{% + \lst@check@chartype{#2}% + {\lst@@ProcessDigit{#1}}% + \relax} +\let\lst@@ProcessOther\lst@ProcessOther +\def\lst@ProcessOther#1#2{% + \lst@check@chartype{#2}% + {\lst@@ProcessOther{#1}}% + \relax} +\let\lst@@ProcessTabulator\lst@ProcessTabulator +\def\lst@ProcessTabulator#1{% + \lst@check@chartype{#1}% + \lst@@ProcessTabulator + \relax} +\def\lst@check@chartype#1#2#3{% + \edef\@tempa{\lst@nextchar=`\string#1\relax}% + \afterassignment\remove@to@nnil + \@tempa\@nnil + #2% + \ifnum\lst@nextchar<\@cclvi + #3% + \else + \lst@ifletter \else \lst@OutputOther \fi + \lst@whitespacefalse + \expandafter\lst@AppendJchar + \fi + #1} +\def\lst@AppendJchar#1#2{% + \lst@check@chartype{#2}% + {\advance\lst@length\@ne\lst@Append{#1}}% + \relax} +\def\lst@check@chartype@BOL#1{% + \edef\@tempa{\lst@nextchar=`\string#1\relax}% + \afterassignment\remove@to@nnil + \@tempa\@nnil + \ifnum\lst@nextchar<\@cclvi\else + \lst@whitespacefalse + \expandafter\lst@AppendJchar + \fi + #1} +\def\lst@InputListing#1{% + \begingroup + \lsthk@PreSet \gdef\lst@intname{#1}% + \expandafter\lstset\expandafter{\lst@set}% + \lsthk@DisplayStyle + \catcode\active=\active + \lst@Init\relax \let\lst@gobble\z@ + \lst@SkipToFirst + \lst@ifprint \def\lst@next{\lst@get@filecontents{#1}}% + \else \let\lst@next\@empty + \fi + \lst@next + \lst@DeInit + \endgroup} +\newread\lst@inputfile +\def\lst@get@filecontents#1{% + \let\lst@filecontents\@empty + \openin\lst@inputfile=#1\relax + \let\@lst@get@filecontents@prevline\relax + \lst@get@filecontents@loop + \closein\lst@inputfile + \lst@filecontents\empty} +\def\lst@get@filecontents@loop{% + \read\lst@inputfile to\@lst@get@filecontents@currline + \ifx\@lst@get@filecontents@prevline\relax\else + \expandafter\expandafter\expandafter\def + \expandafter\expandafter\expandafter\lst@filecontents + \expandafter\expandafter\expandafter{% + \expandafter\lst@filecontents\@lst@get@filecontents@prevline}% + \fi + \let\@lst@get@filecontents@prevline\@lst@get@filecontents@currline + \ifeof\lst@inputfile\else + \expandafter\lst@get@filecontents@loop + \fi} +%%% [$B$3$N=hM}$b!$AjEv6/0z$G$9!%(B] +\def\lst@BOLGobble{% + \ifnum\lst@gobble>\z@ + \@tempcnta\lst@gobble\relax + \expandafter\lst@BOLGobble@ + \else + \expandafter\lst@check@chartype@BOL + \fi} +\def\lst@BOLGobble@#1{% + \let\lst@next#1% + \ifx \lst@next\relax\else + \ifx \lst@next\lst@MProcessListing\else + \ifx \lst@next\lst@ProcessFormFeed\else + \ifx \lst@next\lstenv@backslash + \let\lst@next\lstenv@BOLGobble@@ + \else + \let\lst@next\lst@BOLGobble@@ + \ifx #1\lst@ProcessTabulator + \advance\@tempcnta-\lst@tabsize\relax + \ifnum\@tempcnta<\z@ + \lst@length-\@tempcnta \lst@PreGotoTabStop + \fi + \else + \edef\@tempa{\lst@nextchar=`\string#1\relax}% + \@tempa + \ifnum\lst@nextchar<\@cclvi\else + \advance\@tempcnta\m@ne + \fi + \advance\@tempcnta\m@ne + \fi + \fi \fi \fi \fi + \lst@next} +\def\lst@BOLGobble@@{% + \ifnum\@tempcnta>\z@ + \expandafter\lst@BOLGobble@ + \else + \expandafter\lst@check@chartype@BOL + \fi +} +% +% \begin{$B=$@5;v9`(B}{1.3} +% $B$A$g$C$H$7$?=$@5(B +\gdef\lst@breakProcessOther#1{\lst@ProcessOther#1} +% $B%=!<%9%3!<%IL\:\$7$^$7$?!#(B + +\begin{quote} + \url{http://http://cise.edu.mie-u.ac.jp/~okumura/texfaq/qa/21172.html}\\ + \url{http://http://cise.edu.mie-u.ac.jp/~okumura/texfaq/qa/21184.html}\\ + \url{http://http://cise.edu.mie-u.ac.jp/~okumura/texfaq/qa/21189.html}\\ + \url{http://http://cise.edu.mie-u.ac.jp/~okumura/texfaq/qa/21197.html} +\end{quote} + + Copyright $B$O5H1JE/H~;a$K$"$k$N$@$H;W$$$^$9!%(B + +\section{$B99?7MzNr(B}% ChageLogs + +\begin{description} + \item[ver.~0.1 (2004/03/24)] + $B$H$j$"$($:8x3+!%(B + \item[ver.~0.2 (2006/02/20)] + \verb|\lst@breakProcessOther| $BL?Na$NDj5A$NDI2C!%(B +\end{description} + +\section{$B%=!<%9%3!<%I(B} +\par\narrowbaselines +\verbatiminput{jlisting.sty} +\end{document} diff -r 8580ad6c50dd -r ed882dba29f6 Paper/reference.bib --- a/Paper/reference.bib Tue Nov 06 23:22:43 2018 +0900 +++ b/Paper/reference.bib Wed Nov 07 12:58:24 2018 +0900 @@ -57,3 +57,8 @@ title = {Rakudo and NQP internals - day1}, howpublished = {\url{http://edumentab.github.io/rakudo-and-nqp-internals-course/slides-day1.pdf}}, } + +@misc{threadedcode, + title = {Threaded Code}, + howpublished = {\url{https://www.complang.tuwien.ac.at/forth/threaded-code.html}}, +}