#define BCNOP 1
#define BCPUSH 2
#define BCPOP 3
-#define BCNOT 4
-#define BCADD 5
-#define BCSUB 6
-#define BCMUL 7
-#define BCDIV 8
-#define BCAND 9
-#define BCOR 10
-#define BCEQ 11
-#define BCNEQ 12
-#define BCLES 13
-#define BCGRE 14
-#define BCLEQ 15
-#define BCGEQ 16
-#define BCJMP 17
-#define BCJMPT 18
-#define BCJMPF 19
-#define BCSERIALAVAIL 20
-#define BCSERIALPRINT 21
-#define BCSERIALPRINTLN 22
-#define BCSERIALREAD 23
-#define BCSERIALPARSEINT 24
-#define BCANALOGREAD 25
-#define BCANALOGWRITE 26
-#define BCDIGITALREAD 27
-#define BCDIGITALWRITE 28
-#define BCTEST 29
+#define BCSDS 4
+#define BCNOT 5
+#define BCADD 6
+#define BCSUB 7
+#define BCMUL 8
+#define BCDIV 9
+#define BCAND 10
+#define BCOR 11
+#define BCEQ 12
+#define BCNEQ 13
+#define BCLES 14
+#define BCGRE 15
+#define BCLEQ 16
+#define BCGEQ 17
+#define BCJMP 18
+#define BCJMPT 19
+#define BCJMPF 20
+#define BCSERIALAVAIL 21
+#define BCSERIALPRINT 22
+#define BCSERIALPRINTLN 23
+#define BCSERIALREAD 24
+#define BCSERIALPARSEINT 25
+#define BCANALOGREAD 26
+#define BCANALOGWRITE 27
+#define BCDIGITALREAD 28
+#define BCDIGITALWRITE 29
+#define BCTEST 30
#endif
unMain :: (Main x) -> x
class arith v where
- lit :: t -> v t Expr | toCode t
+ lit :: t -> v t Expr | toCode t & toByteCode t
(+.) infixl 6 :: (v t p) (v t q) -> v t Expr | type, +, zero t & isExpr p & isExpr q //& toExpr2 p & toExpr2 q
(-.) infixl 6 :: (v t p) (v t q) -> v t Expr | type, -, zero t & isExpr p & isExpr q //& toExpr2 p & toExpr2 q
(*.) infixl 7 :: (v t p) (v t q) -> v t Expr | type, *, zero, one t & isExpr p & isExpr q //& toExpr2 p & toExpr2 q
= [bt:case b of
(BCPush i) = [toChar i]
(BCAnalogRead i) = [toChar i]
- (BCAnalogRead i) = [toChar i]
(BCAnalogWrite i) = [toChar i]
(BCDigitalRead i) = [toChar i]
(BCDigitalWrite i) = [toChar i]
where
toByteCode b = toChar $ consIndex{|*|} b + 1
+instance toByteCode Bool where
+ toByteCode True = [toChar 1]
+ toByteCode False = [toChar 0]
+instance toByteCode Int where toByteCode n = map toChar [n/(2<<7),n rem 265]
+instance toByteCode Long where toByteCode (L n) = toByteCode n
+instance toByteCode Char where toByteCode c = [c]
+instance toByteCode String where toByteCode s = undef
+instance toByteCode Button where toByteCode s = [toChar $ consIndex{|*|} s]
+
instance toChar Pin where
toChar (Digital p) = toChar $ consIndex{|*|} p + 1
toChar (Analog p) = toChar $ consIndex{|*|} p + 1
derive gPrint BC, AnalogPin, Pin, DigitalPin
-derive consIndex BC, Pin
-derive consName BC, Pin
+derive consIndex BC, Pin, Button
+derive consName BC, Pin, Button
toReadableByteVal :: BC -> String
toReadableByteVal a = printToString a
instance arith ByteCode where
- lit x = BC [BCPush $ 1]
+ lit x = BC [BCPush 1]
(+.) x y = x <++> y <+-> [BCAdd]
(-.) x y = x <++> y <+-> [BCSub]
(*.) x y = x <++> y <+-> [BCMul]
instance noOp ByteCode where noOp = BC []
+instance sds ByteCode where
+ sds f = {main =
+ let var = 42
+ (v In body) = f var
+ in unMain body
+ }
+ con f = undef
+
instance serial ByteCode where
serialAvailable = BC [BCSerialAvail]
serialPrint s = BC [BCSerialPrint]
to16bit i = toString (toChar (i/265)) +++ toString (toChar (i rem 265))
//Run test programma en pretty print
-Start :: String
-Start = "t" +++ to16bit (size b) +++ b
-//Start :: ByteCode Int Expr
-//Start = bc
+//Start :: String
+//Start = "t" +++ to16bit (size b) +++ b
+Start :: Main (ByteCode Int Expr)
+Start = bc
where
- bc = If (lit True) (analogRead A1) (analogRead A0)
+ bc = sds \x=43 In {main = If (x ==. lit 42) (analogRead A1) (analogRead A0)}
b = toRealByteCode bc
//Start :: ByteCode Int Expr
//Start = If (lit True) (analogRead A1) (analogRead A0)