remove student number
[ri1617.git] / architecture / mtasks.tex
1 \subsection{mTask}
2 \mTask{}s are written in a shallowly embedded class-based DSL that due to
3 the nature of it can be easily extended in language and in view. Currently
4 there is a view for generating \emph{C}-code and a view for simulating
5 \mTask{}s using \iTasks{}. Currently the \mTask{} code includes
6 functionality for running a small task server on the embedded device. These
7 features will not be used in this project as the microcontroller will serve a
8 slightly different purpose, namely serve as a task executioner instead of a
9 server. The bytecode compilation also adds a class that represents all things
10 compilable in bytecode to make sure all the basic types can be compiled. Both
11 signatures are shown in Listing~\ref{lst:bytecode}. We only use a subset of the
12 original \mTask{} definitions because we do not use the functionality for
13 managing tasks.
14
15 \subsection{Classes}
16 To make the DSL easily extendable with functionality without losing
17 extendability of views it is defined as a set of classes that can be
18 implemented by any data type.
19
20 Arithmetic operations and boolean operators are defined respectively in the
21 \CI{arith} and \CI{boolExpr} class. Note that the functions defined by the
22 class have some restrictions for specific views. This is basically the
23 translation from Clean basic type to the representation in the data type.
24
25 \begin{lstlisting}[language=Clean,label={lst:arith}]
26 class arith v where
27 lit :: t -> v t Expr | toCode t & toByteCode t
28 (+.) infixl 6 :: (v t p) (v t q) -> v t Expr | type, +, zero t & isExpr p & isExpr q
29 (-.) infixl 6 :: (v t p) (v t q) -> v t Expr | type, -, zero t & isExpr p & isExpr q
30 (*.) infixl 7 :: (v t p) (v t q) -> v t Expr | type, *, zero, one t & isExpr p & isExpr q
31 (/.) infixl 7 :: (v t p) (v t q) -> v t Expr | type, / t & isExpr p & isExpr q
32
33 class boolExpr v where
34 (&.) infixr 3 :: (v Bool p) (v Bool q) -> v Bool Expr | isExpr p & isExpr q
35 (|.) infixr 2 :: (v Bool p) (v Bool q) -> v Bool Expr | isExpr p & isExpr q
36 Not :: (v Bool p) -> v Bool Expr | isExpr p
37 (==.) infix 4 :: (v a p) (v a q) -> v Bool Expr | ==, toCode a & isExpr p & isExpr q
38 (!=.) infix 4 :: (v a p) (v a q) -> v Bool Expr | ==, toCode a & isExpr p & isExpr q
39 (<.) infix 4 :: (v a p) (v a q) -> v Bool Expr | <, Ord, toCode a & isExpr p & isExpr q
40 (>.) infix 4 :: (v a p) (v a q) -> v Bool Expr | <, Ord, toCode a & isExpr p & isExpr q
41 (<=.) infix 4 :: (v a p) (v a q) -> v Bool Expr | <, Ord, toCode a & isExpr p & isExpr q
42 (>=.) infix 4 :: (v a p) (v a q) -> v Bool Expr | <, Ord, toCode a & isExpr p & isExpr q
43 \end{lstlisting}
44
45
46 In the future a state will probably need to be added to the \CI{Bytecode}
47 type to keep track of some information during bytecode compilation.
48
49 \begin{lstlisting}[language=Clean,label={lst:bytecode}]
50 :: BC
51 = BCNop
52 | BCPush Int
53 | BCPop
54 ...
55
56 :: ByteCode a p = BC [BC]
57 class toByteCode a :: a -> [Char]
58 \end{lstlisting}