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