add images, update intro, add iTasks intro
[msc-thesis1617.git] / methods.tex
1 \section{\acrlong{TOP}}
2 \gls{TOP} is a recent new programming paradigm implemented as
3 \gls{iTasks}\cite{achten_introduction_2015} in the pure lazy functional
4 language \gls{Clean}\cite{brus_cleanlanguage_1987}. \gls{iTasks} is a
5 \gls{EDSL} to model workflow tasks in the broadest sense. A \CI{Task} is just
6 a function that, given some state, returns the observable value of the
7 \CI{TaskValue}. A simple example is shown in Listing~\ref{lst:taskex}
8 accompanied with Figure~\ref{fig:taskex1},~\ref{fig:taskex2} and~%
9 \ref{fig:taskex3}.
10
11 \begin{lstlisting}[language=Clean,label={lst:taskex},%
12 caption={An example \gls{Task} for entering a name}]
13 :: Name = { firstname :: String
14 , lastname :: String
15 }
16
17 derive class iTask Name
18
19 enterInformation :: String [EnterOption m] -> (Task m) | iTask m
20
21 enterName :: Task Name
22 enterName = enterInformation "Enter your name" []
23 \end{lstlisting}
24
25 \begin{figure}[H]
26 \begin{subfigure}{.25\textwidth}
27 \centering
28 \includegraphics[width=.9\linewidth]{taskex1}
29 \caption{Initial interface}\label{fig:taskex1}
30 \end{subfigure}
31 \begin{subfigure}{.25\textwidth}
32 \centering
33 \includegraphics[width=.9\linewidth]{taskex2}
34 \caption{Incomplete entrance}\label{fig:taskex2}
35 \end{subfigure}
36 \begin{subfigure}{.25\textwidth}
37 \centering
38 \includegraphics[width=.9\linewidth]{taskex3}
39 \caption{Complete entry}\label{fig:taskex3}
40 \end{subfigure}
41 \caption{Example of a generated user interface}
42 \end{figure}
43
44 \section{\acrlong{EDSL}s}
45 \glspl{mTask} are expressed in a class based shallowly embedded \gls{EDSL}.
46 There are two main types of \glspl{EDSL}.
47 \todo{Small shallow embedded dsl intro}
48 \todo{Small deep embedded dsl}
49 \todo{Show that class based has the best of both worlds}
50
51 \section{Architecture}
52 \section{Devices}
53
54 The client code for the devices is compiled from one codebase. For a device to
55 be eligible for \glspl{mTask} it must be able to compile the shared codebase
56 and implement (part of) the device specific interface. The shared codebase only
57 uses standard \gls{C} and no special libraries or tricks are used. Therefore
58 the code is compilable for almost any device or system. Note that it is not
59 needed to implement a full interface\todo{handshake}. The full interface,
60 listed in Appendix~\label{app:device-interface}\todo{update interface listing},
61 also includes functions for accessing the peripherals that not every device
62 might have. Devices can choose what to implement by setting the correct macros
63 in the top of the file.
64 \todo{Supported devices}
65
66 \subsection{Specification}
67 Devices are stored in a record type and all devices in the system are stored in
68 a \gls{SDS} containing all devices. From the macro settings in the interface
69 file a profile is created for the device that describes the specification. When
70 a connection between the server and a client is established the server will
71 send a request for specification. The client will serialize his specs and send
72 it to the server so that the server knows what the client is capable of. The
73 exact specification is listed in Listing~\ref{lst:devicespec}
74
75 \begin{lstlisting}[language=Clean,label={lst:devicespec},
76 caption={Device specification for \glspl{mTask}}]
77 :: MTaskDeviceSpec =
78 {haveLed :: Bool
79 ,haveAio :: Bool
80 ,haveDio :: Bool
81 ,taskSpace :: Int // Bytes
82 ,sdsSpace :: Int // Bytes
83 }
84 \end{lstlisting}
85 \todo{Explain specification, combine task and share space}
86
87 \subsection{Communication}
88
89 \section{mTasks}
90 \subsection{\gls{EDSL}}
91 The \gls{mTask}-\gls{EDSL} contains several classes that need to be implemented
92 by a type for it to be an \gls{mTask}. For numeric and boolean arithmetic the
93 classes \texttt{arith} and \texttt{boolExpr} are available and listed in a
94 shortened version in Listing~\ref{lst:arithbool}. All classes are to be
95 implemented by types of kind \texttt{*->*->*} a type \texttt{v t p},
96 respectively a view with a type and the role.
97
98 \texttt{lit} lifts a constant to the \gls{mTask} domain. For a type to be a
99 valid \gls{mTask} type it needs to implement the \texttt{mTaskType} class. The
100 binary operators work as expected.
101
102 \begin{lstlisting}[language=Clean,label={lst:arithbool},
103 caption={Basic classes for expressions}]
104 class mTaskType a | toByteCode, fromByteCode, iTask, TC a
105
106 class arith v where
107 lit :: t -> v t Expr | mTaskType t
108 (+.) infixl 6 :: (v t p) (v t q) -> v t Expr | type, +, zero t & isExpr p & isExpr q
109 ...
110 class boolExpr v where
111 (&.) infixr 3 :: (v Bool p) (v Bool q) -> v Bool Expr | isExpr p & isExpr q
112 Not :: (v Bool p) -> v Bool Expr | isExpr p
113 ...
114 (==.) infix 4 :: (v a p) (v a q) -> v Bool Expr | ==, toCode a & isExpr p & isExpr q
115 \end{lstlisting}
116
117
118 \subsection{Tasks}
119
120 \subsection{Shares}
121 Shares can live on multiple clients at the same time. For every share created
122 for an \gls{mTask} a real \gls{SDS} is created that mirrors the value on the
123 client. All shares currently in use are stored in a system-wide \gls{SDS} in
124 such a way that the actual share can be retrieved at any moment. All shares
125 have a unique numeric identifier and an initial value.
126
127 \begin{lstlisting}[language=Clean,label={lst:sharespec}, caption={\acrlong{SDS}}]
128 :: BCValue = E.e: BCValue e & mTaskType e
129 :: MTaskShareType = MTaskWithShare String | MTaskLens String
130 :: MTaskShare =
131 {withTask :: [String]
132 ,withDevice :: [String]
133 ,identifier :: Int
134 ,realShare :: MTaskShareType
135 ,value :: BCValue
136 }
137
138 sdsStore :: Shared [MTaskShare]
139 \end{lstlisting}
140 \todo{Do something with the sharetype}
141
142 \subsection{Communication}
143 %\todo{Handshake, device specification sending, spec.c}
144 %\todo{mTaskDevice class interface}
145
146 \section{mTasks}
147 \subsection{\gls{EDSL}}
148 \todo{Show the classes}
149
150 \subsection{Shares}
151 \todo{Show the types and why}
152
153 Shares are used to store the values
154
155 Shares all have