The sheer number of connected devices around us is increasing exponentially.
First and foremost, these devices are driven by software.
This thesis is about \ldots
\todo[inline]{introduction}

\section{\Acrlong{IOT}}
\todo[inline]{add more citations and rewrite to make modern}
The \gls{IOT} is growing rapidly and it is changing the way people and machines interact with the world.
The term \gls{IOT} was coined around 1999 to describe the communication of \gls{RFID} devices.
\gls{RFID} became more and more popular the years after but the term \gls{IOT} was not associated with it anymore.
Years later, during the rise of novel network technologies, the term \gls{IOT} resurged with a slightly different meaning.
Today, the \gls{IOT} is the term for a system of devices that sense the environment, act upon it and communicate with each other and the world.
At the time of writing, there is about one connected device per person in the world of which many are part of an \gls{IOT} system.
Gartner estimates that of these connected devices, there are about $5.8$ billion \gls{IOT} devices or endpoints connected~\footnote{Gartner (August 2019)}\todo[inline]{update with recent number}.
They are already in everyone's household in the form of smart electricity meters, smart fridges, smartphones, smart watches, home automation and in the form of much more.
While the number of devices seems to be growing exponentially fast, programming \gls{IOT} applications is difficult.
The devices are a large heterogeneous collection of different platforms, protocols and languages resulting in impedance problems.

The devices in \gls{IOT} systems are equipped with various sensors and actuators.
These range from external ones such as positioning, temperature and humidity to more internal ones like heartbeat and respiration.
When describing \gls{IOT} systems, a layered architecture is often used to compartmentalize the technology.
For the intents and purposes of this paper the four layer architecture defined by ITU-T (International Telecommunications Union {-} Telecommunication Standardization Sector) will be used as visualized in Figure~\ref{fig:layers}.

\begin{figure}
	\centering
	\begin{tikzpicture}[node distance=3em]
		\node (1) [rectangle,draw,minimum width=10em] {Application Layer};
		\node (2) [rectangle,draw,minimum width=10em,below of=1] {Support Laper};
		\node (3) [rectangle,draw,minimum width=10em,below of=2] {Network Layer};
		\node (4) [rectangle,draw,minimum width=10em,below of=3] {Perception Layer};

		\draw [->] (1) -- (2);
		\draw [->] (2) -- (1);
		\draw [->] (2) -- (3);
		\draw [->] (3) -- (2);
		\draw [->] (3) -- (4);
		\draw [->] (4) -- (3);
	\end{tikzpicture}
	\caption{The four layered \gls{IOT} architecture as described by the ITU-T.}%
	\label{fig:layers}
\end{figure}

The first layer is called the perception layer and contains the actual endpoints with their peripherals.
For example in home automation, the sensors reading the room and the actuators opening the curtains are in the perception layer.
As a special type of device, it may also contain a \gls{SN}.
A \gls{SN} is a collection of sensors connected by a mesh network or central hub.
The network layer is the second layer and it consists of the hardware and software to connect the perception layer to the world.
In home automation, this layer may consist of a specialized \gls{IOT} technology such as \gls{BLE} or ZigBee but it may also use existing technologies such as WiFi or wired connections.
The third layer is named support layer and is responsible for the servicing and business rules surrounding the application.
One of its goals is to provide the \gls{API}, interfaces and data storage.
In home automation this provides the server storing the data.
The fourth and final layer in this architecture is the application layer.
The application layer provides the interaction between the user and the \gls{IOT} system.
In home automation, this layer contains the apps for to read the measurements and control the devices.

The perception layer often is a heterogeneous collections of microcontrollers, each having their own peculiarities, language of choice and hardware interfaces.
The hardware needs to be cheap, small-scale and energy efficient.
As a result, the \glspl{MCU} used to power these devices do not have a lot of computational power, a soup\c{c}on of memory, and little communication bandwidth.
Typically the devices do not run a full fledged \gls{OS} but a compiled firmware.
This firmware is often written in an imperative language that needs to be flashed to the program memory.
It is possible to dynamically send the program to the program memory using \gls{OTA} programming~\cite{baccelli_scripting_2018,baccelli_reprogramming_2018}.
Program memory typically is flash based and only lasts a couple of thousand writes before it wears out.
While devices are getting a bit faster, smaller, and cheaper, they keep these properties to an extent.
The properties of the device greatly reduce the flexibility for dynamic systems where tasks are created on the fly, executed on demand and require parallel execution.
These problems can be mitigated by dynamically sending code to be interpreted to the \gls{MCU}.
With interpretation, a specialized interpreter is flashed in the program memory once that receives the program code to execute at runtime.

\section{\Acrlongpl{DSL}}
% General
Programming languages can be divided up into two categories: \glspl{DSL} and \glspl{GPL}\todo{citation needed}.
Where \glspl{GPL} are not made with a demarcated area in mind, \glspl{DSL} are tailor-made for a specific domain.
Consequently, writing idiomatic domain-specific code 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\footnote{Also called external and internal respectively~\cite{fowler_domain-specific_2010}} of which \glspl{EDSL} can again be classified into heterogeneous and homogeneous languages (see \cref{fig:taxonomy_of_dsls} for this taxonomy).

\begin{figure}[ht]
	\centering
	\begin{tikzpicture}[nodes={draw,minimum width=7.5em}]
		\node (dsl)  {\gls{DSL}};
		\node (sta) [below=of dsl,xshift=-3.75em] {standalone};
		\node (emb) [right=of sta] {embedded};
		\node (het) [below=of emb,xshift=-3.75em] {heterogeneous};
		\node (hom) [right=of het] {homogeneous};
		\draw [->] (dsl) -- (sta);
		\draw [->] (dsl) -- (emb);
		\draw [->] (emb) -- (het);
		\draw [->] (emb) -- (hom);
	\end{tikzpicture}
	\caption{Taxonomy of \glspl{DSL} (adapted from Verna~\cite[pg.\ 2]{mernik_extensible_2013})}%
	\label{fig:taxonomy_of_dsls}
\end{figure}

DSLs where historically created as standalone languages which means all the 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 to be usable making standalone \glspl{DSL} costly to create.
Examples of standalone \glspl{DSL} are regular expressions, make, yacc, XML, SQL, \etc.

A radically different approach is embeddding the \gls{DSL} in a host language, i.e.\ \glspl{EDSL}~\cite{hudak_modular_1998}.
By defining the language as constructs in the host language, much of the machinery is inherited and the cost of creating embedded languages is very low.
There are however two sides to the this coin.
If the syntax of the host language is not very flexible, the syntax of the \gls{DSL} may become clumsy.
Furthermore, 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}.

Tratt applied a notion from metaprogramming~\cite{sheard_accomplishments_2001} to \glspl{EDSL} to define homogeneity and heterogeneity of \glspl{EDSL} as follows~\cite{tratt_domain_2008}:
\begin{quote}
	a homogeneous system is one where all the components are specifically designed to work with each other, whereas in heterogeneous systems at least one of the components is largely, or completely, ignorant of the existence of the other parts of the system.
\end{quote}
Homogeneous \glspl{EDSL} are therefore languages that are solely defined as an extension to their host language.
They often restrict features of the host language to provide a safer interface or capture an idiomatic pattern in the host language for reuse.
The difference between a library and a homogeneous \glspl{EDSL} is not always clear.
Examples of homogeneous \glspl{EDSL} are libraries such as ones for \glspl{GUI} creation, LISP's macro system, \etc.

On the other hand, heterogeneous \glspl{EDSL} are languages that are not executed in the host language.
For example, Elliott et al.\ describe the language Pan, for which the final representation in the host language is a compiler that will, when executed, generate code for a completely different target platform~\cite{elliott_compiling_2003}.
In fact, \gls{ITASK} and \gls{MTASK} are both heterogeneous \glspl{EDSL}.

\section{\Acrlong{FP}}\label{ssec:functional programming}
\Gls{FP} is \ldots
\Gls{FP} languages are naturally suitable as a host language for \gls{DSL} embedding because of their rich type systems and minimal and extensible syntax~\cite{gibbons_functional_2015}.

\section{\Acrlong{TOP}}
\Gls{TOP} is a declarative programming paradigm designed to model interactive systems~\cite{plasmeijer_task-oriented_2012}.
Instead of dividing problems up into a layered approach it deals with separation of concerns in a novel way (see \cref{fig:tosd}).
All components of a \gls{TOP} program are centered around the data types and from these datatypes, implementation details such as the interface, the communication and the sharing of data is generated.
\begin{description}
	\item[Data types]
		In \gls{TOP}, everything is based around datatypes.
	\item[Tasks]
		A task is an abstract representation of a piece of work that needs to be done.
		It provides an intuitive abstraction over work in the real world.
		Just as with real-life tasks and workflow, tasks can be combined in various ways such as in parallel or in sequence.
		Furthermore, tasks are observable which means it is possible to observe a --- partial --- result during execution and act upon it by for example starting new tasks.
		Examples of tasks are filling in a form, sending an email, reading a sensor or even doing a physical task.
	\item[UI]
		The \gls{UI} of the system is automatically generated from the representation of the type.
		For example, in \gls{FP} languages this may be done using generic programming or template metaprogramming whereas in imperative programming languages they may be done using introspection\todo{Do I want this sentence here?}.
		In many practical \gls{TOP} systems the \gls{UI} can be tweaked afterwards to suit the needs of the application.
	\item[SDS]
		Tasks can communicate using task values but this imposes a problem in many collaboration patterns where tasks that are not necessarily related need to share data.
		Tasks can also share data using \glspl{SDS}.
		\Glspl{SDS} are an abstraction over any data.
		An \gls{SDS} can represent typed data stored in a file, a chunk of memory, a database \etc.
		\Glspl{SDS} can also represent external impure data such as the time, random numbers or sensory data.
		Similar to tasks, transformation and combination of \glspl{SDS} is possible.
	\item[PL]
		\gls{TOP} languages are usually embedded in \gls{FP} languages but not necessarily.
		The languages in which the \gls{TOP} is hosted provides the integration with the execution platform if there is any.
		Some host languages also provide the implementations for the tasks and \glspl{SDS}.
\end{description}

\begin{figure}[ht]
	\centering
	\begin{tikzpicture}
		\pie[%
			color={red,violet,teal,blue},
			explode={0.1},
			hide number,
			text=inside,
			rotate=45,
			radius=2.25,
		]{%
			25/\textcolor{white}{UI},
			25/\textcolor{white}{Tasks},
			25/\textcolor{white}{PL},
			25/\textcolor{white}{SDS}
		}
		\node [draw,fill=yellow,circle]{Types};
	\end{tikzpicture}
	\caption{\Gls{TOSD} approach (adapted from Stutterheim et al.~\cite[pg.\ 20]{wang_maintaining_2018})}%
	\label{fig:tosd}
\end{figure}

\section{Thesis Outline}

\todo[inline]{reference correct chapters}
Chapters 0 and 0 are based on the paper \emph{A Task-Based \acrshort{DSL} for Microcomputers}~\cite{koopman_task-based_2018}.

Chapters 0 and 0 are based on the Master's thesis and paper \emph{\glst{TOP} and the \glst{IOT}}~\cite{lubbers_task_2017,lubbers_task_2018}.

Chapters 0 and 0 are based on the paper \emph{Multitasking on Microcontrollers using \glst{TOP}}~\cite{lubbers_multitasking_2019}.

Chapters 0 and 0 are based on the paper \emph{Tiered versus Tierless \acrshort{IOT} Stacks: Comparing Smart Campus Software Architectures}~\cite{lubbers_tiered_2020}.

Chapters 0 and 0 are based on the paper \emph{Interpreting \glst{TOP} Programs on Tiny Computers}~\cite{lubbers_interpreting_2019}.

Chapters 0 and 0 are based on the paper \emph{Writing \glst{IOT} applications with \glst{TOP}}~\cite{lubbers_writing_2019}.
