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