update a lot, try to type shares
[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
67 | BCLedOff
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 class gCons BC
82
83 :: ByteCode a p = BC (RWS () [BC] BCState ())
84
85 :: BCShare = {
86 sdsi :: Int,
87 sdspub :: Bool,
88 sdsval :: String
89 }
90
91 :: BCState = {
92 freshl :: [Int],
93 freshs :: [Int],
94 sdss :: [BCShare]
95 }
96 instance zero BCState
97
98 class toByteCode a :: a -> String
99 class fromByteCode a :: String -> a
100 class mTaskType a | toByteCode, fromByteCode a
101
102 instance toByteCode Int, Bool, Char, Long, String, Button, UserLED
103 instance fromByteCode Int, Bool, Char, Long, String, Button, UserLED
104 instance toByteCode MTaskInterval
105 instance fromByteCode MTaskInterval
106
107 instance toChar Pin
108 instance arith ByteCode
109 instance boolExpr ByteCode
110 instance analogIO ByteCode
111 instance digitalIO ByteCode
112 instance userLed ByteCode
113 instance If ByteCode Stmt Stmt Stmt
114 instance If ByteCode e Stmt Stmt
115 instance If ByteCode Stmt e Stmt
116 instance If ByteCode x y Stmt
117 instance IF ByteCode
118 instance noOp ByteCode
119
120 instance sds ByteCode
121 instance assign ByteCode
122 instance seq ByteCode
123 instance serial ByteCode
124
125 toMessages :: MTaskInterval (String, BCState) -> ([MTaskMSGSend], BCState)
126 toSDSUpdate :: Int Int -> [MTaskMSGSend]
127
128 toByteVal :: BC -> String
129 toReadableByteCode :: (ByteCode a b) BCState -> (String, BCState)
130 toRealByteCode :: (ByteCode a b) BCState -> (String, BCState)