667f26b99e46451fcc913fda2c6be7e845a0f7b2
[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 import mTask
6
7 :: BC
8 = BCNop
9 | BCLab Int
10 | BCPush [Char]
11 | BCPop
12 //SDS functions
13 | BCSdsStore Int
14 | BCSdsFetch Int
15 | BCSdsPublish Int
16 //Unary ops
17 | BCNot
18 //Binary Int ops
19 | BCAdd
20 | BCSub
21 | BCMul
22 | BCDiv
23 //Binary Bool ops
24 | BCAnd
25 | BCOr
26 | BCEq
27 | BCNeq
28 | BCLes
29 | BCGre
30 | BCLeq
31 | BCGeq
32 //Conditionals and jumping
33 | BCJmp Int
34 | BCJmpT Int
35 | BCJmpF Int
36 //Serial
37 | BCSerialAvail
38 | BCSerialPrint
39 | BCSerialPrintln
40 | BCSerialRead
41 | BCSerialParseInt
42 //Pins
43 | BCAnalogRead Pin
44 | BCAnalogWrite Pin
45 | BCDigitalRead Pin
46 | BCDigitalWrite Pin
47 | BCTest AnalogPin
48
49 :: ByteCode a p = BC (BCState -> ([BC], BCState))
50 //:: ByteCode a p = BC [BC]
51 //:: ByteCode a p = BC ((ReadWrite (ByteCode a Expr)) BCState -> ([BC], BCState))
52 :: BCState = {
53 freshl :: [Int],
54 freshs :: [Int]
55 }
56
57 class toByteCode a :: a -> [Char]
58 instance toByteCode Int
59 instance toByteCode Bool
60 instance toByteCode Char
61 instance toByteCode String
62 instance toByteCode Long
63 instance toByteCode Button
64
65 toByteVal :: BC -> [Char]