Merge branch 'master' of git.martlubbers.net:msc-thesis1617
[msc-thesis1617.git] / pres.system.tex
index c3642bf..99fba52 100644 (file)
 \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}
@@ -41,8 +48,9 @@ instance ByteCode arith, boolExpr, ...
 \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]
@@ -54,7 +62,7 @@ tell2 x = BC (tell x)
 
 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}
@@ -73,8 +81,11 @@ instance arith ByteCode where
 
 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] >>|
@@ -98,8 +109,7 @@ instance sds ByteCode where
 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]
@@ -114,26 +124,27 @@ makeStore [...]             = [...]
        \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]
@@ -151,14 +162,12 @@ class retrn v where
                \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
 
@@ -279,6 +288,7 @@ class MTaskDuplex a where
                        \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
@@ -304,8 +314,7 @@ where
        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}
@@ -343,7 +352,7 @@ deviceShare d = mapReadWriteError
                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
@@ -354,11 +363,14 @@ 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]
@@ -428,18 +440,18 @@ sendTaskToDevice :: String (Main (ByteCode a Stmt)) (MTaskDevice, MTaskInterval)
        \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}