From bc19cda87c727d85893f56adcb8c6901715c2326 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Thu, 1 Jun 2017 13:52:58 +0200 Subject: [PATCH] share waiting with parametric lenses --- mTaskInterpret.dcl | 4 +++- mTaskInterpret.icl | 2 ++ miTask.icl | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/mTaskInterpret.dcl b/mTaskInterpret.dcl index 99a3533..9de7c72 100644 --- a/mTaskInterpret.dcl +++ b/mTaskInterpret.dcl @@ -40,7 +40,9 @@ from Generics.gCons import class gCons, generic conses, generic consName, generi ,bytesMemory :: Int } -:: BCValue = E.e: BCValue e & mTaskType e +:: BCValue = E.e: BCValue e & mTaskType, TC e + +instance == BCValue instance toString MTaskInterval instance toString MTaskMSGRecv diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index 80d458a..5504a21 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -40,6 +40,8 @@ import Text.Encodings.Base64 import Tasks.Examples +instance == BCValue where (==) a b = toByteCode a == toByteCode b + encode :: MTaskMSGSend -> String encode (MTTask to data) = "t" +++ toByteCode to +++ to16bit (size data) +++ data +++ "\n" encode (MTTaskDel i) = "d" +++ to16bit i +++ "\n" diff --git a/miTask.icl b/miTask.icl index 8e43544..f044e36 100644 --- a/miTask.icl +++ b/miTask.icl @@ -37,9 +37,20 @@ demo = viewSharedInformation "Devices" [] deviceStore pred [x:_] = not $ isEmpty x.deviceShares cont :: MTaskDevice -> Task () - cont dev = updateSharedInformation "Blinkyblink" [] (getRealShare dev (hd dev.deviceShares)) - >>* [OnAction ActionContinue (const $ Just $ cont dev)] - + cont dev + # rs = getRealShare dev (hd dev.deviceShares) + = get rs >>= \oldvalue-> + forever (updateSharedInformation "Blinkyblink" [] (getRealShare dev (hd dev.deviceShares)) + >>* [OnAction ActionContinue (const $ Just $ treturn ())]) + -|| (wait "bigger than 10" (\x->x == oldvalue) rs + >>= viewInformation "Bigger:)" []) + + toInt :: BCValue -> Int + toInt (BCValue e) = dynToInt (dynamic e) + + dynToInt :: Dynamic -> Int + dynToInt (a :: Int) = a + dynToInt x = abort "Not an int" mTaskManager :: Task () mTaskManager = (>>|) startupDevices $ -- 2.20.1