add task deletion and acknowledgements
[mTask.git] / mTaskInterpret.dcl
1 definition module mTaskInterpret
2
3 from Data.Functor.Identity import :: Identity
4 from Control.Monad.State import :: State, :: StateT
5 from Data.Monoid import class Semigroup, class Monoid
6 import mTask
7
8 :: MTaskMSGRecv
9 = MTTaskAck Int
10 | MTTaskDelAck Int
11 | MTSDSAck Int
12 | MTSDSDelAck Int
13 | MTPub Int String
14 | MTMessage String
15 | MTEmpty
16
17 :: MTaskMSGSend
18 = MTTask Int String
19 | MTTaskDel Int
20 | MTSds Int String
21 | MTUpd Int String
22
23 instance toString MTaskMSGRecv
24 instance toString MTaskMSGSend
25 encode :: MTaskMSGSend -> String
26 decode :: String -> MTaskMSGRecv
27
28 :: BC
29 = BCNop
30 | BCLab Int
31 | BCPush [Char]
32 | BCPop
33 //SDS functions
34 | BCSdsStore Int
35 | BCSdsFetch Int
36 | BCSdsPublish Int
37 //Unary ops
38 | BCNot
39 //Binary Int ops
40 | BCAdd
41 | BCSub
42 | BCMul
43 | BCDiv
44 //Binary Bool ops
45 | BCAnd
46 | BCOr
47 | BCEq
48 | BCNeq
49 | BCLes
50 | BCGre
51 | BCLeq
52 | BCGeq
53 //Conditionals and jumping
54 | BCJmp Int
55 | BCJmpT Int
56 | BCJmpF Int
57 //UserLED
58 | BCLedOn [Char]
59 | BCLedOff [Char]
60 //Serial
61 | BCSerialAvail
62 | BCSerialPrint
63 | BCSerialPrintln
64 | BCSerialRead
65 | BCSerialParseInt
66 //Pins
67 | BCAnalogRead Pin
68 | BCAnalogWrite Pin
69 | BCDigitalRead Pin
70 | BCDigitalWrite Pin
71 | BCTest AnalogPin
72
73 :: ByteCode a p = BC (BCState -> ([BC], BCState))
74 instance Semigroup (ByteCode a p)
75 instance Monoid (ByteCode a p)
76
77 :: BCState = {
78 freshl :: [Int],
79 freshs :: [Int],
80 sdss :: [(Int, [Char])]
81 }
82 instance zero BCState
83
84 class toByteCode a :: a -> [Char]
85 instance toByteCode Int
86 instance toByteCode Bool
87 instance toByteCode Char
88 instance toByteCode String
89 instance toByteCode Long
90 instance toByteCode Button
91 instance toByteCode UserLED
92
93 instance toChar Pin
94 instance arith ByteCode
95 instance boolExpr ByteCode
96 instance analogIO ByteCode
97 instance digitalIO ByteCode
98 instance userLed ByteCode
99 //instance If ByteCode Stmt Stmt Stmt
100 //instance If ByteCode e Stmt Stmt
101 //instance If ByteCode Stmt e Stmt
102 instance If ByteCode x y Stmt
103 instance IF ByteCode
104 instance noOp ByteCode
105
106 instance sds ByteCode
107 instance assign ByteCode
108 instance seq ByteCode
109 instance serial ByteCode
110
111 //pub :: (ByteCode a b) -> ByteCode a b
112
113 toMessages :: Int (String, BCState) -> ([MTaskMSGSend], BCState)
114 toSDSUpdate :: Int Int -> [MTaskMSGSend]
115
116 toByteVal :: BC -> [Char]
117 toReadableByteCode :: (ByteCode a b) -> (String, BCState)
118 toRealByteCode :: (ByteCode a b) BCState -> (String, BCState)