From: Mart Lubbers Date: Fri, 16 Dec 2016 18:53:24 +0000 (+0100) Subject: read and write sds X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=db7588d3c42ad9e1b5af5a6f3d08c82a8b0ccf0d;p=mTask.git read and write sds --- diff --git a/mTask.dcl b/mTask.dcl index 4ecf37d..d71ba44 100644 --- a/mTask.dcl +++ b/mTask.dcl @@ -86,7 +86,7 @@ class var2 v where var2 :: t ((v t Upd)->(Main (v c s))) -> (Main (v c s)) | type, toCode t con2 :: t ((v t Expr) ->(Main (v c s))) -> (Main (v c s)) | type t class sds v where - sds :: ((v t Upd)->In t (Main (v c s))) -> (Main (v c s)) | type, toCode t + sds :: ((v t Upd)->In t (Main (v c s))) -> (Main (v c s)) | type, toByteCode, toCode t con :: ((v t Expr) ->In t (Main (v c s))) -> (Main (v c s)) | type t class seq v where (>>=.) infixr 0 :: (v t p) ((v t Expr) -> (v u q)) -> (v u Stmt) | type t & type u diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index ab86aed..81bf135 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -49,11 +49,13 @@ runBC (BC m) = m retrn :: ([BC] -> ByteCode a p) retrn = BC o tuple +fmp :: ([BC] -> [BC]) (ByteCode a p) -> ByteCode a p +fmp f b = BC \s->let (bc, s`) = runBC b s in (f bc, s`) instance toByteCode Bool where toByteCode True = [toChar 1] toByteCode False = [toChar 0] -instance toByteCode Int where toByteCode n = map toChar [n/(2<<7),n rem 265] +instance toByteCode Int where toByteCode n = map toChar [n/256,n rem 256] instance toByteCode Long where toByteCode (L n) = toByteCode n instance toByteCode Char where toByteCode c = [c] instance toByteCode String where toByteCode s = undef @@ -105,7 +107,6 @@ BCIfStmt b t e = withLabel \else->withLabel \endif->retrn [BCJmpF else] <++> t instance noOp ByteCode where noOp = mempty - withLabel :: (Int -> (ByteCode b q)) -> ByteCode b q withLabel f = BC \s->let [fresh:fs] = s.freshl in runBC (f fresh) {s & freshl=fs} @@ -116,13 +117,18 @@ withSDS f = BC \s->let [fresh:fs] = s.freshs instance sds ByteCode where sds f = {main = withSDS \sds-> - let (v In body) = f $ retrn [BCSdsStore sds] - in unMain body <++> retrn [BCSdsStore sds] + let (v In body) = f $ retrn [BCSdsFetch sds] + in retrn [BCPush $ toByteCode v,BCSdsStore sds] <++> unMain body } con f = undef instance assign ByteCode where - (=.) v e = e <++> abort (printToString $ fst $ runBC v zero) + (=.) v e = e <++> fmp makeStore v + +makeStore [] = [] +makeStore [x:xs] = case x of + BCSdsFetch i = [BCSdsStore i:xs] + y = [y:xs] instance seq ByteCode where (>>=.) _ _ = abort "undef on >>=." @@ -148,10 +154,6 @@ toReadableByteCode x # (bc, st) = runBC x zero = join "\n" $ map printToString bc -toReadableByteVal :: BC -> String -toReadableByteVal a = printToString a - - //Start :: String //Start = toReadableByteCode bc // where @@ -159,12 +161,13 @@ toReadableByteVal a = printToString a // bc = (lit 36 +. lit 42) +. lit 44 Start :: String -Start = toReadableByteCode $ unMain bc +//Start = toReadableByteCode $ unMain bc +Start = toRealByteCode $ unMain bc where bc :: Main (ByteCode Int Expr) - bc = sds \x=46 In - sds \y=46 In - {main = y =. x +. y} + bc = sds \x=41 In + sds \y=1 In + {main = x =. x +. y} //to16bit :: Int -> String //to16bit i = toString (toChar (i/265)) +++ toString (toChar (i rem 265))