import iTasks._Framework.Serialization
derive class iTask MTaskShareType
+
+derive gEditor MTaskShare
+derive gText MTaskShare
+derive JSONEncode MTaskShare
+derive JSONDecode MTaskShare
+derive gDefault MTaskShare
+derive gEq MTaskShare
+
:: MTaskShareType = MTaskWithShare String | MTaskLens String
:: MTaskShare =
{withTask :: String
,identifier :: Int
,realShare :: MTaskShareType
,value :: String
+ ,dynvalue :: Dynamic
}
manageShares :: [MTaskShare] -> Task ()
from Data.Func import $
derive class iTask MTaskShareType
+
+derive gEditor MTaskShare
+derive gText MTaskShare
+derive JSONEncode MTaskShare
+derive JSONDecode MTaskShare
+derive gDefault MTaskShare
+gEq{|MTaskShare|} m1 m2 = m1.identifier == m2.identifier
+
manageShares :: [MTaskShare] -> Task ()
manageShares shares =
forever (enterChoice "Choose share to update" [ChooseFromGrid id] shares
|withTask=withTask
,identifier=identifier
,value=value
+ ,dynvalue=dynamic value
,realShare=MTaskWithShare $ "mTaskSDS-" +++ toString identifier
} >>= \sh->set value (getSDSShare sh) >>| treturn sh
import mTask
import iTasks
-derive class iTask MTaskTask, MTaskInterval, Main, ByteCode, Stmt, Expr, BC, BCState, UserLED, RWST
+derive class iTask MTaskTask, MTaskInterval, Main, ByteCode, Stmt, Expr, BC, BCState, RWST
:: MTaskTask = {
name :: String,
import iTasks._Framework.Serialization
-derive class iTask MTaskTask, MTaskInterval, Main, ByteCode, Stmt, Expr, BC, BCState, UserLED, RWST, Identity
+derive class iTask MTaskTask, MTaskInterval, Main, ByteCode, Stmt, Expr, BC, BCState, RWST, Identity
makeTask :: String Int -> Task MTaskTask
makeTask name ident = get currentDateTime
import Devices.mTaskDevice
import iTasks
-derive class iTask MTaskShare
-
memoryShare :: String a -> Shared a | iTask a
deviceStore :: Shared [MTaskDevice]
import qualified Data.Map as DM
from Data.Func import $
-derive class iTask MTaskShare
-
memoryShare :: String a -> Shared a | iTask a
memoryShare s d = sdsFocus s $ memoryStore "" $ Just d
imporove setp: >>*.
*/
-import GenPrint
-import Generics.gCons
-import Generics.gdynamic
-
//import iTasks
//
//import iTasks._Framework.Generic
import GenEq, StdMisc, StdArray
import mTaskCode, mTaskSimulation, mTaskInterpret
+//import mTaskCode, mTaskInterpret
import mTaskSerial, mTaskLCD
// =================== mTask ===================
unMain :: (Main x) -> x
class arith v where
- lit :: t -> v t Expr | toCode t & toByteCode t
+ lit :: t -> v t Expr | toCode t & mTaskType t
(+.) infixl 6 :: (v t p) (v t q) -> v t Expr | type, +, zero t & isExpr p & isExpr q //& toExpr2 p & toExpr2 q
(-.) infixl 6 :: (v t p) (v t q) -> v t Expr | type, -, zero t & isExpr p & isExpr q //& toExpr2 p & toExpr2 q
(*.) infixl 7 :: (v t p) (v t q) -> v t Expr | type, *, zero, one t & isExpr p & isExpr q //& toExpr2 p & toExpr2 q
// ----- tools ----- //
-derive gPrint Pin, Button, UserLED, AnalogPin, DigitalPin, PinMode
-derive class gCons Pin, Button, UserLED, AnalogPin, DigitalPin, PinMode
-
instance == DigitalPin
instance == AnalogPin
instance == UserLED
instance == AnalogPin where (==) x y = x === y
instance == UserLED where (==) x y = x === y
-derive gEq UserLED
-derive gPrint Pin, Button, UserLED, AnalogPin, DigitalPin, PinMode
-derive class gCons Pin, Button, UserLED, AnalogPin, DigitalPin, PinMode
+//derive class gCons UserLED, Long, Pin, Button, UserLED, AnalogPin, DigitalPin, PinMode
+//derive class iTask UserLED, Long, Pin, Button, UserLED, AnalogPin, DigitalPin, PinMode
tab =: toString (repeatn tabSize ' ')
tabSize :== 2
import Generics.gdynamic
import Generics.gCons
+import StdEnv
-import iTasks
+//import iTasks
import GenEq, StdMisc, StdArray
import mTask
definition module mTaskInterpret
+import mTask
+
from Data.Functor.Identity import :: Identity
from Control.Monad.State import :: State, :: StateT
from Control.Monad.RWST import :: RWST, :: RWS
from Data.Either import :: Either
-import mTask
+from iTasks._Framework.Generic.Defaults import generic gDefault
+from GenPrint import generic gPrint
+from Generics.gCons import class gCons, generic conses, generic consName, generic consIndex, generic consNum
:: MTaskMSGRecv
= MTTaskAck Int
| OnInterval Int
| OnInterrupt Int
+:: BCValue = E.e: BCValue e & mTaskType e
+
instance toString MTaskInterval
instance toString MTaskMSGRecv
instance toString MTaskMSGSend
:: BC
= BCNop
| BCLab Int
-// | E.e: BCPush e & toByteCode e
- | BCPush String
+ | BCPush BCValue
+// | BCPush String
| BCPop
//SDS functions
| BCSdsStore Int
| BCDigitalWrite Pin
| BCTest AnalogPin
-derive class gCons BC
+derive gPrint BCValue
+derive consIndex BCValue
+derive consName BCValue
+derive conses BCValue
+derive consNum BCValue
+
+derive class gCons Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin
+derive class iTask UserLED, Long, Pin, Button, AnalogPin, DigitalPin, PinMode
+derive gEditor BCValue
+derive gText BCValue
+derive JSONEncode BCValue
+derive JSONDecode BCValue
+derive gDefault BCValue
+derive gEq BCValue
:: ByteCode a p = BC (RWS () [BC] BCState ())
class toByteCode a :: a -> String
class fromByteCode a :: String -> a
-class mTaskType a | toByteCode, fromByteCode, TC a
+class mTaskType a | toByteCode, fromByteCode, iTask, TC a
-instance toByteCode Int, Bool, Char, Long, String, Button, UserLED
+instance toByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
instance fromByteCode Int, Bool, Char, Long, String, Button, UserLED
instance toByteCode MTaskInterval
instance fromByteCode MTaskInterval
import Data.Functor
import StdList
from Data.Func import $
-from Text import class Text(lpad,concat,toUpperCase), instance Text String
+from Text import class Text(subString,lpad,concat,toUpperCase), instance Text String
import qualified Text
import Text.JSON
toByteVal :: BC -> String
toByteVal b = {toChar $ consIndex{|*|} b} +++
case b of
- (BCPush i) = i
+ (BCPush i) = toByteCode i
(BCLab i) = {toChar i}
(BCSdsStore i) = to16bit i
(BCSdsFetch i) = to16bit i
(BCJmpF i) = {toChar i}
_ = ""
+instance toByteCode BCValue where toByteCode (BCValue v) = toByteCode v
instance toByteCode Bool where toByteCode b = toByteCode $ if b 1 0
instance toByteCode Int where toByteCode n = {toChar $ n/256,toChar $ n rem 256}
instance toByteCode Long where toByteCode (L n) = toByteCode n
//Intervals have the first bit 1 and the rest is a 15 bit unsigned int
toByteCode (OnInterrupt i) = {toChar $ i/256 bitor 127, toChar $ i rem 256}
+//parseByteCode :: String -> BCValue
+//parseByteCode "b" = BCValue True
+//parseByteCode "i" = BCValue 0
+
instance fromByteCode Bool where fromByteCode s = fromByteCode s == 1
instance fromByteCode Int where fromByteCode s = (toInt s.[0])*256 + toInt s.[1]
instance fromByteCode Long where fromByteCode s = L $ fromByteCode s
instance fromByteCode String where fromByteCode s = abort $ "Undef on fromBytecode String" +++ s
instance fromByteCode Button where fromByteCode s = conses{|*|} !! fromByteCode s
instance fromByteCode UserLED where fromByteCode s = conses{|*|} !! fromByteCode s
+instance fromByteCode BCValue
+ where
+ fromByteCode s = let tail = subString 1 (size s) s in case s.[0] of
+ 'b' = BCValue $ castfbc True tail
+ 'i' = BCValue $ castfbc 0 tail
+ 'l' = BCValue $ castfbc (L 0) tail
+ 'c' = BCValue $ castfbc ('0') tail
+ 'B' = BCValue $ castfbc (NoButton) tail
+ 'L' = BCValue $ castfbc (LED1) tail
+ where
+ castfbc :: a -> (String -> a) | mTaskType a
+ castfbc _ = fromByteCode
+
instance fromByteCode MTaskInterval
where
fromByteCode s
toChar (Digital p) = toChar $ consIndex{|*|} p
toChar (Analog p) = toChar $ consIndex{|*|} p
-derive gPrint BC
+derive gPrint Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin, BC
derive class gCons BC
+consIndex{|BCValue|} _ = 0
+consName{|BCValue|} _ = "BCValue"
+conses{|BCValue|} = [BCValue 0]
+consNum{|BCValue|} _ = 1
+gPrint{|BCValue|} v ps = gPrint{|*|} (readable $ BCPush v) ps
+
+gEditor{|BCValue|} = undef
+gText{|BCValue|} fm Nothing = []
+gText{|BCValue|} fm (Just (BCValue e)) = gText{|*|} fm (Just e)
+JSONEncode{|BCValue|} b (BCValue e) = JSONEncode{|*|} b (toByteCode e)
+JSONDecode{|BCValue|} b n = appFst (fmap fromByteCode) $ JSS b n
+ where
+ JSS :: (Bool [JSONNode] -> (Maybe String, [JSONNode]))
+ JSS = JSONDecode{|*|}
+gDefault{|BCValue|} = BCValue 0
+gEq{|BCValue|} (BCValue e) (BCValue f) = False
+
+derive class gCons Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin
+derive class iTask UserLED, Long, Pin, Button, AnalogPin, DigitalPin, PinMode
+
op2 :: (ByteCode a p1) (ByteCode a p2) BC -> ByteCode b Expr
op2 (BC x) (BC y) bc = BC $ x >>| y >>| tell [bc]
tell` x = BC $ tell x
-instance zero Bool where zero = False
-
instance arith ByteCode where
- lit x = tell` [BCPush $ toByteCode x]
+ lit x = tell` [BCPush $ BCValue x]
(+.) x y = op2 x y BCAdd
(-.) x y = op2 x y BCSub
(*.) x y = op2 x y BCMul
import StdDebug
bclength :: BC -> Int
-bclength (BCPush s) = 1 + size s
+bclength (BCPush s) = 1 + size (toByteCode s)
bclength (BCSdsStore _) = 3
bclength (BCSdsFetch _) = 3
bclength (BCSdsPublish _) = 3
computeGotos [x:xs] i = appFst (\bc->[x:bc]) (computeGotos xs $ i + bclength x)
readable :: BC -> String
-readable (BCPush d) = "BCPush " +++ concat [safe c\\c<-:d]
+readable (BCPush d) = "BCPush " +++ concat [safe c\\c<-:toByteCode d]
where
safe c = if (isControl c) ("\\d" +++ toString (toInt c)) (toString c)
readable b = printToString b
from16bit :: String -> Int
from16bit s = toInt s.[0] * 256 + toInt s.[1]
+
+//derive class gCons UserLED, Long, Pin, Button, UserLED, AnalogPin, DigitalPin, PinMode
definition module mTaskSimulation
-from iTasks.API.Core.Types import class iTask, :: Task, generic gEditor, generic gText, generic JSONEncode, generic JSONDecode, generic gDefault, :: Editor, :: TextFormat, :: JSONNode
import mTask
+from Generics.gdynamic import :: Dyn, class dyn, generic toGenDynamic, generic fromGenDynamic
+from GenPrint import class PrintOutput, :: PrintState
+from Data.Maybe import :: Maybe
+from iTasks import class iTask, generic gEditor, generic gDefault, generic gText, generic JSONEncode, generic JSONDecode, :: Task, :: Editor, :: JSONNode, :: TextFormat
+
:: Display a = Display a
derive class iTask Display
// ----- Interactive Simulation ----- //
-derive class iTask DigitalPin, AnalogPin, Dyn, StateInterface, DisplayVar, Pin
-
simulate :: (Main (Eval a p)) -> Task ()
toView :: State` -> StateInterface
mergeView :: State` StateInterface -> State`
// ----- Interactive Simulation ----- //
-derive class iTask DigitalPin, AnalogPin, Dyn, StateInterface, DisplayVar, Pin
+derive class iTask StateInterface, DisplayVar
simulate :: (Main (Eval a p)) -> Task ()
simulate {main=(E f)} = setup zero where