# HG changeset patch # User Kaito Tokumori # Date 1454995902 -32400 # Node ID ea7938131775e68653dc23544028fccee7d49e9f # Parent 24e4c08b4e35da7dfc087cdef0464f3d7e15ec30 script diff -r 24e4c08b4e35 -r ea7938131775 paper/chapter1.tex --- a/paper/chapter1.tex Tue Feb 09 02:55:11 2016 +0900 +++ b/paper/chapter1.tex Tue Feb 09 14:31:42 2016 +0900 @@ -96,6 +96,7 @@ このような形にすることで, code segment 側では関数から呼ばれたか, code segment からの継続かを考慮する必要がなくなる. また, funcA から見た場合にも, 呼び出した関数の内部で code segment が使われているかどうかが隠蔽され, code segment の有無を考慮しなくて良い. \section{Gears OS サポート} +\label{sec:Gears} Gears OS は当研究室で開発している並列フレームワークで, CbC で記述している. Gears では通常の CbC には存在しないメタレベルの処理を表す meta code segment, データの単位である data segment, data segment や code segment 等の情報を管理する context 等がある. これらを現在の CbC の機能のみを用いて記述するとリスト\ref{gears}のようになり, 多くの労力を要する. そのためこの記述を助ける機能が必要であり, 本研究ではこれらを利用するプログラミングをサポートするために以下の機能を提案した. \begin{itemize} diff -r 24e4c08b4e35 -r ea7938131775 paper/chapter4.tex --- a/paper/chapter4.tex Tue Feb 09 02:55:11 2016 +0900 +++ b/paper/chapter4.tex Tue Feb 09 14:31:42 2016 +0900 @@ -1,3 +1,92 @@ \chapter{Gears OS サポート} +\ref{sec:Gears} 節で述べた Gears OS の記述を助ける構文について記す. + +Gears OS のための構文のサポートには python スクリプトを用いた. 記述したプログラムをこのスクリプトに読み込ませることで CbC コンパイラでコンパイル可能な構文へと変換される. このようにすることで Gears OS のコード, CbC のコード両方のコンパイルが可能になる. \section{meta Code Segment の接続} -\section{stub の接続} +Gears OS では code segment 間の遷移に meta レベルの meta code segment を挟む. その様子を表したのが図 \ref{fig:meta} である. 通常レベルの code segment は一度 meta code segment へと継続し, その後次の code segment へと継続する. このとき通常レベルの code segment からは meta code segment への継続は隠蔽され, 通常レベルの code segment に直接継続しているように見えるべきである (図 \ref{fig:meta} の破線の継続). しかし既存の CbC では meta code segment への継続はサポートしておらず,これを実現するとリスト \ref{GearsCode} のようになり, meta code segment への継続を隠蔽することは出来ない. これらをスクリプトを用いることで リスト \ref{hideMeta} のように記述できるようになる. code segment から見ると直接次の code segment へ継続しているように見えるが, スクリプトを通すことで リスト \ref{GearsCode} のコードに変換されるので, きちんと meta code segment の処理も行われる. + +この変換は, meta code segment が通常レベルの code segment に継続する際に enum から成る code segment ID を利用して継続することを利用したものである. + +また, 同時に context の隠蔽も行っている. context は全ての code segment, data segment を管理しており, これに通常レベルの code segment から触れるのは好ましくないためこのようにした. + +\begin{figure}[htpb] + \begin{center} + \scalebox{0.45}{\includegraphics{fig/meta.pdf}} + \end{center} + \caption{Gears OS における code segment の継続} + \label{fig:meta} +\end{figure} + +\begin{lstlisting}[frame=lrbt,label=GearsCode,caption={CbC で実現する Gears OS コード例}] +__code meta(struct Context* context, enum Code next) { + goto (context->code[next])(context); +} + +__code code1_stub(struct Context* context) { + goto code1(context, &context->data[Allocate]->allocate); +} + +__code code1(struct Context* context, struct Allocate* allocate) { + allocate->size = sizeof(long); + allocator(context); + goto meta(context, Code2); +} + + +__code code2(struct Context* context, long* count) { + *count = 0; + goto meta(context, Code3); +} + +__code code2_stub(struct Context* context) { + goto code2(context, &context->data[Count]->count); +} +\end{lstlisting} + +\begin{lstlisting}[frame=lrbt,label=hideMeta,caption={meta code segment への継続の隠蔽}] +__code meta(struct Context* context, enum Code next) { + goto (context->code[next])(context); +} + +__code code1_stub(struct Context* context) { + goto code1(context, &context->data[Allocate]->allocate); +} + +__code code1(struct Allocate* allocate) { + allocate->size = sizeof(long); + allocator(); + goto code2(); +} + + +__code code2(long* count) { + *count = 0; + goto code3(); +} + +__code code2_stub(struct Context* context) { + goto code2(context, &context->data[Count]->count); +} +\end{lstlisting} + +\section{stub の自動生成} +もう一つの機能として stub の自動生成がある. 前節で, Gears OS では code segment は meta code segment に継続し, その後 code segment に継続すると述べたが, 正確には meta code segment から code segment に継続する際に stub という継続を挟む. stub では, code segment が必要とする data segment を context から取り出すという処理を行うもので, リスト \ref{GearsCode}, \ref{hideMeta} の code1\_stub, code2\_stub がそれにあたる. stub は code segment 毎に生成されるためこの自動生成を行うことで code segment の記述量を約半分にすることができる. meta code segment への継続, context の隠蔽, stub の生成全てを自動化した最終的なコードがリスト \ref{stubOmit} である. + +\begin{lstlisting}[frame=lrbt,label=stubOmit,caption={機械的な記述を取り除いた Gears OS のコード}] +__code meta(struct Context* context, enum Code next) { + goto (context->code[next])(context); +} + +__code code1(struct Allocate* allocate) { + allocate->size = sizeof(long); + allocator(); + goto code2(); +} + +__code code2(long* count) { + *count = 0; + goto code3(); +} +\end{lstlisting} + +改めて元のコードであるリスト \ref{GearsCode} と, スクリプトのサポートを受けるコードリスト \ref{stubOmit} を メタへの継続, stub による data segment の取り出しなど機械的な処理を記述する必要がなくなり CbC の記述が楽になっていることがわかる. 機械的な処理の自動化はコードを書く量を減らすだけでなく, 本来記述したい処理部分のプログラミングに集中することができるという利点も齎す. diff -r 24e4c08b4e35 -r ea7938131775 paper/fig/meta.graffle --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paper/fig/meta.graffle Tue Feb 09 14:31:42 2016 +0900 @@ -0,0 +1,974 @@ + + + + + ActiveLayerIndex + 0 + ApplicationVersion + + com.omnigroup.OmniGraffle6 + 169.5.0.253125 + + AutoAdjust + + BackgroundGraphic + + Bounds + {{0, 0}, {1118.4000244140625, 782.79998779296875}} + Class + SolidGraphic + ID + 2 + Style + + stroke + + Draws + NO + + + + BaseZoom + 0 + CanvasOrigin + {0, 0} + ColumnAlign + 1 + ColumnSpacing + 36 + CreationDate + 2014-02-10 06:36:22 +0000 + Creator + utah + DisplayScale + 1 in = 1 in + GraphDocumentVersion + 12 + GraphicsList + + + Class + LineGraphic + FontInfo + + Font + Helvetica + Size + 12 + + ID + 34 + Points + + {414, 72} + {468, 72} + + Style + + shadow + + Draws + NO + + stroke + + HeadArrow + 0 + Legacy + + LineType + 1 + Pattern + 1 + TailArrow + 0 + + + + + Class + LineGraphic + FontInfo + + Font + Helvetica + Size + 12 + + Head + + ID + 29 + Info + 2 + + ID + 33 + Points + + {189, 72} + {243, 72} + + Style + + shadow + + Draws + NO + + stroke + + HeadArrow + 0 + Legacy + + LineType + 1 + Pattern + 1 + TailArrow + 0 + + + + + Class + LineGraphic + FontInfo + + Font + Helvetica + Size + 12 + + ID + 32 + Points + + {585, 99} + {585, 135} + + Style + + shadow + + Draws + NO + + stroke + + HeadArrow + FilledArrow + Legacy + + LineType + 1 + TailArrow + 0 + + + + + Class + LineGraphic + FontInfo + + Font + Helvetica + Size + 12 + + ID + 31 + OrthogonalBarAutomatic + + OrthogonalBarPoint + {0, 0} + OrthogonalBarPosition + -1 + Points + + {414, 162} + {468, 162} + {468, 72} + {531, 72} + + Style + + shadow + + Draws + NO + + stroke + + HeadArrow + FilledArrow + Legacy + + LineType + 2 + TailArrow + 0 + + + + + Class + LineGraphic + FontInfo + + Font + Helvetica + Size + 12 + + ID + 30 + Points + + {360, 99} + {360, 135} + + Style + + shadow + + Draws + NO + + stroke + + HeadArrow + FilledArrow + Legacy + + LineType + 1 + TailArrow + 0 + + + + + Class + LineGraphic + FontInfo + + Font + Helvetica + Size + 12 + + ID + 29 + OrthogonalBarAutomatic + + OrthogonalBarPoint + {0, 0} + OrthogonalBarPosition + -1 + Points + + {189, 162} + {243, 162} + {243, 72} + {306, 72} + + Style + + shadow + + Draws + NO + + stroke + + HeadArrow + FilledArrow + Legacy + + LineType + 2 + TailArrow + 0 + + + + + Class + LineGraphic + FontInfo + + Font + Helvetica + Size + 12 + + ID + 27 + Points + + {135, 99} + {135, 135} + + Style + + shadow + + Draws + NO + + stroke + + HeadArrow + FilledArrow + Legacy + + LineType + 1 + TailArrow + 0 + + + + + Bounds + {{60.5, 198}, {83, 30}} + Class + ShapedGraphic + FitText + YES + Flow + Resize + ID + 26 + Style + + fill + + Draws + NO + + shadow + + Draws + NO + + stroke + + Draws + NO + + + Text + + Text + {\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf340 +{\fonttbl\f0\fnil\fcharset0 HelveticaNeue;} +{\colortbl;\red255\green255\blue255;} +\deftab720 +\pard\pardeftab720\qc\partightenfactor0 + +\f0\fs32 \cf0 meta level} + + Wrap + NO + + + Bounds + {{51.0625, 3}, {96, 30}} + Class + ShapedGraphic + FitText + YES + Flow + Resize + ID + 25 + Style + + fill + + Draws + NO + + shadow + + Draws + NO + + stroke + + Draws + NO + + + Text + + Text + {\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf340 +{\fonttbl\f0\fnil\fcharset0 HelveticaNeue;} +{\colortbl;\red255\green255\blue255;} +\deftab720 +\pard\pardeftab720\qc\partightenfactor0 + +\f0\fs32 \cf0 normal level} + + Wrap + NO + + + Bounds + {{531, 135}, {108, 54}} + Class + ShapedGraphic + FontInfo + + Font + Helvetica + Size + 9 + + HFlip + YES + ID + 24 + Magnets + + {1, 0.5} + {1, -0.5} + {-1, 0.5} + {-1, -0.5} + {0.5, 1} + {-0.5, 1} + {0.5, -1} + {-0.5, -1} + + Style + + fill + + Color + + b + 0.99999099999999996 + g + 0.99997400000000003 + r + 1 + + + shadow + + Draws + NO + + + Text + + Text + {\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf340 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\qc\partightenfactor0 + +\f0\fs28 \cf0 meta3} + VerticalPad + 0.0 + + + + Bounds + {{306, 135}, {108, 54}} + Class + ShapedGraphic + FontInfo + + Font + Helvetica + Size + 9 + + HFlip + YES + ID + 23 + Magnets + + {1, 0.5} + {1, -0.5} + {-1, 0.5} + {-1, -0.5} + {0.5, 1} + {-0.5, 1} + {0.5, -1} + {-0.5, -1} + + Style + + fill + + Color + + b + 0.99999099999999996 + g + 0.99997400000000003 + r + 1 + + + shadow + + Draws + NO + + + Text + + Text + {\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf340 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\qc\partightenfactor0 + +\f0\fs28 \cf0 meta2} + VerticalPad + 0.0 + + + + Bounds + {{81, 135}, {108, 54}} + Class + ShapedGraphic + FontInfo + + Font + Helvetica + Size + 9 + + HFlip + YES + ID + 22 + Magnets + + {1, 0.5} + {1, -0.5} + {-1, 0.5} + {-1, -0.5} + {0.5, 1} + {-0.5, 1} + {0.5, -1} + {-0.5, -1} + + Style + + fill + + Color + + b + 0.99999099999999996 + g + 0.99997400000000003 + r + 1 + + + shadow + + Draws + NO + + + Text + + Text + {\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf340 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\qc\partightenfactor0 + +\f0\fs28 \cf0 meta1} + VerticalPad + 0.0 + + + + Class + LineGraphic + FontInfo + + Font + Helvetica + Size + 12 + + ID + 21 + Points + + {684, 117} + {54, 117} + + Style + + shadow + + Draws + NO + + stroke + + HeadArrow + 0 + Legacy + + LineType + 1 + Pattern + 2 + TailArrow + 0 + + + + + Bounds + {{531, 45}, {108, 54}} + Class + ShapedGraphic + FontInfo + + Font + Helvetica + Size + 9 + + HFlip + YES + ID + 19 + Magnets + + {1, 0.5} + {1, -0.5} + {-1, 0.5} + {-1, -0.5} + {0.5, 1} + {-0.5, 1} + {0.5, -1} + {-0.5, -1} + + Style + + fill + + Color + + b + 0.99999099999999996 + g + 0.99997400000000003 + r + 1 + + + shadow + + Draws + NO + + + Text + + Text + {\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf340 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\qc\partightenfactor0 + +\f0\fs28 \cf0 code3} + VerticalPad + 0.0 + + + + Bounds + {{306, 45}, {108, 54}} + Class + ShapedGraphic + FontInfo + + Font + Helvetica + Size + 9 + + HFlip + YES + ID + 5 + Magnets + + {1, 0.5} + {1, -0.5} + {-1, 0.5} + {-1, -0.5} + {0.5, 1} + {-0.5, 1} + {0.5, -1} + {-0.5, -1} + + Style + + fill + + Color + + b + 0.99999099999999996 + g + 0.99997400000000003 + r + 1 + + + shadow + + Draws + NO + + + Text + + Text + {\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf340 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\qc\partightenfactor0 + +\f0\fs28 \cf0 code2} + VerticalPad + 0.0 + + + + Bounds + {{81, 45}, {108, 54}} + Class + ShapedGraphic + FontInfo + + Font + Helvetica + Size + 9 + + HFlip + YES + ID + 4 + Magnets + + {1, 0.5} + {1, -0.5} + {-1, 0.5} + {-1, -0.5} + {0.5, 1} + {-0.5, 1} + {0.5, -1} + {-0.5, -1} + + Style + + fill + + Color + + b + 0.99999099999999996 + g + 0.99997400000000003 + r + 1 + + + shadow + + Draws + NO + + + Text + + Text + {\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf340 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\qc\partightenfactor0 + +\f0\fs28 \cf0 code1} + VerticalPad + 0.0 + + + + GridInfo + + SnapsToGrid + YES + + GuidesLocked + NO + GuidesVisible + YES + HPages + 2 + ImageCounter + 1 + KeepToScale + + Layers + + + Lock + NO + Name + Layer 1 + Print + YES + View + YES + + + LayoutInfo + + Animate + NO + circoMinDist + 18 + circoSeparation + 0.0 + layoutEngine + dot + neatoLineLength + 0.20000000298023224 + neatoSeparation + 0.0 + twopiSeparation + 0.0 + + LinksVisible + NO + MagnetsVisible + NO + MasterSheets + + ModificationDate + 2016-02-09 02:10:43 +0000 + Modifier + utah + NotesVisible + NO + Orientation + 2 + OriginVisible + NO + PageBreaks + YES + PrintInfo + + NSBottomMargin + + float + 41 + + NSHorizonalPagination + + coded + BAtzdHJlYW10eXBlZIHoA4QBQISEhAhOU051bWJlcgCEhAdOU1ZhbHVlAISECE5TT2JqZWN0AIWEASqEhAFxlwCG + + NSLeftMargin + + float + 18 + + NSPaperSize + + size + {595.20001220703125, 841.79998779296875} + + NSPrintReverseOrientation + + coded + BAtzdHJlYW10eXBlZIHoA4QBQISEhAhOU051bWJlcgCEhAdOU1ZhbHVlAISECE5TT2JqZWN0AIWEASqEhAFxlwCG + + NSRightMargin + + float + 18 + + NSTopMargin + + float + 18 + + + PrintOnePage + + ReadOnly + NO + RowAlign + 1 + RowSpacing + 36 + SheetTitle + Canvas 1 + SmartAlignmentGuidesActive + YES + SmartDistanceGuidesActive + YES + UniqueID + 1 + UseEntirePage + + VPages + 1 + WindowInfo + + CurrentSheet + 0 + Expanded_Canvases + + Frame + {{252, -73}, {1263, 938}} + ShowInfo + + ShowRuler + + Sidebar + + SidebarWidth + 200 + TopSlabHeight + 250 + VisibleRegion + {{0, 0}, {749, 780}} + Zoom + 1 + ZoomValues + + + Canvas 1 + 1 + 1 + + + + + diff -r 24e4c08b4e35 -r ea7938131775 paper/fig/meta.pdf Binary file paper/fig/meta.pdf has changed diff -r 24e4c08b4e35 -r ea7938131775 paper/fig/meta.xbb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paper/fig/meta.xbb Tue Feb 09 14:31:42 2016 +0900 @@ -0,0 +1,8 @@ +%%Title: ./fig/meta.pdf +%%Creator: extractbb 20140317 +%%BoundingBox: 0 0 653 243 +%%HiResBoundingBox: 0.000000 0.000000 653.000000 243.000000 +%%PDFVersion: 1.3 +%%Pages: 1 +%%CreationDate: Tue Feb 9 11:23:59 2016 + diff -r 24e4c08b4e35 -r ea7938131775 paper/master_paper.pdf Binary file paper/master_paper.pdf has changed