sapl
mTask-data
mTaskInterpret
+mTaskMakeSymbols
BINARIES:= mTaskExamples mTaskInterpret
-all: $(BINARIES)
+all: $(BINARIES) int/mTaskSymbols.h
+
+int/mTaskSymbols.h: mTaskMakeSymbols
+ ./$< -nr > $@
%: %.icl $(wildcard *.[id]cl)
$(CLM) $(CLMLIBS) $(CLMFLAGS) $(basename $<) -o $@
consIndex{|Char|} c = toInt c
consIndex{|String|} _ = 0
+import StdMisc, StdDebug
+
generic conses a :: [a]
conses{|CONS|} f = map CONS f
conses{|UNIT|} = [UNIT]
case BCSERIALPARSEINT:
printf("SerialParseInt()\n");
break;
+ case BCANALOGREAD:
+ printf("AnalogRead()\n");
+ break;
+ case BCANALOGWRITE:
+ printf("AnalogWrite()\n");
default:
die("Unrecognized command: %X\n", program[--pc]);
}
#ifndef MTASK_H
#define MTASK_H
-#define BCNop 0
-#define BCPush 1
-#define BCPop 2
-#define BCNot 3
-#define BCAdd 4
-#define BCSub 5
-#define BCMul 6
-#define BCDiv 7
-#define BCAnd 8
-#define BCOr 9
-#define BCEq 10
-#define BCNeq 11
-#define BCLes 12
-#define BCGre 13
-#define BCLeq 14
-#define BCGeq 15
-#define BCJmp 16
-#define BCJmpT 17
-#define BCJmpF 18
+#define BCNOP 0
+#define BCPUSH 1
+#define BCPOP 2
+#define BCNOT 3
+#define BCADD 4
+#define BCSUB 5
+#define BCMUL 6
+#define BCDIV 7
+#define BCAND 8
+#define BCOR 9
+#define BCEQ 10
+#define BCNEQ 11
+#define BCLES 12
+#define BCGRE 13
+#define BCLEQ 14
+#define BCGEQ 15
+#define BCJMP 16
+#define BCJMPT 17
+#define BCJMPF 18
#define BCSERIALAVAIL 19
#define BCSERIALPRINT 20
#define BCSERIALPRINTLN 21
#define BCSERIALREAD 22
#define BCSERIALPARSEINT 23
+#define BCANALOGREAD 24
+#define BCANALOGWRITE 25
+#define BCDIGITALREAD 26
+#define BCDIGITALWRITE 27
#endif
| BCSerialRead
| BCSerialParseInt
//Pins
- | BCAnalogRead AnalogPin
- | BCAnalogWrite AnalogPin
+ | BCAnalogRead String
+ | BCAnalogWrite String
+ | BCDigitalRead String
+ | BCDigitalWrite String
//:: ByteCode a p = BC (BCState -> ([BC], BCState))
:: ByteCode a p = BC [BC]
(>=.) x y = x <++> y <+-> [BCGeq]
instance analogIO ByteCode where
- analogRead p = BC [BCAnalogRead p]
- analogWrite p b = b <+-> [BCAnalogWrite p]
+ analogRead p = BC [BCAnalogRead $ toCode p]
+ analogWrite p b = b <+-> [BCAnalogWrite $ toCode p]
+
+instance digitalIO ByteCode where
+ digitalRead p = BC [BCDigitalRead $ toCode p]
+ digitalWrite p b = b <+-> [BCDigitalWrite $ toCode 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 Stmt e where If b t e = BCIfStmt b t e
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
//Start :: ByteCode Int Expr
//Start = (lit 36 +. lit 42) +. lit 84
-(<+) 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 True) (analogRead A1) (analogRead A0)
//Start = If ((lit 36) ==. (lit 42)) (noOp) (noOp)
//Generate header file
--- /dev/null
+module mTaskMakeSymbols
+
+//import iTasks
+import gdynamic, gCons, GenEq, StdMisc, StdArray, GenBimap
+import GenPrint
+import mTask
+import StdEnum
+
+import StdFile
+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,toUpperCase), instance Text String
+
+derive consIndex BC
+derive consName BC
+derive conses BC, AnalogPin
+
+(<+) infixr 5 :: a b -> String | toString a & toString b
+(<+) a b = toString a +++ toString b
+
+toDefine :: Int BC -> String
+toDefine i b = "#define " <+ toUpperCase (consName{|*|} b) <+ " " <+ i
+
+Start w
+# (io, w) = stdio w
+# io = io <<< "#ifndef MTASK_H\n#define MTASK_H\n"
+# io = io <<< join "\n" (map (uncurry toDefine) (zip2 [0..] conses{|*|}))
+# (ok, w) = fclose (io <<< "\n#endif\n") w
+| not ok = abort "Couldn't close stdio"
+= w