From: Mart Lubbers Date: Tue, 22 Nov 2016 14:05:09 +0000 (+0100) Subject: changed mTaskInterpret to output a real task X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=e62ff4107298a5c69667b10ab807cf932b2c8d9a;p=mTask.git changed mTaskInterpret to output a real task --- diff --git a/Makefile b/Makefile index 0332515..1a36a32 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CLEAN_HOME?=/opt/clean CLM:=clm -override CLMFLAGS+=-dynamics -l -no-pie -h 200M -t -nt -lat +override CLMFLAGS+=-dynamics -l -no-pie -h 200M -t -nt #-lat CLMLIBS:=\ -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/Dynamics\ -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/Generics\ diff --git a/int/int.c b/int/int.c index f3332f7..6300c9d 100644 --- a/int/int.c +++ b/int/int.c @@ -47,9 +47,8 @@ bool input_available(int fd){ void read_message(int fd_in, int fd_out) { //Find next task - uint8_t c; + uint8_t c, ct; uint16_t tasklen; - uint8_t ct; for(ct = 0; ct ([BC], BCState)) @@ -48,7 +48,7 @@ import mTask a::() } -toByteVal :: BC -> String +toByteVal :: BC -> [Char] toReadableByteVal :: BC -> String //instance toCode Pin diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index 9a51e0c..886f463 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -16,18 +16,36 @@ import StdList from Data.Func import $ from Text import class Text(concat,join,toUpperCase), instance Text String -toByteVal :: BC -> String -toByteVal a = toString $ toChar $ consIndex{|*|} a - -derive gPrint BC, AnalogPin -derive consIndex BC -derive consName BC +toByteVal :: BC -> [Char] +toByteVal b +# bt = toByteCode b += [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] + (BCJmp i) = [toChar i] + (BCJmpT i) = [toChar i] + (BCJmpF i) = [toChar i] + _ = []] + where + toByteCode b = toChar $ consIndex{|*|} b + 1 + +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 toReadableByteVal :: BC -> String toReadableByteVal a = printToString a instance arith ByteCode where - lit x = BC [BCPush $ toCode x] + lit x = BC [BCPush $ 1] (+.) x y = x <++> y <+-> [BCAdd] (-.) x y = x <++> y <+-> [BCSub] (*.) x y = x <++> y <+-> [BCMul] @@ -45,12 +63,12 @@ instance boolExpr ByteCode where (>=.) x y = x <++> y <+-> [BCGeq] instance analogIO ByteCode where - analogRead p = BC [BCAnalogRead $ toCode p] - analogWrite p b = b <+-> [BCAnalogWrite $ toCode p] + analogRead p = BC [BCAnalogRead $ pin p] + analogWrite p b = b <+-> [BCAnalogWrite $ pin p] instance digitalIO ByteCode where - digitalRead p = BC [BCDigitalRead $ toCode p] - digitalWrite p b = b <+-> [BCDigitalWrite $ toCode p] + digitalRead p = BC [BCDigitalRead $ pin p] + digitalWrite p b = b <+-> [BCDigitalWrite $ pin 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 @@ -85,13 +103,22 @@ instance zero BCState where zero = {a=()} toRealByteCode :: (ByteCode a Expr) -> String -toRealByteCode (BC x) = concat $ map toByteVal x +toRealByteCode (BC x) = concat $ map (toString o toByteVal) x //Start :: ByteCode Int Expr //Start = (lit 36 +. lit 42) +. lit 84 +to16bit :: Int -> String +to16bit i = toString (toChar (i/265)) +++ toString (toChar (i rem 265)) + //Run test programma en pretty print -Start = toRealByteCode $ If (lit True) (analogRead A1) (analogRead A0) +Start :: String +Start = "t" +++ to16bit (size b) +++ b +//Start :: ByteCode Int Expr +//Start = bc + where + bc = If (lit True) (analogRead A1) (analogRead A0) + b = toRealByteCode bc //Start :: ByteCode Int Expr //Start = If (lit True) (analogRead A1) (analogRead A0) //Start = If ((lit 36) ==. (lit 42)) (noOp) (noOp) diff --git a/mTaskMakeSymbols.icl b/mTaskMakeSymbols.icl index bb4c33e..b505ee8 100644 --- a/mTaskMakeSymbols.icl +++ b/mTaskMakeSymbols.icl @@ -18,9 +18,9 @@ from Data.Func import $ import Data.List from Text import class Text(join,toUpperCase), instance Text String -derive consIndex BC -derive consName BC -derive conses BC, AnalogPin +derive consIndex BC, Pin +derive consName BC, Pin +derive conses BC, AnalogPin, DigitalPin, Pin (<+) infixr 5 :: a b -> String | toString a & toString b (<+) a b = toString a +++ toString b