From: Mart Lubbers Date: Thu, 10 Nov 2016 14:01:48 +0000 (+0100) Subject: add conses, add if, some examples X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=2936e3ba44acd430c2b3290801ab1ffa700a8c25;p=mTask.git add conses, add if, some examples --- diff --git a/.gitignore b/.gitignore index c43012d..9505dbe 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ mTaskExamples sapl mTask-data mTaskInterpret +mTaskMakeSymbols diff --git a/Makefile b/Makefile index 6ad7e16..0332515 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,10 @@ CLMLIBS:=\ BINARIES:= mTaskExamples mTaskInterpret -all: $(BINARIES) +all: $(BINARIES) int/mTaskSymbols.h + +int/mTaskSymbols.h: mTaskMakeSymbols + ./$< -nr > $@ %: %.icl $(wildcard *.[id]cl) $(CLM) $(CLMLIBS) $(CLMFLAGS) $(basename $<) -o $@ diff --git a/gCons.icl b/gCons.icl index 3f13a7d..77e223b 100644 --- a/gCons.icl +++ b/gCons.icl @@ -36,6 +36,8 @@ consIndex{|Bool|} b = if b 1 0 consIndex{|Char|} c = toInt c consIndex{|String|} _ = 0 +import StdMisc, StdDebug + generic conses a :: [a] conses{|CONS|} f = map CONS f conses{|UNIT|} = [UNIT] diff --git a/int/int.c b/int/int.c index 89dcd0d..9dc52a2 100644 --- a/int/int.c +++ b/int/int.c @@ -120,6 +120,11 @@ int main(void) 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]); } diff --git a/int/mTaskSymbols.h b/int/mTaskSymbols.h index 51a8d79..f67721b 100644 --- a/int/mTaskSymbols.h +++ b/int/mTaskSymbols.h @@ -1,27 +1,31 @@ #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 diff --git a/mTaskInterpret.dcl b/mTaskInterpret.dcl index fa5d1d2..0048859 100644 --- a/mTaskInterpret.dcl +++ b/mTaskInterpret.dcl @@ -35,8 +35,10 @@ import mTask | 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] diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index d689b5f..600f86c 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -46,12 +46,16 @@ instance boolExpr ByteCode where (>=.) 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 @@ -84,12 +88,9 @@ instance zero BCState where //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 diff --git a/mTaskMakeSymbols.icl b/mTaskMakeSymbols.icl new file mode 100644 index 0000000..b18c546 --- /dev/null +++ b/mTaskMakeSymbols.icl @@ -0,0 +1,36 @@ +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