add interpreter part
authorMart Lubbers <mart@martlubbers.net>
Thu, 15 Jun 2017 08:46:17 +0000 (10:46 +0200)
committerMart Lubbers <mart@martlubbers.net>
Thu, 15 Jun 2017 08:46:17 +0000 (10:46 +0200)
conclusion.tex
results.mtask.tex
thesis.tex

index 94b75ff..729f479 100644 (file)
@@ -56,7 +56,10 @@ of the client software. However, it could be implemented as a compile-time
 option and exchanged during the handshake so that the server knows the
 multithreading capabilities of the client.
 
 option and exchanged during the handshake so that the server knows the
 multithreading capabilities of the client.
 
-\todo{Parametric lenses on devices share?}
+Hardly any work has been done in the interpreter. The current interpreter is a
+no nonsense stack machine. A lot of improvements can be done in this part. For
+example, precomputed \emph{gotos} can improve jumping to the correct part of
+the code corresponding to the correct instruction.
 
 \subsection{Resources}
 Resource analysis during compilation can be useful to determine if an
 
 \subsection{Resources}
 Resource analysis during compilation can be useful to determine if an
index 2ad243a..9c16fc5 100644 (file)
@@ -324,7 +324,50 @@ position in the program memory.
 20   : BCDigitalWrite (Digital D0)
 \end{lstlisting}
 
 20   : BCDigitalWrite (Digital D0)
 \end{lstlisting}
 
-\todo{add more elaborate example?}
-
-\section{Interpretation}
-\todo{details about the interpreter on the client}
+\section{Interpreter}
+The client contains an interpreter to execute a \gls{Task}'s bytecode.
+
+First some preparatory work is done. The stack will be initialized and the
+program counter and stack pointer are set to zero and the bottom respectively.
+Then the interpreter executes one step at the time while the program counter is
+smaller than the program length. The code for this is listed in
+Listing~\ref{lst:interpr}. One execution step is basically a big switch
+statement going over all possible bytecode instructions. Some instructions are
+detailed upon in the listing. The \CI{BCPush} instruction is a little more
+complicated in real life because some decoding will take place as not all
+\CI{BCValue}'s are of the same length.
+
+\begin{lstlisting}[language=C,label={lst:interpr},%
+       caption={Rough code outline for interpretation}]
+#define f16(p) program[pc]*265+program[pc+1]
+
+void run_task(struct task *t){
+       uint8_t *program = t->bc;
+       int plen = t->tasklength;
+       int pc = 0;
+       int sp = 0;
+       while(pc < plen){
+               switch(program[pc++]){
+               case BCNOP:
+                       break;
+               case BCPUSH:
+                       stack[sp++] = pc++ //Simplified
+                       break;
+               case BCPOP:
+                       sp--;
+                       break;
+               case BCSDSSTORE:
+                       sds_store(f16(pc), stack[--sp]);
+                       pc+=2;
+                       break;
+               // ...
+               case BCADD: trace("add");
+                       stack[sp-2] = stack[sp-2] + stack[sp-1];
+                       sp -= 1;
+                       break;
+               // ...
+               case BCJMPT: trace("jmpt to %d", program[pc]);
+                       pc = stack[--sp] ? program[pc]-1 : pc+1;
+                       break;
+}
+\end{lstlisting}
index d6d6e71..2c89d51 100644 (file)
@@ -61,8 +61,7 @@
 \chapter{Conclusion \& Discussion}\label{chp:conclusion}
 \input{conclusion}
 
 \chapter{Conclusion \& Discussion}\label{chp:conclusion}
 \input{conclusion}
 
-\appendix%
-\label{chp:appendix}
+\appendix\label{chp:appendix}
 
 \chapter{Communication protocol}\label{app:communication-protocol}
 \input{appendix-protocol}
 
 \chapter{Communication protocol}\label{app:communication-protocol}
 \input{appendix-protocol}