Merge branch 'master' of git.martlubbers.net:msc-thesis1617
[msc-thesis1617.git] / mtaskext.examples.tex
index 05c1d9b..d680072 100644 (file)
@@ -1,18 +1,22 @@
 As an example for the bytecode compilation the following listing shows the
 thermostat example given in Listing~\ref{lst:exmtask} compiled to bytecode.
-The left column indicates the position in the program memory.
+The left column indicates the position in the program memory. The \CI{endif}
+label is resolved to an address outside of the program space. This is not a
+problem since this is included in the stopping condition of the interpreter.
+When the program counter exceeds the length of the program, the task
+terminates.
 
-\begin{lstlisting}[caption={Thermostat bytecode},language=c]
1-2 : BCAnalogRead (Analog A0)
3-6 : BCPush (Int 50)
7   : BCGre
8-9 : BCJmpF 17                   //Jump to else
-10-12: BCPush (Bool 1)
-13-14: BCDigitalWrite (Digital D0)
-15-16: BCJmp 21                    //Jump to endif
-17-19: BCPush (Bool 0)             //Else label
-20   : BCDigitalWrite (Digital D0)
-21   :                             //Endif label
+\begin{lstlisting}[language=Clean,caption={Thermostat bytecode},language=c]
0-1 : BCAnalogRead (Analog A0)
2-5 : BCPush (Int 50)
6   : BCGre
7-8 : BCJmpF 17                   //Jump to else
+ 9-11: BCPush (Bool 1)
+12-13: BCDigitalWrite (Digital D0)
+14-15: BCJmp 21                    //Jump to endif
+16-18: BCPush (Bool 0)             //Else label
+19   : BCDigitalWrite (Digital D0)
+20   :                             //Endif label
 \end{lstlisting}
 
 The factorial function can be expressed as an \gls{mTask}-\gls{Task} and uses
@@ -22,7 +26,7 @@ factorial after which is will return. The following listings shows the actual
 \gls{mTask} and the generated messages followed by the actual bytecode in a
 readable form.
 
-\begin{lstlisting}[caption={Factorial as an \gls{mTask}-\gls{Task}}]
+\begin{lstlisting}[language=Clean,caption={Factorial as an \gls{mTask}-\gls{Task}}]
 factorial :: Int -> Main (ByteCode () Stmt)
 factorial i = sds \y=i In
        namedsds \x=1 Named "result" In
@@ -40,7 +44,7 @@ Start = fst $ toMessages (OnInterval 500) (factorial 5) zero
 //[MTSds 2 (BCValue 5), MTSds 1 (BCValue 1), MTTask (OnInterval 500) ...]
 \end{lstlisting}
 
-\begin{lstlisting}[label={lst:actualbc},%
+\begin{lstlisting}[language=Clean,label={lst:actualbc},%
        caption={The resulting bytecode for the factorial function},language=C]
  0-2 : BCSdsFetch 1
  3-6 : BCPush (Int 1)