+ zero = {freshl=[1..], freshs=[1..], sdss=[]}
+
+
+toRealByteCode :: (ByteCode a b) -> (String, BCState)
+toRealByteCode x
+# (bc, st) = runBC x zero
+# (bc, gtmap) = computeGotos bc 1
+= (concat $ map (toString o toByteVal) (map (implGotos gtmap) bc), st)
+
+implGotos map (BCJmp t) = BCJmp $ fromJust ('DM'.get t map)
+implGotos map (BCJmpT t) = BCJmpT $ fromJust ('DM'.get t map)
+implGotos map (BCJmpF t) = BCJmpF $ fromJust ('DM'.get t map)
+implGotos _ i = i
+
+computeGotos :: [BC] Int -> ([BC], 'DM'.Map Int Int)
+computeGotos [] _ = ([], 'DM'.newMap)
+computeGotos [BCLab l:xs] i = appSnd ('DM'.put l i) (computeGotos xs i)
+computeGotos [x:xs] i = appFst (\bc->[x:bc]) (computeGotos xs (i+(bclength x)))
+
+readable :: BC -> String
+readable (BCPush d) = "BCPush " +++ concat (map safe d)
+ where
+ safe c
+ | isControl c = "\\d" +++ toString (toInt c)
+ = toString c
+readable b = printToString b
+
+toReadableByteCode :: (ByteCode a b) -> (String, BCState)
+toReadableByteCode x
+# (bc, st) = runBC x zero
+# (bc, gtmap) = computeGotos bc 0
+= (join "\n" $ map readable (map (implGotos gtmap) bc), st)
+
+toMessages :: Int (String, BCState) -> ([MTaskMSGSend], BCState)
+toMessages interval (bytes, st=:{sdss}) = ([MTSds i (toString b)\\(i,b)<-sdss] ++ [MTTask interval bytes], st)
+
+toSDSUpdate :: Int Int -> [MTaskMSGSend]
+toSDSUpdate i v = [MTUpd i (to16bit v)]
+
+Start = toMessages 500 $ toRealByteCode (unMain bc)
+ where
+ bc = sds \x=5 In
+ sds \y=4 In
+ {main = If (y ==. lit 0) (pub x) (x =. x *. y :. y =. y -. lit 1)}