fd22548df2aea43afd9dc8daff8a6c4fa75751fa
[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 }
58 instance zero BCState
59
60 class toByteCode a :: a -> [Char]
61 instance toByteCode Int
62 instance toByteCode Bool
63 instance toByteCode Char
64 instance toByteCode String
65 instance toByteCode Long
66 instance toByteCode Button
67
68 instance toChar Pin
69 instance arith ByteCode
70 instance boolExpr ByteCode
71 instance analogIO ByteCode
72 instance digitalIO ByteCode
73 instance If ByteCode Stmt Stmt Stmt
74 instance If ByteCode Stmt e Stmt
75 instance If ByteCode Stmt Stmt e
76 instance If ByteCode x y Expr
77 instance IF ByteCode
78 instance noOp ByteCode
79
80 instance sds ByteCode
81 instance assign ByteCode
82 instance seq ByteCode
83 instance serial ByteCode
84
85 toByteVal :: BC -> [Char]
86 toReadableByteCode :: (ByteCode a Expr) -> String
87 toRealByteCode :: (ByteCode a Expr) -> String