paragraphs in future, update on shares
[msc-thesis1617.git] / conclusion.tex
1 \section{Discussion \& Future Research}
2 The system is still a crude prototype and a proof of concept. Improvements and
3 extension for the system are amply available in several fields of study.
4
5 \subsection{Simulation}
6 An additional simulation view to the \gls{mTask}-\gls{EDSL} could be added that
7 works in the same way as the existing \gls{C}-backed simulation. It simulates
8 the bytecode interpretation. Moreover would be possible to let the simulator
9 function as a real device, thus handling all communication through the
10 existing \gls{SDS}-based systems and behave like a real device. At the moment
11 the \emph{POSIX}-client is the reference client and contains debugging code.
12 Adding a simulation view to the system allows for easy interactive debugging.
13 However, it might not be easy to devise a simulation tool that accurately
14 simulates the \gls{mTask} system accurately on some levels. The semantics can
15 be simulated but timing and peripheral input/output are more difficult to
16 simulate properly.
17
18 \subsection{Optimization}
19 \paragraph{Multitasking on the client:}
20 True multitasking could be added to the client software. This allows
21 \gls{mTask}-\glspl{Task} to run truly parallel. All \glspl{mTask} get slices
22 of execution time and will each have their own interpreter state instead of one
23 system-wide one that is reset after am \gls{mTask} finishes. This does require
24 separate stacks for each \gls{Task} and therefore increases the system
25 requirements of the client software. However, it could be implemented as a
26 compile-time option and exchanged during the handshake so that the server knows
27 the multithreading capabilities of the client.
28
29 \paragraph{Optimizing the interpreter:}
30 Hardly any work has been done in the interpreter. The current interpreter is a
31 no nonsense stack machine. A lot of improvements can be done in this part. For
32 example, precomputed \emph{gotos} can improve jumping to the correct part of
33 the code corresponding to the correct instruction. Moreover, the stack
34 currently consists of 16-bit values. All operations work on 16-bit values and
35 this simplifies the interpreter implementation. A memory improvement can be
36 made by converting the stack to 8-bit values. This does pose some problems
37 since an equality instruction must work on single-byte booleans \emph{and}
38 two-byte integers. Adding specialized instructions per word size could overcome
39 this problem.
40
41 \subsection{Resources}
42 \paragraph{Resource analysis: }
43 Resource analysis during compilation can be useful to determine if an
44 \gls{mTask}-\gls{Task} is suitable for a specific device. If the device does
45 not contain the correct peripherals --- such as an \gls{LCD} --- then the
46 \gls{mTask}-\gls{Task} should be rejected and feedback to the user must be
47 given. It might even be possible to do this statically on the type level.
48
49 \paragraph{Extended resource analysis: }
50 The previous idea could be extended to the analysis of stack size and possibly
51 communication bandwidth. With this functionality ever more reliable fail-over
52 systems can be designed. When the system knows precise bounds it can allocate
53 more \glspl{Task} on a device whilst staying within safe memory bounds. The
54 resource allocation can be done at runtime within the backend itself or a
55 general backend can be devices that can calculate the resources needed for a
56 given \gls{mTask}. A specific \gls{mTask} cannot have multiple views at the
57 same time due to the restrictions of class based shallow embedding. It might
58 even be possible to encode the resource allocation in the type system itself
59 using forms of dependant types.
60
61 \subsection{Functionality}
62 \paragraph{Add more combinators: }
63 More \gls{Task}-combinators --- already existing in the \gls{iTasks}-system ---
64 could be added to the \gls{mTask}-system to allow for more fine-grained control
65 flow between \gls{mTask}-\glspl{Task}. In this way the new system follows the
66 \gls{TOP} paradigm even more and makes programming \glspl{mTask} for
67 \gls{TOP}-programmers more seamless. Some of the combinators require previously
68 mentioned extension such as the parallel combinator. Others might be achieved
69 using simple syntactic transformations.
70
71 \paragraph{Launch \glspl{Task} from a \gls{Task}: }
72 Currently the \gls{C}-view allows \glspl{Task} to launch other \glspl{Task}. In
73 the current system this type of logic has to take place server side. Adding
74 this functionality to the bytecode-view allows greater flexibility, easier
75 programming and less communication resources. Adding these semantics requires
76 modifications to the client software and extensions to the communication
77 protocol since relations between \glspl{Task} also need to be encoded and
78 communicated.
79
80 The \gls{SDS} functionality in the current system is bare. There is no easy way
81 of reusing a \gls{SDS} for another \gls{Task} on the same device or on another
82 device. Such functionality can be implemented in a crude way by tying the
83 \glspl{SDS} together in the \gls{iTasks} environment. However, this will result
84 in a slow updating system. Functionality for reusing shares from a device
85 should be added. This requires rethinking the storage because some typedness is
86 lost when the \gls{SDS} is stored after compilation. A possibility would be to
87 use runtime typing with \CI{Dynamic}s or the encoding technique currently used
88 for \CI{BCValue}s. Using \glspl{SDS} for multiple \glspl{Task} within one
89 device is solved when the previous point at paragraph~\ref{par:tasklaunch} is
90 implemented.
91
92 \subsection{Robustness}
93 \paragraph{Reconnect with lost devices:}
94 The robustness of the system can be greatly improved. Devices that lose
95 connection are in the current system not well supported. The device will stop
96 functioning and have to be emptied for a reconnect. \Glspl{Task} residing on a
97 device that disconnected should be kept on the server to allow a swift
98 reconnect and restoration of the \glspl{Task}. This holds the same for the
99 client software. The client drops all existing \glspl{Task} on a shutdown
100 request. An extra specialization of the shutdown could be added that drops the
101 connection but keeps the \glspl{Task} in memory. During the downtime the
102 \glspl{Task} can still be executed but publications need to be delayed. If the
103 same server connects to the client the delayed publications can be sent
104 anyways.
105
106 \paragraph{Reverse \gls{Task} sending:}
107 Moreover, devices could send their current \glspl{Task} back at the
108 server to synchronize it. This allows interchanging servers without
109 interrupting the client. Allowing the client to send \glspl{Task} to the server
110 is something to handle with care because it can easily cause high bandwidth
111 usage.
112
113 \section{Conclusion}
114 This thesis introduces a novel system for add \gls{IoT} functionality to
115 the \gls{TOP} implementation \gls{iTasks}. A new view for the existing
116 \gls{mTask}-\gls{EDSL} has been created which compiles the program
117 into bytecode that can be interpreted by a client. Clients have
118 been written for several microcontrollers and consumer architectures which can
119 be connected through various means of communication such as serial port,
120 bluetooth, wifi and wired network communication. The bytecode on the devices is
121 interpreted using a stack machine and provides the programmer interfaces
122 to the peripherals. The semantics of the \glspl{mTask} tries to resemble the
123 \gls{iTasks} semantics as close as possible.
124
125 The host language has a very efficient compiler and code generator. Therefore,
126 compiling \glspl{mTask} is also fast. Compiling \glspl{mTask} is nothing
127 more than running some functions native to the host language.
128
129 The dynamic nature allows the microcontroller to be programmed once and used
130 many times. The program memory of microcontrollers often guarantees around
131 $10.000$ write or upload cycles and therefore existing techniques such as
132 generating \gls{C} code are not usable for dynamic \gls{Task} environments.
133 The dynamic nature also allows the programmer to design fail-over mechanisms.
134 When a device is assigned a \gls{Task} but another device suddenly becomes
135 unusable, the \gls{iTasks} system can reassign a new \gls{mTask}-\gls{Task} to
136 the first device that possibly takes over some of the functionality of the
137 broken device without needing to recompile the code.