generic consIndex a :: a -> Int
derive consIndex CONS of {gcd_index},UNIT,PAIR,EITHER,OBJECT,Int,Bool,Char,String
+
+generic conses a :: [a]
+derive conses CONS,UNIT,PAIR,EITHER,OBJECT,FIELD,RECORD,Int,Bool,Char,Real,String,(),{},{!},[],[! ],[ !],[!!]
ARDSL project
*/
-import StdEnv, StdGeneric
+import StdEnv, StdGeneric, GenBimap, _SystemStrictLists
generic consName a :: a -> String
consName{|CONS of {gcd_name}|} f x = gcd_name
consIndex{|Bool|} b = if b 1 0
consIndex{|Char|} c = toInt c
consIndex{|String|} _ = 0
+
+generic conses a :: [a]
+conses{|CONS|} f = map CONS f
+conses{|UNIT|} = [UNIT]
+conses{|PAIR|} f g = []
+conses{|EITHER|} f g = map LEFT f ++ map RIGHT g
+conses{|OBJECT|} f = map OBJECT f
+conses{|RECORD|} f = map RECORD f
+conses{|FIELD|} f = map FIELD f
+conses{|Int|} = [0]
+conses{|Bool|} = [True]
+conses{|Char|} = ['\0']
+conses{|Real|} = [0.0]
+conses{|String|} = [""]
+conses{|[]|} _ = [[ ]]
+conses{|[!]|} _ = [[!]]
+conses{|[ !]|} _ = [[ !]]
+conses{|[!!]|} _ = [[!!]]
+conses{|{}|} _ = [{}]
+conses{|{!}|} _ = [{!}]
+conses{|()|} = [()]
+
implementation module mTaskInterpret
//import iTasks
-import gdynamic, gCons, GenEq, StdMisc, StdArray
+import gdynamic, gCons, GenEq, StdMisc, StdArray, GenBimap
import GenPrint
import mTask
import StdString
from StdFunc import o
+import StdBool
import StdTuple
import Data.Tuple
import StdList
from Data.Func import $
-from Text import class Text(join), instance Text String
-
-
-
+from Text import class Text(join,toUpperCase), instance Text String
toByteVal :: BC -> String
toByteVal a = undef
-derive gPrint BC
+derive gPrint BC, AnalogPin
+derive consIndex BC
+derive consName BC
+derive conses BC, AnalogPin
toReadableByteVal :: BC -> String
toReadableByteVal a = printToString a
(<=.) x y = x <++> y <+-> [BCLeq]
(>=.) x y = x <++> y <+-> [BCGeq]
+instance analogIO ByteCode where
+ analogRead p = BC [BCAnalogRead p]
+ analogWrite p b = b <+-> [BCAnalogWrite p]
+
instance If ByteCode Stmt Stmt Stmt where If b t e = BCIfStmt b t e
instance If ByteCode Stmt e Stmt where If b t e = BCIfStmt b t e
//instance If ByteCode Stmt Stmt e where If b t e = BCIfStmt b t e
-//instance If ByteCode Stmt x y where If b t e = BCIfStmt b t e
-instance IF ByteCode where
+instance If ByteCode x y Expr where If b t e = BCIfStmt b t e
+instance IF ByteCode where
IF b t e = BCIfStmt b t e
(?) b t = BCIfStmt b t $ BC []
-BCIfStmt b t e = b <+-> [BCJmpF $ length <$> t + 1] <++> t <+-> [BCJmp $ length <$> e] <++> e
+BCIfStmt b t e = b <+-> [BCJmpF $ length <$> t + 1] <++> t
+ <+-> [BCJmp $ length <$> e] <++> e
instance noOp ByteCode where noOp = BC []
+instance serial ByteCode where
+ serialAvailable = BC [BCSerialAvail]
+ serialPrint s = BC [BCSerialPrint]
+ serialPrintln s = BC [BCSerialPrintln]
+ serialRead = BC [BCSerialRead]
+ serialParseInt = BC [BCSerialParseInt]
(<++>) infixl 7
(<++>) (BC x) (BC y) = BC $ x ++ y
(<$>) infixl 9
(<$>) f (BC x) = f x
-instance serial ByteCode where
- serialAvailable = undef
- serialPrint _ = undef
- serialPrintln _ = undef
- serialRead = undef
- serialParseInt = undef
-
instance zero BCState where
zero = {a=()}
//Start :: ByteCode Int Expr
//Start = (lit 36 +. lit 42) +. lit 84
-//
-derive consIndex BC
-derive consName BC
-Start w
-# (io, w) = stdio w
-# io = io <<< "#ifndef MTASK_H\n#define MTASK_H\n"
-# io = io <<< join "\n" ["#define " +++ consName{|*|} x +++ " " +++ toString (consIndex{|*|} x)\\x<-allBC]
-# (ok, w) = fclose (io <<< "\n#endif\n") w
-| not ok = abort "Couldn't close stdio"
-= w
- where
- allBC = [BCNop, BCPush "", BCPop, BCNeg, BCNot, BCAdd, BCSub, BCMul,
- BCDiv, BCAnd, BCOr, BCEq, BCNeq, BCLes, BCGre, BCLeq, BCGeq,
- BCJmp 0, BCJmpT 0, BCJmpF 0]
+(<+) infixr 5 :: a b -> String | toString a & toString b
+(<+) a b = toString a +++ toString b
+
+//Run test programma en pretty print
+Start :: ByteCode Int Expr
+Start = analogRead A0
+//Start = If ((lit 36) ==. (lit 42)) (noOp) (noOp)
+
+//Generate header file
+//Start w
+//# (io, w) = stdio w
+//# io = io <<< "#ifndef MTASK_H\n#define MTASK_H\n"
+//# io = io <<< join "\n" ["#define " <+ toUpperCase (consName{|*|} x) <+ " " <+ consIndex{|*|} x\\x<-allBC]
+// with
+// allBC :: [BC]
+// allBC = conses{|*|}
+//# (ok, w) = fclose (io <<< "\n#endif\n") w
+//| not ok = abort "Couldn't close stdio"
+//= w