X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;ds=sidebyside;f=top%2Flang.tex;h=1e1b02c9cd4f9e0eb81d04220d4cc0789f350071;hb=4e17593a20e8c3af4c82a0b14bc648ddc180c25d;hp=2baed8b341156fd5b6a14bd3b6908e694e3421f4;hpb=5aa57e0cb31d64685ad4c0624c1047a4b7e77399;p=phd-thesis.git diff --git a/top/lang.tex b/top/lang.tex index 2baed8b..1e1b02c 100644 --- a/top/lang.tex +++ b/top/lang.tex @@ -5,18 +5,13 @@ \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} @@ -34,8 +29,8 @@ The following interpretations are available for \gls{MTASK}. 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} @@ -79,7 +74,6 @@ class type t | iTask, ... ,fromByteCode, toByteCode t 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. @@ -95,14 +89,15 @@ someTask :: MTask v Int | mtask v & liftsds v & sensor1 v & ... 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. @@ -149,7 +144,7 @@ e2 = if' (e0 ==. int e1) \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.}] @@ -162,7 +157,7 @@ approxEqual x y eps = if' (x ==. y) true \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}). @@ -239,6 +234,7 @@ swapTuple = % 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. @@ -249,10 +245,12 @@ swapTuple = \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 @@ -275,7 +273,6 @@ class delay v :: (v n) -> MTask v n | long v n \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}. @@ -341,7 +338,7 @@ task2 = declarePin D3 PMOutput \d3->{main=writeD d3 true} \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. @@ -373,8 +370,6 @@ class step v | expr v where | 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. @@ -405,8 +400,8 @@ The semantics are easily described using \gls{CLEAN} functions shown in \cref{ls \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) @@ -416,8 +411,8 @@ con (Value l ls) (Value r 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