07eb3ea722ffd9a54b5a973292bb8cfeff8ef0fc
[msc-thesis1617.git] / mtask.io.tex
1 Values can be assigned to all expressions that have an \CI{Upd} role. Examples
2 of such expressions are \glspl{SDS} and \gls{GPIO} pins. Moreover, class
3 extensions can be created for specific peripherals such as built-in
4 \glspl{LED}. The classes facilitating this are shown in
5 Listing~\ref{lst:sdsio}. In this way the assignment is the same for every
6 assignable entity.
7
8 \begin{lstlisting}[%
9 label={lst:sdsio},caption={Input/Output classes}]
10 :: DigitalPin = D0 | D1 | D2 | D3 | D4 | D5 |D6 | D7 | D8 | D9 | D10 | D11 | D12 | D13
11 :: AnalogPin = A0 | A1 | A2 | A3 | A4 | A5
12 :: UserLED = LED1 | LED2 | LED3
13
14 class dIO v where dIO :: DigitalPin -> v Bool Upd
15 class aIO v where aIO :: AnalogPin -> v Int Upd
16 class analogRead v where
17 analogRead :: AnalogPin -> v Int Expr
18 analogWrite :: AnalogPin (v Int p) -> v Int Expr
19 class digitalRead v where
20 digitalRead :: DigitalPin -> v Bin Expr
21 digitalWrite :: DigitalPin (v Bool p) -> v Int Expr
22
23 :: UserLED = LED1 | LED2 | LED3
24 class userLed v where
25 ledOn :: (v UserLED q) -> (v () Stmt)
26 ledOff :: (v UserLED q) -> (v () Stmt)
27
28 class assign v where
29 (=.) infixr 2 :: (v t Upd) (v t p) -> v t Expr | ...
30 \end{lstlisting}
31
32 One way of storing data in \gls{mTask}-\glspl{Task} is using \glspl{SDS}.
33 \glspl{SDS} serve as variables in \gls{mTask} and maintain their value across
34 executions. \glspl{SDS} can be used by multiple \glspl{Task} and can be used
35 to share data. The classes associated with \glspl{SDS} are listed in
36 Listing~\ref{lst:sdsclass}. The \CI{Main} type is introduced to box an
37 \gls{mTask} and make it recognizable by the type system by separating programs
38 and decorations such as \glspl{SDS}.
39
40 \begin{lstlisting}[%
41 label={lst:sdsclass},caption={\glspl{SDS} in \gls{mTask}}]
42 :: In a b = In infix 0 a b
43 :: Main a = {main :: a}
44
45 class sds v where
46 sds :: ((v t Upd)->In t (Main (v c s))) -> (Main (v c s)) | ...
47 \end{lstlisting}