#include "sds.h"
#ifdef STM
-#define trace(op, ...) ;
+#define trace(op, ...) {};
#else
#define trace(op, ...) printf("pc: %d, sp: %d, op: " op "\n", pc, sp, ##__VA_ARGS__);
#endif
//Read task bytecode
for(unsigned int i = 0; i<tasks[ct].tlen; i++){
tasks[ct].bc[i] = read_byte();
- debug("t[][%i]: 0x%02x %d", i,
- tasks[ct].bc[i], tasks[ct].bc[i]);
+// debug("t[][%i]: 0x%02x %d", i,
+// tasks[ct].bc[i], tasks[ct].bc[i]);
}
//Return the task number for later removal
debug("Received a task of length %d", tasks[ct].tlen);
(
consumeNetworkStream (processSDSs sdsShares messageShare) ch ||-
viewSharedInformation "channels" [ViewWith lens] ch ||-
+ viewSharedInformation "messages" [] messageShare ||-
viewSh sdsShares ch
) >>* [OnAction ActionFinish (always shutDown)]
)
)
) ||- viewSh xs ch
- sdsShares = makeShares st
-
- (msgs, st) = toMessages 500 (toRealByteCode (unMain bc))
+ (msgs, sdsShares) = makeBytecode 500 bc
bc :: Main (ByteCode () Stmt)
bc = sds \x=1 In sds \pinnetje=1 In {main =
digitalWrite D2 (lit True)
)
)}
-// bc :: Main (ByteCode Int Stmt)
-// bc = sds \x=1 In {main =
-// If (x ==. lit 3)
-// (x =. lit 1)
-// (x =. x +. lit 1) :. pub x}
-
-makeShares :: BCState -> [(Int, Shared Int)]
-makeShares {sdss=[]} = []
-makeShares s=:{sdss=[(i,d):xs]} =
- [(i, ms ("mTaskSDS-" +++ toString i) 1):makeShares {s & sdss=xs}]
+
+makeBytecode :: Int (Main (ByteCode () Stmt)) -> ([MTaskMSGSend], [(Int, Shared Int)])
+makeBytecode timeout bc
+# (msgs, st) = toMessages timeout (toRealByteCode (unMain bc))
+# shares = map (\(i,d)->(i, sdsFocus (s i) (memoryStore (s i) (Just (dd d))))) st.sdss
+= (msgs, shares)
where
- ms name i = sdsFocus name (memoryStore name (Just i))
+ s i = "mTaskSDS-" +++ toString i
+ dd [x,y] = (toInt x)*265+(toInt y)
+
sendMsg :: [MTaskMSGSend] (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task ()
sendMsg m ch = upd (\(r,rs,s,ss)->(r,rs,s ++ m,ss)) ch @! ()