X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=mTaskInterpret.icl;h=2c44484017529f042440435f10f12c6e2b780d22;hb=6abf86833edeae1742db393160db8a9e5c043889;hp=1833e6201e5f5472c8a8c05d5671a33846aaba77;hpb=f90517d738696125a067f113edf93f404873115b;p=mTask.git diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index 1833e62..2c44484 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -1,7 +1,9 @@ implementation module mTaskInterpret //import iTasks -import gdynamic, gCons, GenEq, StdMisc, StdArray, GenBimap +import Generics.gCons + +import GenEq, StdMisc, StdArray, GenBimap import GenPrint import StdEnum import mTask @@ -23,19 +25,23 @@ import qualified Data.Map as DM import Text.Encodings.Base64 encode :: MTaskMSGSend -> String -encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n" encode (MTTask to data) = "t" +++ to16bit to +++ to16bit (size data) +++ data +++ "\n" +encode (MTTaskDel i) = "d" +++ to16bit i +++ "\n" +encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n" encode (MTUpd i v) = "u" +++ to16bit i +++ v +++ "\n" decode :: String -> MTaskMSGRecv decode x | size x == 0 = MTEmpty = case x.[0] of + 't' = MTTaskAck (from16bit (x % (1,3))) + 'd' = MTTaskDelAck (from16bit (x % (1,3))) + 'm' = MTMessage x + 's' = MTSDSAck (from16bit (x % (1,3))) + 'a' = MTSDSDelAck (from16bit (x % (1,3))) + 'p' = MTPub (from16bit (x % (1,3))) (x % (3,5)) '\0' = MTEmpty '\n' = MTEmpty - 'm' = MTMessage x - 't' = MTTaskAdded (from16bit (x % (1,3))) - 'u' = MTPub (from16bit (x % (1,3))) (x % (3,5)) _ = MTMessage x//abort ("Didn't understand message: " +++ join " " [toString (toInt c)\\c<-: x] +++ "\n") safePrint :== toString o toJSON @@ -45,13 +51,18 @@ instance toString MTaskMSGSend where +++ " value " +++ safePrint v toString (MTTask to data) = "Task timeout: " +++ toString to +++ " data " +++ safePrint data + toString (MTTaskDel i) = "Task delete request: " +++ toString i toString (MTUpd i v) = "Update id: " +++ toString i +++ " value " +++ safePrint v instance toString MTaskMSGRecv where + toString (MTTaskAck i) = "Task added with id: " +++ toString i + toString (MTTaskDelAck i) = "Task deleted with id: " +++ toString i + toString (MTSDSAck i) = "SDS added with id: " +++ toString i + toString (MTSDSDelAck i) = "SDS deleted with id: " +++ toString i toString (MTPub i v) = "Publish id: " +++ toString i +++ " value " +++ safePrint v - toString (MTTaskAdded i) = "Task added with id: " +++ toString i + toString (MTMessage m) = m toString MTEmpty = "Empty message" bclength :: BC -> Int @@ -220,9 +231,9 @@ instance zero BCState where zero = {freshl=[1..], freshs=[1..], sdss=[]} -toRealByteCode :: (ByteCode a b) -> (String, BCState) -toRealByteCode x -# (bc, st) = runBC x zero +toRealByteCode :: (ByteCode a b) BCState -> (String, BCState) +toRealByteCode x s +# (bc, st) = runBC x s # (bc, gtmap) = computeGotos bc 1 = (concat $ map (toString o toByteVal) (map (implGotos gtmap) bc), st) @@ -256,7 +267,7 @@ toMessages interval (bytes, st=:{sdss}) = ([MTSds i (toString b)\\(i,b)<-sdss] + toSDSUpdate :: Int Int -> [MTaskMSGSend] toSDSUpdate i v = [MTUpd i (to16bit v)] -Start = toMessages 500 $ toRealByteCode (unMain bc) +Start = toMessages 500 $ toRealByteCode (unMain bc) zero where bc = sds \x=5 In sds \y=4 In