X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=miTask.icl;h=62b6ce1738c7e51720e05c0b9fed6c0de29d605f;hb=c23eb53a452d0aea1a26ba60fe8ce9abcb77ea02;hp=a00d6f0a6f5b06ca27ccd366304b299b3134695a;hpb=a0182655c28502ffcadbe36de99d9a4e503e310e;p=mTask.git diff --git a/miTask.icl b/miTask.icl index a00d6f0..62b6ce1 100644 --- a/miTask.icl +++ b/miTask.icl @@ -7,25 +7,46 @@ from Text import class Text(concat,join,split), instance Text String import iTasks import mTask +derive class iTask MTaskMessage + Start :: *World -> *World +Start world = startEngine ( + enterInformation "Port Number?" [] + >>= \port->withShared ([], False, [], False) (mTaskTask port) + ) world Start world = startEngine mTaskTask world -mTaskTask :: Task () -mTaskTask = withShared ([],False,[],False) (\ch-> - syncNetworkChannel "localhost" 8123 "\n" id id ch ||- - sendByteCode ||- - updateSharedInformation "channels" [] ch @! ()) - -sendByteCode :: Task () -sendByteCode = viewInformation "send" [] "4" @! () -// (toReadableByteCode (unMain bc)) @! () +mTaskTask :: Int (Shared ([MTaskMessage],Bool,[MTaskMessage],Bool)) -> Task () +mTaskTask port ch = + syncNetworkChannel "localhost" port "\n" decode encode ch ||- + ( + sendMsg msgs ch >>= \_-> + viewSharedInformation "channels" [ViewWith lens] ch @! () + ) >>* [OnAction ActionFinish (always shutDown)] where - bc :: Main (ByteCode Int Expr) - bc = sds \x=41 In - sds \y=1 In - {main = x =. x +. y} + lens :: ([MTaskMessage],Bool,[MTaskMessage],Bool) -> ([String], [String]) + lens (r,_,s,_) = (f r, f s) + where + f [] = [] + f [MTEmpty:xs] = f xs + f [x:xs] = [toString x:f xs] + + msgs + | not (trace_tn (fst (toReadableByteCode (unMain bc)))) = undef + = toMessages 500 (toRealByteCode (unMain bc)) + + bc :: Main (ByteCode Int Stmt) + bc = sds \x=1 In {main = + If (x ==. lit 3) + (x =. lit 1) + (x =. x +. lit 1) :. pub x} -syncNetworkChannel :: String Int String (String -> m) (m -> String) (Shared ([m],Bool,[m],Bool)) -> Task () | iTask m +sendMsg :: [MTaskMessage] (Shared ([MTaskMessage],Bool,[MTaskMessage],Bool)) -> Task () +sendMsg m ch +| not (trace_tn (join "\n" (map (toString o toJSON) m))) = undef += upd (\(r,rs,s,ss)->(r,rs,s ++ m,ss)) ch @! () + +syncNetworkChannel :: String Int String (String -> m) (n -> String) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n syncNetworkChannel server port msgSeparator decodeFun encodeFun channel = tcpconnect server port channel {ConnectionHandlers|onConnect=onConnect,whileConnected=whileConnected,onDisconnect=onDisconnect} @! () where @@ -43,17 +64,17 @@ syncNetworkChannel server port msgSeparator decodeFun encodeFun channel onDisconnect l (received,receiveStopped,send,sendStopped) = (Ok l,Just (received,True,send,sendStopped)) -consumeNetworkStream :: ([m] -> Task ()) (Shared ([m],Bool,[m],Bool)) -> Task () | iTask m -consumeNetworkStream processTask channel - = ((watch channel >>* [OnValue (ifValue ifProcess process)]) >| if (isEmpty received) (return ()) (processTask received) - @! receiveStopped - - empty :: ([m],Bool,[m],Bool) -> ([m],Bool,[m],Bool) - empty (_,rs,s,ss) = ([],rs,s,ss) +//consumeNetworkStream :: ([m] -> Task ()) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n +//consumeNetworkStream processTask channel +// = ((watch channel >>* [OnValue (ifValue ifProcess process)]) >| if (isEmpty received) (return ()) (processTask received) +// @! receiveStopped +// +// empty :: ([m],Bool,[m],Bool) -> ([m],Bool,[m],Bool) +// empty (_,rs,s,ss) = ([],rs,s,ss)