\begin{frame}[fragile]
\frametitle{Adding a View}
\begin{lstlisting}[language=Clean]
+
:: ByteCode a p = BC (RWS () [BC] BCState ())
+
+:: RWS r w s a = RWS (r s -> (a, s, w))
:: BC = BCNop | BCPush BCValue | ...
:: BCValue = E.e: BCValue e & mTaskType, TC e
:: BCShare = { sdsi :: Int, sdsval :: BCValue, sdsname :: String }
:: BCState = { freshl :: Int, freshs :: Int, sdss :: [BCShare] }
+class mTaskType a | toByteCode, fromByteCode, iTask, TC a
+class toByteCode a :: a -> String
+class fromByteCode a :: String -> a
+
instance ByteCode arith, boolExpr, ...
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Implementation}
\begin{itemize}
- \item Writing instruction
- \item Carrying state
+ \item Reader Write State Transformer Monad
+ \item Write instruction
+ \item Carry state
\item Hand-crafted helpers
\end{itemize}
\begin{lstlisting}[language=Clean]
instance arith ByteCode where
lit x = tell2 [BCPush (BCValue x)]
- (+.) x y = op2 x y BCDiv
+ (+.) x y = op2 x y BCAdd
...
\end{lstlisting}
\end{frame}
freshlabel = get >>= \st=:{freshl}->put {st & freshl=freshl+1} >>| pure freshl
-instance If ByteCode Stmt Stmt Stmt where If b t e = BCIfStmt b t e
-...
+instance IF ByteCode
+where
+ IF b t e = BCIfStmt b t e
+ (?) b t = BCIfStmt b t (tell` [])
+
BCIfStmt (BC b) (BC t) (BC e) = BC (
freshlabel >>= \else->freshlabel >>= \endif->
b >>| tell [BCJmpF else] >>|
instance assign ByteCode where
(=.) (BC v) (BC e) = BC (e >>| censor makeStore v)
-instance sdspub ByteCode where
- pub (BC x) = BC (censor (\[BCSdsFetch s]->[BCSdsPublish s]) x)
+addSDS sds v s = {s & sdss=[{sds & sdsval=BCValue v}:s.sdss]}
makeStore [BCSdsFetch i] = [BCSdsStore i]
makeStore [BCDigitalRead i] = [BCDigitalWrite i]
\begin{lstlisting}
class sdspub v where
pub :: (v t Upd) -> (v () Stmt)
+
instance sdspub ByteCode where
- pub (BC x) = BC (censor (\[BCSdsFetch s]->[BCSdsPublish s]) x)
+ pub (BC x)
+ = BC (censor (\[BCSdsFetch s]->[BCSdsPublish s]) x)
\end{lstlisting}
\end{frame}
\begin{frame}[fragile]
\frametitle{Task scheduling}
- \begin{block}{Old}
+ \begin{block}{Arduino C++ system}
\begin{itemize}
\item Task server
\item Tasks start other tasks
\end{itemize}
\end{block}
\pause{}
- \begin{block}{New}
+ \begin{block}{Interpreted Bytecode system}
\begin{itemize}[<+->]
- \item Old system, taskserver, tasks start tasks
- \item New system, task+strategy
+ \item Task accompanied with strategy
\item \CI{OnShot}, \CI{OnInterval}, \CI{OnInterrupt}
- \item How to handle termination
+ \item How to handle termination?
\end{itemize}
\pause{}
\begin{lstlisting}[language=Clean]
\item Modular implementation
\item Specification generated from the macros
\end{itemize}
-
+ \pause{}
\begin{lstlisting}[language=C,caption={interface.h}]
...
#elif defined TARGET_STM32F767ZI
#define APINS 128
-#define DPINS 128
-#define STACKSIZE 1024
-#define MEMSIZE 1024
+...
#define HAVELED 1
#define HAVEHB 1
\item Used for notifications
\item On write the SDS returns \CI{p -> Bool}
\end{itemize}
+ \pause{}
\end{block}
\begin{lstlisting}[language=Clean]
sdsFocus :: p1 (RWShared p1 r w) -> RWShared p2 r w | iTask p
realDeviceStore :: Shared [MTaskDevice]
realDeviceStore = sharedStore "mTaskDevices" []
- realRead :: P *IWorld
- -> (MaybeError TaskException [MTaskDevice], *IWorld)
+ realRead :: P *IWorld -> (MaybeError TaskException [MTaskDevice], *IWorld)
realRead p iw = read realDeviceStore iw
\end{lstlisting}
\end{onlyenv}
Just d = Ok d)
, \w ds->case splitWith ((==)d) ds of
([], _) = Error $ exception "Device lost"
- ([_:_], ds) = Ok $ Just [w:ds])
+ ([_], ds) = Ok $ Just [w:ds])
$ sdsFocus (Just (d, -1)) deviceStore
shareShare :: MTaskDevice MTaskShare -> Shared BCValue
\subsection{Communication}
\begin{frame}
\frametitle{The glue of the system}
- \begin{itemize}
- \item Compile, send and interact with Tasks
- \item Interact with SDSs
- \item All communication via channels
- \end{itemize}
+ \pause{}
+ \begin{block}{Communication}
+ \begin{itemize}
+ \item Compile, send and interact with Tasks
+ \item Interact with SDSs
+ \item All communication via channels
+ \end{itemize}
+ \end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{Example, blink}
\begin{lstlisting}[language=Clean]
blink :: Task ()
-blink = makeDevice "stm32" stm32 >>= connectDevice
- >>= \stm-> sendTaskToDevice "blink" blinkTask (stm32, OnInterval 1000)
- >>= \(st, [t:_])->forever (
+blink = addDevice
+ >>= connectDevice
+ >>= \stm->sendTaskToDevice "blink" blinkTask (stm, OnInterval 1000)
+ >>= \(st, [_,t])->forever (
updateSharedInformation "Which led to blink" [] (shareShare stm t)
) >>* [OnAction (Action "Shutdown") $ always
$ deleteDevice stm >>| shutDown 0
]
where
- stm32 = makeDevice "Stm32"
- (SerialDevice {devicePath="/dev/ttyUSB0", baudrate=B9600, ...}
- blinkTask = sds \led=LED0 In sds \x=True In
- {main = IF x (ledOff led) (ledOn led) :. x =. Not x }
-
+ blinkTask = sds \led=LED1 In sds \x=True In {main =
+ ledOff led1 :. ledOff led2 :. ledOff led3 :.
+ IF x (ledOff led) (ledOn led) :.
+ x =. Not x}
\end{lstlisting}
\end{frame}