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