update now working
[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 //Serial
54 | BCSerialAvail
55 | BCSerialPrint
56 | BCSerialPrintln
57 | BCSerialRead
58 | BCSerialParseInt
59 //Pins
60 | BCAnalogRead Pin
61 | BCAnalogWrite Pin
62 | BCDigitalRead Pin
63 | BCDigitalWrite Pin
64 | BCTest AnalogPin
65
66 :: ByteCode a p = BC (BCState -> ([BC], BCState))
67 instance Semigroup (ByteCode a p)
68 instance Monoid (ByteCode a p)
69
70 :: BCState = {
71 freshl :: [Int],
72 freshs :: [Int],
73 sdss :: [(Int, [Char])]
74 }
75 instance zero BCState
76
77 class toByteCode a :: a -> [Char]
78 instance toByteCode Int
79 instance toByteCode Bool
80 instance toByteCode Char
81 instance toByteCode String
82 instance toByteCode Long
83 instance toByteCode Button
84
85 instance toChar Pin
86 instance arith ByteCode
87 instance boolExpr ByteCode
88 instance analogIO ByteCode
89 instance digitalIO ByteCode
90 //instance If ByteCode Stmt Stmt Stmt
91 //instance If ByteCode e Stmt Stmt
92 //instance If ByteCode Stmt e Stmt
93 instance If ByteCode x y Stmt
94 instance IF ByteCode
95 instance noOp ByteCode
96
97 instance sds ByteCode
98 instance assign ByteCode
99 instance seq ByteCode
100 instance serial ByteCode
101
102 //pub :: (ByteCode a b) -> ByteCode a b
103
104 toMessages :: Int (String, BCState) -> ([MTaskMSGSend], BCState)
105 toSDSUpdate :: Int Int -> [MTaskMSGSend]
106
107 toByteVal :: BC -> [Char]
108 toReadableByteCode :: (ByteCode a b) -> (String, BCState)
109 toRealByteCode :: (ByteCode a b) -> (String, BCState)