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