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