extend shares
[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 Int
15 | MTTaskDelAck Int
16 | MTSDSAck Int
17 | MTSDSDelAck Int
18 | MTPub Int BCValue
19 | MTMessage String
20 | MTDevSpec MTaskDeviceSpec
21 | MTEmpty
22
23 :: MTaskMSGSend
24 = MTTask MTaskInterval String
25 | MTTaskDel Int
26 | MTShutdown
27 | MTSds Int BCValue
28 | MTUpd Int BCValue
29 | MTSpec
30
31 :: MTaskInterval
32 = OneShot
33 | OnInterval Int
34 | OnInterrupt Int
35
36 :: MTaskDeviceSpec =
37 {haveLed :: Bool
38 ,haveAio :: Bool
39 ,haveDio :: Bool
40 ,bytesMemory :: Int
41 }
42
43 :: BCValue = E.e: BCValue e & mTaskType e
44
45 instance toString MTaskInterval
46 instance toString MTaskMSGRecv
47 instance toString MTaskMSGSend
48 encode :: MTaskMSGSend -> String
49 decode :: String -> MTaskMSGRecv
50
51 :: BC
52 = BCNop
53 | BCLab Int
54 | BCPush BCValue
55 // | BCPush String
56 | BCPop
57 //SDS functions
58 | BCSdsStore BCShare
59 | BCSdsFetch BCShare
60 | BCSdsPublish BCShare
61 //Unary ops
62 | BCNot
63 //Binary Int ops
64 | BCAdd
65 | BCSub
66 | BCMul
67 | BCDiv
68 //Binary Bool ops
69 | BCAnd
70 | BCOr
71 //Binary ops
72 | BCEq
73 | BCNeq
74 | BCLes
75 | BCGre
76 | BCLeq
77 | BCGeq
78 //Conditionals and jumping
79 | BCJmp Int
80 | BCJmpT Int
81 | BCJmpF Int
82 //UserLED
83 | BCLedOn
84 | BCLedOff
85 //Serial
86 | BCSerialAvail
87 | BCSerialPrint
88 | BCSerialPrintln
89 | BCSerialRead
90 | BCSerialParseInt
91 //Pins
92 | BCAnalogRead Pin
93 | BCAnalogWrite Pin
94 | BCDigitalRead Pin
95 | BCDigitalWrite Pin
96 //Return
97 | BCReturn
98
99 derive gPrint BCValue, MTaskDeviceSpec
100 derive consIndex BCValue
101 derive consName BCValue
102 derive conses BCValue
103 derive consNum BCValue
104
105 derive class gCons Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin
106 derive class iTask UserLED, Long, Pin, Button, AnalogPin, DigitalPin, PinMode, MTaskDeviceSpec
107 derive gEditor BCValue
108 derive gText BCValue
109 derive JSONEncode BCValue
110 derive JSONDecode BCValue
111 derive gDefault BCValue
112 derive gEq BCValue
113
114 :: ByteCode a p = BC (RWS () [BC] BCState ())
115
116 :: BCShare = {
117 sdsi :: Int,
118 sdsval :: BCValue
119 }
120
121 :: BCState = {
122 freshl :: [Int],
123 freshs :: [Int],
124 sdss :: [BCShare]
125 }
126 instance zero BCState
127
128 class toByteCode a :: a -> String
129 class fromByteCode a :: String -> a
130 class mTaskType a | toByteCode, fromByteCode, iTask, TC a
131
132 instance toByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
133 instance fromByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
134 instance toByteCode MTaskInterval
135 instance fromByteCode MTaskInterval, MTaskDeviceSpec
136
137 instance arith ByteCode
138 instance boolExpr ByteCode
139 instance analogIO ByteCode
140 instance digitalIO ByteCode
141 instance userLed ByteCode
142 instance If ByteCode Stmt Stmt Stmt
143 instance If ByteCode e Stmt Stmt
144 instance If ByteCode Stmt e Stmt
145 instance If ByteCode x y Stmt
146 instance IF ByteCode
147 instance noOp ByteCode
148 instance retrn ByteCode
149
150 instance sds ByteCode
151 instance assign ByteCode
152 instance seq ByteCode
153 instance serial ByteCode
154
155 toMessages :: MTaskInterval (Main (ByteCode a b)) BCState -> ([MTaskMSGSend], BCState)
156
157 toByteVal :: BC -> String
158 toReadableByteCode :: (ByteCode a b) BCState -> (String, BCState)
159 toRealByteCode :: (ByteCode a b) BCState -> (String, BCState)