BCValue is existential now
[mTask.git] / mTaskInterpret.dcl
1 definition module mTaskInterpret
2
3 import mTask
4
5 from Data.Functor.Identity import :: Identity
6 from Control.Monad.State import :: State, :: StateT
7 from Control.Monad.RWST import :: RWST, :: RWS
8 from Data.Either import :: Either
9 from iTasks._Framework.Generic.Defaults import generic gDefault
10 from GenPrint import generic gPrint
11 from Generics.gCons import class gCons, generic conses, generic consName, generic consIndex, generic consNum
12
13 :: MTaskMSGRecv
14 = MTTaskAck Int
15 | MTTaskDelAck Int
16 | MTSDSAck Int
17 | MTSDSDelAck Int
18 | MTPub Int String
19 | MTMessage String
20 | MTEmpty
21
22 :: MTaskMSGSend
23 = MTTask MTaskInterval String
24 | MTTaskDel Int
25 | MTSds Int String
26 | MTUpd Int String
27
28 :: MTaskInterval
29 = OneShot
30 | OnInterval Int
31 | OnInterrupt Int
32
33 :: BCValue = E.e: BCValue e & mTaskType e
34
35 instance toString MTaskInterval
36 instance toString MTaskMSGRecv
37 instance toString MTaskMSGSend
38 encode :: MTaskMSGSend -> String
39 decode :: String -> MTaskMSGRecv
40
41 :: BC
42 = BCNop
43 | BCLab Int
44 | BCPush BCValue
45 // | BCPush String
46 | BCPop
47 //SDS functions
48 | BCSdsStore Int
49 | BCSdsFetch Int
50 | BCSdsPublish Int
51 //Unary ops
52 | BCNot
53 //Binary Int ops
54 | BCAdd
55 | BCSub
56 | BCMul
57 | BCDiv
58 //Binary Bool ops
59 | BCAnd
60 | BCOr
61 | BCEq
62 | BCNeq
63 | BCLes
64 | BCGre
65 | BCLeq
66 | BCGeq
67 //Conditionals and jumping
68 | BCJmp Int
69 | BCJmpT Int
70 | BCJmpF Int
71 //UserLED
72 | BCLedOn
73 | BCLedOff
74 //Serial
75 | BCSerialAvail
76 | BCSerialPrint
77 | BCSerialPrintln
78 | BCSerialRead
79 | BCSerialParseInt
80 //Pins
81 | BCAnalogRead Pin
82 | BCAnalogWrite Pin
83 | BCDigitalRead Pin
84 | BCDigitalWrite Pin
85 | BCTest AnalogPin
86
87 derive gPrint BCValue
88 derive consIndex BCValue
89 derive consName BCValue
90 derive conses BCValue
91 derive consNum BCValue
92
93 derive class gCons Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin
94 derive class iTask UserLED, Long, Pin, Button, AnalogPin, DigitalPin, PinMode
95 derive gEditor BCValue
96 derive gText BCValue
97 derive JSONEncode BCValue
98 derive JSONDecode BCValue
99 derive gDefault BCValue
100 derive gEq BCValue
101
102 :: ByteCode a p = BC (RWS () [BC] BCState ())
103
104 :: BCShare = {
105 sdsi :: Int,
106 sdspub :: Bool,
107 sdsval :: Dynamic,
108 sdsbc :: String
109 }
110
111 :: BCState = {
112 freshl :: [Int],
113 freshs :: [Int],
114 sdss :: [BCShare]
115 }
116 instance zero BCState
117
118 class toByteCode a :: a -> String
119 class fromByteCode a :: String -> a
120 class mTaskType a | toByteCode, fromByteCode, iTask, TC a
121
122 instance toByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
123 instance fromByteCode Int, Bool, Char, Long, String, Button, UserLED
124 instance toByteCode MTaskInterval
125 instance fromByteCode MTaskInterval
126
127 instance toChar Pin
128 instance arith ByteCode
129 instance boolExpr ByteCode
130 instance analogIO ByteCode
131 instance digitalIO ByteCode
132 instance userLed ByteCode
133 instance If ByteCode Stmt Stmt Stmt
134 instance If ByteCode e Stmt Stmt
135 instance If ByteCode Stmt e Stmt
136 instance If ByteCode x y Stmt
137 instance IF ByteCode
138 instance noOp ByteCode
139
140 instance sds ByteCode
141 instance assign ByteCode
142 instance seq ByteCode
143 instance serial ByteCode
144
145 toMessages :: MTaskInterval (String, BCState) -> ([MTaskMSGSend], BCState)
146 toSDSUpdate :: Int Int -> [MTaskMSGSend]
147
148 toByteVal :: BC -> String
149 toReadableByteCode :: (ByteCode a b) BCState -> (String, BCState)
150 toRealByteCode :: (ByteCode a b) BCState -> (String, BCState)