\begin{document}
\input{subfileprefix}
-\chapter{The \texorpdfstring{\gls{MTASK}}{mTask} \texorpdfstring{\glsxtrshort{DSL}}{DSL}}%
+\chapter{The \texorpdfstring{\gls{MTASK}}{mTask} language}%\texorpdfstring{\glsxtrshort{DSL}}{DSL}}%
\label{chp:mtask_dsl}
\begin{chapterabstract}
-This chapter introduces the \gls{MTASK} language more technically by:
+ \noindent This chapter introduces the \gls{TOP} language \gls{MTASK} language by:
\begin{itemize}
\item introducing the setup of the \gls{EDSL};
- \item and showing the language interface and examples for:
- \begin{itemize}
- \item data types
- \item expression
- \item task and their combinators.
- \end{itemize}
+ \item and showing the language interface and examples for the type system, data types, expressions, tasks and their combinators.
\end{itemize}
\end{chapterabstract}
The simulator converts the expression to a ready-for-work \gls{ITASK} simulation in which the user can inspect and control the simulated peripherals and see the internal state of the tasks.
\item[Byte code compiler]
- The compiler compiles the \gls{MTASK} program at runtime to a specialised byte code.
- Using a handful of integration functions and tasks, \gls{MTASK} tasks can be executed on microcontrollers and integrated in \gls{ITASK} as if they were regular \gls{ITASK} tasks.
+ The compiler compiles the \gls{MTASK} program to a specialised byte code.
+ Using a handful of integration functions and tasks (see \cref{chp:integration_with_itask}), \gls{MTASK} tasks can be executed on microcontrollers and integrated in \gls{ITASK} as if they were regular \gls{ITASK} tasks.
Furthermore, with special language constructs, \glspl{SDS} can be shared between \gls{MTASK} and \gls{ITASK} programs.
\end{description}
class basicType t | type t where ...
class mtask v | expr, ..., int, real, long v
-
\end{lstClean}
Sensors, \glspl{SDS}, functions, \etc{} may only be defined at the top level.
someTask =
sensor1 config1 \sns1->
sensor2 config2 \sns2->
- sds \s1=initial
- In liftsds \s2=someiTaskSDS
- In fun \fun1= ( ... )
- In fun \fun2= ( ... )
+ sds \s1 = initialValue
+ In liftsds \s2 = someiTaskSDS
+ In fun \fun1= ( ... )
+ In fun \fun2= ( ... )
In { main = mainexpr }
\end{lstClean}
\section{Expressions}\label{sec:expressions}
+This section shows all \gls{MTASK} constructs for exppressions.
\Cref{lst:expressions} shows the \cleaninline{expr} class containing the functionality to lift values from the host language to the \gls{MTASK} language (\cleaninline{lit}); perform number and boolean arithmetics; do comparisons; and conditional execution.
For every common boolean and arithmetic operator in the host language, an \gls{MTASK} variant is present, suffixed by a period to not clash with \gls{CLEAN}'s builtin operators.
\Gls{MTASK} is shallowly embedded in \gls{CLEAN} and the terms are constructed at runtime.
This means that \gls{MTASK} programs can also be tailor-made at runtime or constructed using \gls{CLEAN} functions maximising the linguistic reuse \citep{krishnamurthi_linguistic_2001}
-\cleaninline{approxEqual} in \cref{lst:example_macro} performs an approximate equality---albeit not taking into account all floating point pecularities---.
+\cleaninline{approxEqual} in \cref{lst:example_macro} performs a simple approximate equality---albeit without taking into account all floating point pecularities.
When calling \cleaninline{approxEqual} in an \gls{MTASK} function, the resulting code is inlined.
\begin{lstClean}[label={lst:example_macro},caption={Example linguistic reuse in the \gls{MTASK} language.}]
\end{lstClean}
\subsection{Data types}
-Most of \gls{CLEAN}'s basic types have been mapped on \gls{MTASK} types.
+Most of \gls{CLEAN}'s fixed-size basic types are mapped on \gls{MTASK} types.
However, it can be useful to have access to compound types as well.
All types in \gls{MTASK} must have a fixed size representation on the stack so sum types are not (yet) supported.
While it is possible to lift types using the \cleaninline{lit} function, you cannot do anything with the types besides passing them around but they are being produced by some parallel task combinators (see \cref{sssec:combinators_parallel}).
% VimTeX: SynIgnore off
\section{Tasks and task combinators}\label{sec:top}
+This section describes \gls{MTASK}'s task language.
\Gls{MTASK}'s task language can be divided into three categories, namely
\begin{enumerate*}
\item Basic tasks, in most \gls{TOP} systems, the basic tasks are called editors, modelling the interactivity with the user.
\end{enumerate*}
As \gls{MTASK} is integrated with \gls{ITASK}, the same stability distinction is made for task values.
-A task in \gls{MTASK} is denoted by the \gls{DSL} type synonym shown in \cref{lst:task_type}.
+A task in \gls{MTASK} is denoted by the \gls{DSL} type synonym shown in \cref{lst:task_type}, an expression of the type \cleaninline{TaskValue a} in interpretation \cleaninline{v}.
\begin{lstClean}[label={lst:task_type},caption={Task type in \gls{MTASK}.}]
:: MTask v a :== v (TaskValue a)
+
+// From the iTask library
:: TaskValue a
= NoValue
| Value a Bool
\subsubsection{Peripherals}\label{sssec:peripherals}
For every sensor or actuator, basic tasks are available that allow interaction with the specific peripheral.
The type classes for these tasks are not included in the \cleaninline{mtask} class collection as not all devices nor all language interpretations have such peripherals connected.
-%\todo{Historically, peripheral support has been added \emph{by need}.}
\Cref{lst:dht,lst:gpio} show the type classes for \glspl{DHT} sensors and \gls{GPIO} access.
Other peripherals have similar interfaces, they are available in the \cref{sec:aux_peripherals}.
\end{lstClean}
\subsection{Task combinators}
-Task combinators are used to combine multiple tasks into one to describe workflows.
+Task combinators are used to combine multiple tasks to describe workflows.
There are three main types of task combinators, namely:
\begin{enumerate*}
\item Sequential combinators that execute tasks one after the other, possibly using the result of the left hand side.
| Always (MTask v u)
\end{lstClean}
-\todo{more examples step?}
-
The following listing shows an example of a step in action.
The \cleaninline{readPinBin} function produces an \gls{MTASK} task that classifies the value of an analogue pin into four bins.
It also shows that the nature of embedding allows the host language to be used as a macro language.
\begin{lstClean}[caption={Semantics of the\\conjunction combinator.},label={lst:semantics_con}]
con :: (TaskValue a) (TaskValue b)
-> TaskValue (a, b)
-con NoValue r = NoValue
-con l NoValue = NoValue
+con NoValue r = NoValue
+con l NoValue = NoValue
con (Value l ls) (Value r rs)
= Value (l, r) (ls && rs)
\begin{lstClean}[caption={Semantics of the\\disjunction combinator.},label={lst:semantics_dis}]
dis :: (TaskValue a) (TaskValue a)
-> TaskValue a
-dis NoValue r = r
-dis l NoValue = l
+dis NoValue r = r
+dis l NoValue = l
dis (Value l ls) (Value r rs)
| rs = Value r True
| otherwise = Value l ls