Merge branch 'master' of gitlab.science:mlubbers/mTask
[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, TC e
44
45 instance == BCValue
46
47 instance toString MTaskInterval
48 instance toString MTaskMSGRecv
49 instance toString MTaskMSGSend
50 encode :: MTaskMSGSend -> String
51 decode :: String -> MTaskMSGRecv
52
53 :: BC
54 = BCNop
55 | BCLab Int
56 | BCPush BCValue
57 // | BCPush String
58 | BCPop
59 //SDS functions
60 | BCSdsStore BCShare
61 | BCSdsFetch BCShare
62 | BCSdsPublish BCShare
63 //Unary ops
64 | BCNot
65 //Binary Int ops
66 | BCAdd
67 | BCSub
68 | BCMul
69 | BCDiv
70 //Binary Bool ops
71 | BCAnd
72 | BCOr
73 //Binary ops
74 | BCEq
75 | BCNeq
76 | BCLes
77 | BCGre
78 | BCLeq
79 | BCGeq
80 //Conditionals and jumping
81 | BCJmp Int
82 | BCJmpT Int
83 | BCJmpF Int
84 //UserLED
85 | BCLedOn
86 | BCLedOff
87 //Serial
88 | BCSerialAvail
89 | BCSerialPrint
90 | BCSerialPrintln
91 | BCSerialRead
92 | BCSerialParseInt
93 //Pins
94 | BCAnalogRead Pin
95 | BCAnalogWrite Pin
96 | BCDigitalRead Pin
97 | BCDigitalWrite Pin
98 //Return
99 | BCReturn
100
101 derive gPrint BCValue, MTaskDeviceSpec
102 derive consIndex BCValue
103 derive consName BCValue
104 derive conses BCValue
105 derive consNum BCValue
106
107 derive class gCons Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin
108 derive class iTask UserLED, Long, Pin, Button, AnalogPin, DigitalPin, PinMode, MTaskDeviceSpec
109 derive gEditor BCValue
110 derive gText BCValue
111 derive JSONEncode BCValue
112 derive JSONDecode BCValue
113 derive gDefault BCValue
114 derive gEq BCValue
115
116 :: ByteCode a p = BC (RWS () [BC] BCState ())
117
118 :: BCShare = {
119 sdsi :: Int,
120 sdsval :: BCValue
121 }
122
123 :: BCState = {
124 freshl :: [Int],
125 freshs :: [Int],
126 sdss :: [BCShare]
127 }
128 instance zero BCState
129
130 class toByteCode a :: a -> String
131 class fromByteCode a :: String -> a
132 class mTaskType a | toByteCode, fromByteCode, iTask, TC a
133
134 instance toByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
135 instance fromByteCode Int, Bool, Char, Long, String, Button, UserLED, BCValue
136 instance toByteCode MTaskInterval
137 instance fromByteCode MTaskInterval, MTaskDeviceSpec
138
139 instance arith ByteCode
140 instance boolExpr ByteCode
141 instance analogIO ByteCode
142 instance digitalIO ByteCode
143 instance aIO ByteCode
144 instance dIO ByteCode
145 instance userLed ByteCode
146 instance If ByteCode Stmt Stmt Stmt
147 instance If ByteCode e Stmt Stmt
148 instance If ByteCode Stmt e Stmt
149 instance If ByteCode x y Stmt
150 instance IF ByteCode
151 instance noOp ByteCode
152 instance retrn ByteCode
153
154 instance sds ByteCode
155 instance sdspub ByteCode
156 instance assign ByteCode
157 instance seq ByteCode
158 instance serial ByteCode
159
160 toMessages :: MTaskInterval (Main (ByteCode a b)) BCState -> ([MTaskMSGSend], BCState)
161
162 toByteVal :: BC -> String
163 toReadableByteCode :: (ByteCode a b) BCState -> (String, BCState)
164 toRealByteCode :: (ByteCode a b) BCState -> (String, BCState)