\documentclass[../thesis.tex]{subfiles}
\input{subfilepreamble}
+\setcounter{chapter}{-1}
\begin{document}
\chapter{Prelude}%
\label{chp:introduction}
\begin{chapterabstract}
- This chapter:
- \begin{itemize}
- \item introduces the topic and research ventures of this dissertation;
- \item shows a reading guide;
- \item provides background material on the \glsxtrlong{IOT}, \glsxtrlongpl{DSL}, \glsxtrlong{TOP}, \gls{ITASK}, and \gls{MTASK}.
- \item and concludes with a detailed overview of the contributions.
- \end{itemize}
+ This chapter is the introduction of the dissertation and to the thesis.
+ It first provides a general introduction to the topics and research venues taken in this document, ending with a reading guide.
+ The sections that follow provide background material on the \glsxtrlong{IOT}, \glsxtrlongpl{DSL}, \glsxtrlong{TOP}, \gls{ITASK}, and \gls{MTASK}.
+ Finally, it provides a detailed overview of the contributions.
\end{chapterabstract}
There are at least 13.4 billion devices connected to the internet at the time of writing\footnote{\url{https://transformainsights.com/research/tam/market}, accessed on: \formatdate{13}{10}{2022}}.
Each and every one of those devices senses, acts, or otherwise interacts with people, other computers, and the environment surrounding us.
-Even though there is a substantial variety among these devices, they have one thing in common: they are all computers to some degree and hence require software to operate.
+Even though there is a substantial variety among these devices, they all have one thing in common: they are all computers and hence require software to operate.
An increasing amount of these connected devices are so-called \emph{edge devices} that operate in the \gls{IOT}.
Typically, these edge devices are powered by microcontrollers.
Said microcontrollers contain integrated circuits accommodating a microprocessor designed for use in embedded applications.
-Typical edge devices are therefore tiny in size; have little memory; contain a slow, but energy-efficient processor; and allow for a lot of connectivity to connect peripherals such as sensors and actuators to interact with their surroundings.
+Typical edge devices are therefore tiny in size; have little memory; contain a slow, but energy-efficient processor; and allow for a lot of connectivity to connect peripherals such as sensors and actuators in order to interact with their surroundings.
%
%\begin{figure}[ht]
% \centering
% \label{fig:esp_prototype}
%\end{figure}
+Programming and maintaining \gls{IOT} systems is a complex and error-prone process.
An \gls{IOT} programmer has to program each device and their interoperation using different programming paradigms, programming languages, and abstraction levels resulting in semantic friction.
-Programming and maintaining \gls{IOT} systems is therefore a very complex and an error-prone process.
This thesis describes the research carried out around taming these complex \gls{IOT} systems using \gls{TOP}.
-\Gls{TOP} is an innovative tierless programming paradigm for programming multi-tier interactive systems using a single declarative specification of the work that needs to be done.
-By utilising advanced compiler technologies, much of the internals, communication, and interoperation of the multi-tiered applications is automatically generated.
-The result of this compilation is a ready-for-work application.
-For example, the \gls{TOP} system \gls{ITASK} can be used to program all layers of a distributed web application from a single source.
-Unfortunately, because the abstraction level is so high, the hardware requirements are too excessive for such systems to be suitable for the average edge device.
+\Gls{TOP} is an innovative tierless programming paradigm for interactive multi-tier systems.
+By utilising advanced compiler technologies, much of the internals, communication, and interoperation of the applications is automatically generated.
+From a single declarative specification of the work that needs to be done, the compiler makes a ready-for-work application.
+For example, the \gls{TOP} system \gls{ITASK} can be used to program all layers of a multi-user distributed web applications from a single source specification.
+Unfortunately, because the abstraction level is so high, the hardware requirements are too excessive for such systems to be suitable for the average \gls{IOT} edge device.
This is where \glspl{DSL} are brought into play.
\Glspl{DSL} are programming languages created with a specific domain in mind.
Consequently, jargon does not have to be expressed in the language itself, but they can be built-in features.
-As a result, the hardware requirements can be drastically lower, even with high levels of abstraction.
+As a result, the hardware requirements can be drastically lower, even with high levels of abstraction for the specified domain.
To bridge the gap between the \gls{IOT} edge devices, the \gls{MTASK} \gls{DSL} is used.
\Gls{MTASK} is a novel programming language for programming \gls{IOT} edge devices using \gls{TOP}.
As it is integrated with \gls{ITASK}, it allows for all layers of an \gls{IOT} application to be programmed from a single source.
+\todo{Kan deze \P\ weg? Aan\-ge\-zien het ook al in de volgende sectie staat}
-\section{Reading guide}
+\section{Reading guide}%
+\label{lst:reading_guide}
The thesis is structured as a purely functional rhapsody.
On Wikipedia, a musical rhapsody is defined as follows \citep{wikipedia_contributors_rhapsody_2022}:
\begin{quote}\emph{%
Standalone source code listings are marked by the programming language used, e.g.\ \gls{CLEAN}\footnotemark, \gls{HASKELL}, \gls{CPP}, \etc.
\footnotetext{\Cref{chp:clean_for_haskell_programmers} contains a guide for \gls{CLEAN} tailored to \gls{HASKELL} programmers.}
-\section{\texorpdfstring{\Glsxtrlong{IOT}}{Internet of things}}\label{sec:back_iot}
+\section{\texorpdfstring{\Glsxtrlong{IOT}}{Internet of things}}%
+\label{sec:back_iot}
The \gls{IOT} is growing rapidly and it is changing the way people and machines interact with the world.
While the term \gls{IOT} briefly gained interest around 1999 to describe the communication of \gls{RFID} devices \citep{ashton_internet_1999,ashton_that_2009}, it probably already popped up halfway the eighties in a speech by \citet{peter_t_lewis_speech_1985}:
When describing \gls{IOT} systems, a tiered---or layered---architecture is often used for compartmentalisation.
The number of tiers heavily depends on the required complexity of the model but for the intents and purposes of this thesis, the layered architecture as shown in \cref{fig:iot-layers} is used.
-\begin{figure}[ht]
+\begin{figure}
\centering
\includestandalone{iot-layers}
\caption{A layered \gls{IOT} architecture.}%
Interpretation always comes with an overhead, making it challenging to create them for small edge devices.
However, the hardware requirements can be reduced by embedding domain-specific data into the programming language to be interpreted, so called \glspl{DSL}.
-\section{\texorpdfstring{\Glsxtrlongpl{DSL}}{Domain-specific languages}}\label{sec:back_dsl}
+\section{\texorpdfstring{\Glsxtrlongpl{DSL}}{Domain-specific languages}}%
+\label{sec:back_dsl}
% General
-Programming languages can be divided up into two categories: \glspl{DSL}\footnote{Historically \glsxtrshortpl{DSL} have been called DSELs as well.} and \glspl{GPL} \citep{fowler_domain_2010}.
+Programming languages can be divided up into two categories: \glspl{DSL}\footnotemark\ and \glspl{GPL} \citep{fowler_domain_2010}.
+\footnotetext{Historically \glsxtrshortpl{DSL} have been called DSELs as well.}
Where \glspl{GPL} are not made with a demarcated area in mind, \glspl{DSL} are tailor-made for a specific domain.
-Writing idiomatic domain-specific code in an \gls{DSL} is easy but this may come at the cost of the \gls{DSL} being less expressive to an extent that it may not even be Turing complete.
+Writing idiomatic domain-specific code in a \gls{DSL} is easy but this may come at the cost of the \gls{DSL} being less expressive to an extent that it may not even be Turing complete.
\Glspl{DSL} come in two main flavours: standalone and embedded (\cref{sec:standalone_embedded})\footnote{Standalone and embedded are also called external and internal respectively.} of which \glspl{EDSL} can further be classified into heterogeneous and homogeneous languages (\cref{sec:hetero_homo}).
This hyponymy is shown in \cref{fig:hyponymy_of_dsls}.
-\begin{figure}[ht]
+\begin{figure}
\centering
\includestandalone{hyponymy_of_dsls}
\caption{A hyponymy of \glspl{DSL} (adapted from \citet[\citepage{2}]{mernik_extensible_2013})}%
\label{fig:hyponymy_of_dsls}
\end{figure}
-\subsection{Standalone and embedded}\label{sec:standalone_embedded}
+\subsection{Standalone and embedded}%
+\label{sec:standalone_embedded}
\glspl{DSL} where historically created as standalone languages, meaning that all machinery is developed solely for the language.
The advantage of this approach is that the language designer is free to define the syntax and type system of the language as they wish, not being restricted by any constraint.
Unfortunately it also means that they need to develop a compiler or interpreter for the language, making standalone \glspl{DSL} costly to create.
Furthermore, \gls{DSL} errors shown to the programmer may be larded with host language errors, making it difficult for a non-expert of the host language to work with the \gls{DSL}.
\Gls{FP} languages are especially suitable for hosting embedded \glspl{DSL} because they often have strong and versatile type systems, minimal but flexible syntax and offer referential transparency.
-\subsection{Heterogeneity and homogeneity}\label{sec:hetero_homo}
+\subsection{Heterogeneity and homogeneity}%
+\label{sec:hetero_homo}
\Citet{tratt_domain_2008} applied a notion from metaprogramming \citep{sheard_accomplishments_2001} to \glspl{EDSL} to define homogeneity and heterogeneity of \glspl{EDSL} as follows:
\begin{quote}
\Gls{ITASK} runs in its host language as well so it is a homogeneous \gls{DSL}.
Tasks written using \gls{MTASK} are serialised and executed on \gls{IOT} edge devices and it is therefore a heterogeneous \gls{DSL}.
-\section{\texorpdfstring{\Glsxtrlong{TOP}}{Task-oriented programming}}\label{sec:back_top}
+\section{\texorpdfstring{\Glsxtrlong{TOP}}{Task-oriented programming}}%
+\label{sec:back_top}
\Gls{TOP} is a recent declarative programming paradigm for modelling interactive systems \citep{plasmeijer_task-oriented_2012}.
\Citet{steenvoorden_tophat_2022} defines two instruments for \gls{TOP}: \gls{TOP} languages and \gls{TOP} engines.
The language is the \emph{formal} language for specifying interactive systems.
From the data types, utilising various \emph{type-parametrised} concepts, all other aspects are handled automatically (see \cref{fig:tosd}).
This approach to software development is called \gls{TOSD} \citep{wang_maintaining_2018}.
-\begin{figure}[ht]
+\begin{figure}
\centering
\begin{subfigure}[t]{.5\textwidth}
\centering
\includestandalone{tosd}
\caption{\Gls{TOSD} approach.}
\end{subfigure}
- \caption{Separation of concerns in a traditional setting compared to \gls{TOSD} (adapted from~\cite[\citepage{20}]{wang_maintaining_2018}).}%
+ \caption{Separation of concerns in a traditional setting compared to \gls{TOSD} (adapted from \citep[\citepage{20}]{wang_maintaining_2018}).}%
\label{fig:tosd}
\end{figure}
The \gls{UOD} is explicitly and separately modelled by the relations that exist in the functions of the host language.
\end{description}
-Applying the concepts of \gls{LSOC} to \gls{IOT} systems can broadly be done in two ways:
+Applying the concepts of \gls{LSOC} to \gls{IOT} systems can be done in two ways.
Firstly, edge devices can be seen as simple resources, thus accessed through the resource access layer.
The second view is that edge devices contain miniature \gls{LSOC} systems in itself as well.
In \gls{TOSD} the same can be applied.
The individual components in the miniature systems, the tasks, the \glspl{SDS}, are connected to the main system.
-%\todo[inline]{Is deze \P{} duidelijk genoeg?}
+\todo{Is deze \P\ dui\-de\-lijk genoeg of \"uberhaupt nodig?}
\subsection{\texorpdfstring{\Gls{ITASK}}{ITask}}
The concept of \gls{TOP} originated from the \gls{ITASK} framework, a declarative interactive systems language and \gls{TOP} engine for defining multi-user distributed web applications implemented as an \gls{EDSL} in the lazy pure \gls{FP} language \gls{CLEAN} \citep{plasmeijer_itasks:_2007,plasmeijer_task-oriented_2012}.
Only when the user enters a complete value in the web editor, then the continue button enables and the result can be viewed.
Special combinators (e.g.\ \cleaninline{@>>} at \cref{lst:task_ui}) are used to tweak the \gls{UI} so that informative labels are displayed.
-\begin{figure}[ht]
+\begin{figure}
\includegraphics[width=.325\linewidth]{person0g}
\includegraphics[width=.325\linewidth]{person1g}
\includegraphics[width=.325\linewidth]{person2g}
In {main = blink true}[+\label{lst:intro:mtask_to}+]
\end{lstClean}
+\todo{Zal ik hier nog een soort conclusie maken van \gls{MTASK}.}
+
\subsection{Other \texorpdfstring{\glsxtrshort{TOP}}{TOP} languages}
While \gls{ITASK} conceived \gls{TOP}, it is not the only \gls{TOP} system.
Some \gls{TOP} systems arose from Master's and Bachelor's thesis projects.
Some \gls{TOP} languages were created to solve a practical problem.Toppyt \citep{lijnse_toppyt_2022} is a general purpose \gls{TOP} language written in \gls{PYTHON} used to host frameworks for modelling C2 systems, and hTask \citep{lubbers_htask_2022}, a vessel for experimenting with asynchronous \glspl{SDS}.
Finally there are \gls{TOP} languages with strong academic foundations.
\Gls{TOPHAT} is a fully formally specified \gls{TOP} language designed to capture the essence of \gls{TOP} formally \citep{steenvoorden_tophat_2019}.
-Such a formal specification allows for symbolic execution, hint generation, but also the translation to \gls{ITASK} for actually performing the work\citep[\citesection{G.3}]{steenvoorden_tophat_2022}.
+Such a formal specification allows for symbolic execution, hint generation, but also the translation to \gls{ITASK} for actually performing the work \citep{steenvoorden_tophat_2022}.
-\section{Contributions}\label{sec:contributions}
-This section provides a thorough overview of the relation to publications and the scientific contributions of the episodes and chapters.
+\section{Contributions}%
+\label{sec:contributions}
+\todo{Dit heb ik sterk ingekort. Ok\'e?}
+This section provides a thorough overview of the relation between the scientific publications and the episodes and chapters.
\subsection{\Fullref{prt:dsl}}
The \gls{MTASK} system is a heterogeneous \gls{EDSL} and during the development of it, several novel basal techniques for embedding \glspl{DSL} in \gls{FP} languages have been found.
-This episode is a paper based episodes on these techniques.
+This episode is paper based.
\Cref{chp:classy_deep_embedding} is based on the paper \emph{Deep Embedding with Class} \citep{lubbers_deep_2022}.
-While supervising \citeauthor{amazonas_cabral_de_andrade_developing_2018}'s \citeyear{amazonas_cabral_de_andrade_developing_2018} Master's thesis, focussing on an early version of \gls{MTASK}, a seed was planted for a novel deep embedding technique for \glspl{DSL} where the resulting language is extendible both in constructs and in interpretation using type classes and existential data types.
-Slowly the ideas organically grew to form the technique shown in the paper.
-The related work section is updated with the research found only after publication.
+It shows a novel deep embedding technique for \glspl{DSL} where the resulting language is extendible both in constructs and in interpretation just using type classes and existential data types\footnotemark.
+\footnotetext{%
+The related work section is updated with the research found after publication.
\Cref{sec:classy_reprise} was added after publication and contains a (yet) unpublished extension of the embedding technique for reducing the required boilerplate at the cost of requiring some advanced type system extensions.
+}
\Cref{chp:first-class_datatypes} is based on the paper \emph{First-Class Data Types in Shallow Embedded Domain-Specific Languages} \citep{lubbers_first-class_2022}.
It shows how to inherit data types from the host language in \glspl{EDSL} using metaprogramming by providing a proof-of-concept implementation using \gls{HASKELL}'s metaprogramming system: \glsxtrlong{TH}.
-Besides showing the result, the paper also serves as a gentle introduction to using \glsxtrlong{TH} and contains a thorough literature study on research that uses \glsxtrlong{TH}.
+Besides showing the result, the paper also serves as a gentle introduction to, and contains a thorough literature study on \glsxtrlong{TH}.
%The research in this paper and writing the paper was performed by me, though there were weekly meetings with Pieter Koopman and Rinus Plasmeijer in which we discussed and refined the ideas.
-\subsection{\nameref{prt:top}}
-This is a monograph compiled from the following papers and revised lecture notes on \gls{MTASK}.
-It provides a gentle introduction to all aspects of the \gls{MTASK} system and \gls{TOP} for the \gls{IOT}.
+\subsection{\Fullref{prt:top}}
+There were many papers and revised lecture notes published on the design, implementation and usage of \gls{MTASK}.
+This episode is a monograph compiled from the following publications and shows all aspects of the \gls{MTASK} system and \gls{TOP} for the \gls{IOT}.
+\todo{Hier een over\-zicht van de chapters geven?}
\begin{itemize}
\item \emph{A Task-Based \glsxtrshort{DSL} for Microcomputers} \citep{koopman_task-based_2018}.
This is the initial \gls{TOP}\slash{}\gls{MTASK} paper.
It provides an overview of the initial \gls{TOP} \gls{MTASK} language and shows first versions of some of the interpretations.
- \item \emph{Task Oriented Programming for the \glsxtrlong{IOT}} \citep{lubbers_task_2018}.
-
- This paper was an extension of my Master's thesis \citep{lubbers_task_2017}.
+ \item \emph{Task Oriented Programming for the Internet of Things} \citep{lubbers_task_2018}\footnotetext{This work is an extension of my Master's thesis \citep{lubbers_task_2017}.}.
It shows how a simple imperative variant of \gls{MTASK} was integrated with \gls{ITASK}.
While the language was a lot different from later versions, the integration mechanism is still used in \gls{MTASK} today.
% \paragraph{Contribution}
% The research in this paper and writing the paper was performed by me, though there were weekly meetings with Pieter Koopman and Rinus Plasmeijer in which we discussed and refined the ideas.
- \item \emph{Multitasking on Microcontrollers using Task Oriented Programming} \citep{lubbers_multitasking_2019}\footnote{%
- This work acknowledges the support of the ERASMUS+ project ``Focusing Education on Composability, Comprehensibility and Correctness of Working Software'', no. 2017--1--SK01--KA203--035402
- }.
-
- This paper is a short paper on the multitasking capabilities of \gls{MTASK} comparing it to traditional multitasking methods for \gls{ARDUINO}.
+ \item \emph{Multitasking on Microcontrollers using Task Oriented Programming} \citep{lubbers_multitasking_2019}\footnote{This work acknowledges the support of the \erasmusplus{} project ``Focusing Education on Composability, Comprehensibility and Correctness of Working Software'', no.\ 2017--1--SK01--KA203--035402.}.
+ This is a short paper on the multitasking capabilities of \gls{MTASK} comparing it to traditional multitasking methods for \gls{ARDUINO}.
% \paragraph{Contribution}
% The research in this paper and writing the paper was performed by me, though there were weekly meetings with Pieter Koopman and Rinus Plasmeijer.
\item \emph{Simulation of a Task-Based Embedded Domain Specific Language for the Internet of Things} \citep{koopman_simulation_2018}\footnotemark[\value{footnote}].
-
These revised lecture notes are from a course on the \gls{MTASK} simulator was provided at the 2018 \gls{CEFP}\slash{}\gls{3COWS} winter school in Ko\v{s}ice, Slovakia.
% \paragraph{Contribution}
% Pieter Koopman wrote and taught it, I helped with the software and research.
\item \emph{Writing Internet of Things Applications with Task Oriented Programming} \citep{lubbers_writing_2019}\footnotemark[\value{footnote}].
-
- These revised lecture notes are from a course on programming in \gls{IOT} systems using \gls{MTASK} provided at the 2019 \gls{CEFP}\slash{}\gls{3COWS} summer school in Budapest, Hungary.
+ These revised lecture notes are from a course on programming \gls{IOT} systems using \gls{MTASK} provided at the 2019 \gls{CEFP}\slash{}\gls{3COWS} summer school in Budapest, Hungary.
% \paragraph{Contribution}
% Pieter Koopman prepared and taught half of the lecture and supervised the practical session.
% I taught the other half of the lecture, wrote the lecture notes, made the assignments and supervised the practical session.
\item \emph{Interpreting Task Oriented Programs on Tiny Computers} \citep{lubbers_interpreting_2019}.
-
- This paper shows an implementation for \gls{MTASK} for microcontrollers.
+ This paper shows an implementation of the byte code compiler and \gls{RTS} of \gls{MTASK}.
% \paragraph{Contribution}
% The research in this paper and writing the paper was performed by me, though there were weekly meetings with Pieter Koopman and Rinus Plasmeijer.
\item \emph{Reducing the Power Consumption of IoT with Task-Oriented Programming} \citep{crooijmans_reducing_2022}.
-
This paper shows how to create a scheduler so that devices running \gls{MTASK} tasks can go to sleep more automatically and how interrupts are incorporated in the language.
% \paragraph{Contribution}
% The research was carried out by \citet{crooijmans_reducing_2021} during his Master's thesis.
% I did the daily supervision and helped with the research, Pieter Koopman was the formal supervisor and wrote most of the paper.
- \item \emph{Green Computing for the Internet of Things} \citep{lubbers_green_2022}\footnote{
- This work acknowledges the support of the Erasmus+ project ``SusTrainable---Promoting Sustainability as a Fundamental Driver in Software Development Training and Education'', no. 2020--1--PT01--KA203--078646}.
-
+ \item \emph{Green Computing for the Internet of Things} \citep{lubbers_green_2022}\footnote{This work acknowledges the support of the \erasmusplus{} project ``SusTrainable---Promoting Sustainability as a Fundamental Driver in Software Development Training and Education'', no.\ 2020--1--PT01--KA203--078646.}.
These revised lecture notes are from a course on sustainable \gls{IOT} programming with \gls{MTASK} provided at the 2022 SusTrainable summer school in Rijeka, Croatia.
% \paragraph{Contribution}
\end{itemize}
\paragraph{Contribution:}
-The original imperative predecessors the \gls{MTASK} language and their initial interpretations were developed by Pieter Koopman and Rinus Plasmeijer.
+The original imperative predecessors of the \gls{MTASK} language and their initial interpretations were developed by Pieter Koopman and Rinus Plasmeijer.
I continued with the language; developed the byte code interpreter, the precursor to the \gls{C} code generation interpretation; the integration with \gls{ITASK}; and the \gls{RTS}.
The paper of which I am first author are solely written by me.
\subsection{\nameref{prt:tvt}}
\Cref{prt:tvt} is based on a journal paper that quantitatively and qualitatively compares traditional \gls{IOT} architectures with \gls{IOT} systems using \gls{TOP} and contains a single chapter.
This chapter is based on the journal paper: \emph{Could Tierless Programming Reduce IoT Development Grief?} \citep{lubbers_could_2022}\footnote{This work is an extension of the conference article: \emph{Tiered versus Tierless IoT Stacks: Comparing Smart Campus Software Architectures} \citep{lubbers_tiered_2020}\footnotemark.}.
-\footnotetext{This paper was partly funded by the 2019 Radboud-Glasgow Collaboration Fund.}
-
+\footnotetext{This work was partly funded by the 2019 Radboud-Glasgow Collaboration Fund.}
It compares programming traditional tiered architectures to tierless architectures by showing a qualitative and a quantitative four-way comparison of a smart-campus application.
\paragraph{Contribution:}
Writing the paper was performed by all authors.
-I created the server application, the \gls{CLEAN}\slash{}\gls{ITASK}\slash{}\gls{MTASK} implementation (\glsxtrshort{CWS}) and the \gls{CLEAN}\slash{}\gls{ITASK} implementation (\glsxtrshort{CRS})
-Adrian Ramsingh created the \gls{MICROPYTHON} implementation (\glsxtrshort{PWS}), the original \gls{PYTHON} implementation (\glsxtrshort{PRS}) and the server application were created by \citet{hentschel_supersensors:_2016}.
+I created the server application, the \gls{CLEAN}\slash{}\gls{ITASK}\slash{}\gls{MTASK} implementation (\glsxtrshort{CWS}), and the \gls{CLEAN}\slash{}\gls{ITASK} implementation (\glsxtrshort{CRS});
+Adrian Ramsingh created the \gls{MICROPYTHON} implementation (\glsxtrshort{PWS}); the original \gls{PYTHON} implementation (\glsxtrshort{PRS}), and the server application were created by \citet{hentschel_supersensors:_2016}.
\input{subfilepostamble}
\end{document}
\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