rewrite generation to rws
[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 Control.Monad.RWST import :: RWST, :: RWS
6 from Data.Either import :: Either
7 import mTask
8
9 :: MTaskMSGRecv
10 = MTTaskAck Int
11 | MTTaskDelAck Int
12 | MTSDSAck Int
13 | MTSDSDelAck Int
14 | MTPub Int String
15 | MTMessage String
16 | MTEmpty
17
18 :: MTaskMSGSend
19 = MTTask MTaskInterval String
20 | MTTaskDel Int
21 | MTSds Int String
22 | MTUpd Int String
23
24 :: MTaskInterval
25 = OneShot
26 | OnInterval Int
27 | OnInterrupt Int
28
29 instance toString MTaskInterval
30 instance toString MTaskMSGRecv
31 instance toString MTaskMSGSend
32 encode :: MTaskMSGSend -> String
33 decode :: String -> MTaskMSGRecv
34
35 :: BC
36 = BCNop
37 | BCLab Int
38 // | E.e: BCPush e & toByteCode e
39 | BCPush String
40 | BCPop
41 //SDS functions
42 | BCSdsStore Int
43 | BCSdsFetch Int
44 | BCSdsPublish Int
45 //Unary ops
46 | BCNot
47 //Binary Int ops
48 | BCAdd
49 | BCSub
50 | BCMul
51 | BCDiv
52 //Binary Bool ops
53 | BCAnd
54 | BCOr
55 | BCEq
56 | BCNeq
57 | BCLes
58 | BCGre
59 | BCLeq
60 | BCGeq
61 //Conditionals and jumping
62 | BCJmp Int
63 | BCJmpT Int
64 | BCJmpF Int
65 //UserLED
66 | BCLedOn UserLED
67 | BCLedOff UserLED
68 //Serial
69 | BCSerialAvail
70 | BCSerialPrint
71 | BCSerialPrintln
72 | BCSerialRead
73 | BCSerialParseInt
74 //Pins
75 | BCAnalogRead Pin
76 | BCAnalogWrite Pin
77 | BCDigitalRead Pin
78 | BCDigitalWrite Pin
79 | BCTest AnalogPin
80
81 derive gPrint BC
82 derive class gCons BC
83
84 :: ByteCode a p = BC (RWS () [BC] BCState ())
85
86 :: BCShare = {
87 sdsi :: Int,
88 sdspub :: Bool,
89 sdsval :: String
90 }
91
92 :: BCState = {
93 freshl :: [Int],
94 freshs :: [Int],
95 sdss :: [BCShare]
96 }
97 instance zero BCState
98
99 class toByteCode a :: a -> String
100 class fromByteCode a :: String -> a
101 class mTaskType a | toByteCode, fromByteCode a
102
103 instance toByteCode Int, Bool, Char, Long, String, Button, UserLED
104 instance fromByteCode Int, Bool, Char, Long, String, Button, UserLED
105 instance toByteCode MTaskInterval
106 instance fromByteCode MTaskInterval
107
108 instance toChar Pin
109 instance arith ByteCode
110 instance boolExpr ByteCode
111 instance analogIO ByteCode
112 instance digitalIO ByteCode
113 instance userLed ByteCode
114 instance If ByteCode Stmt Stmt Stmt
115 instance If ByteCode e Stmt Stmt
116 instance If ByteCode Stmt e Stmt
117 instance If ByteCode x y Stmt
118 instance IF ByteCode
119 instance noOp ByteCode
120
121 instance sds ByteCode
122 instance assign ByteCode
123 instance seq ByteCode
124 instance serial ByteCode
125
126 toMessages :: MTaskInterval (String, BCState) -> ([MTaskMSGSend], BCState)
127 toSDSUpdate :: Int Int -> [MTaskMSGSend]
128
129 toByteVal :: BC -> String
130 toReadableByteCode :: (ByteCode a b) BCState -> (String, BCState)
131 toRealByteCode :: (ByteCode a b) BCState -> (String, BCState)