extend shares
[mTask.git] / mTaskInterpret.icl
index 635f68b..df59c28 100644 (file)
@@ -100,9 +100,9 @@ toByteVal b = {toChar $ consIndex{|*|} b} +++
        case b of
                (BCPush (BCValue i)) = toByteCode i
                (BCLab i) = {toChar i}
-               (BCSdsStore i) = to16bit i
-               (BCSdsFetch i) = to16bit i
-               (BCSdsPublish i) = to16bit i
+               (BCSdsStore i) = to16bit i.sdsi
+               (BCSdsFetch i) = to16bit i.sdsi
+               (BCSdsPublish i) = to16bit i.sdsi
                (BCAnalogRead i) = {toChar $ consIndex{|*|} i}
                (BCAnalogWrite i) = {toChar $ consIndex{|*|} i}
                (BCDigitalRead i) = {toChar $ consIndex{|*|} i}
@@ -166,7 +166,7 @@ instance fromByteCode MTaskDeviceSpec where
                }
 
 derive gPrint Long, UserLED, Button, AnalogPin, DigitalPin, PinMode, Pin, BC, MTaskDeviceSpec
-derive class gCons BC
+derive class gCons BC, BCShare
 
 consIndex{|BCValue|} _ = 0
 consName{|BCValue|} _ = "BCValue"
@@ -251,18 +251,16 @@ instance noOp ByteCode where noOp = tell` [BCNop]
 unBC (BC x) = x
 
 instance sds ByteCode where
-       sds f = {main = BC $ freshs 
+       sds f = {main = BC $ freshs
+                               >>= \sdsi->pure {BCShare | sdsi=sdsi,sdsval=BCValue 0}
                                >>= \sds->pure (f (tell` [BCSdsFetch sds]))
-                               >>= \(v In bdy)->modify (addSDS sds v) >>| unBC (unMain bdy)}
-//                             >>= \(v In bdy)->modify (addSDS sds (toByteCode v)) >>| unBC (unMain bdy)}
+                               >>= \(v In bdy)->modify (addSDS sds v)
+                               >>| unBC (unMain bdy)}
                where
-                       addSDS i v s = {s & sdss=[{sdsi=i,sdspub=False,sdsval=(BCValue v)}:s.sdss]}
+                       addSDS sds v s = {s & sdss=[{sds & sdsval=BCValue v}:s.sdss]}
 
        con f = undef
-       pub (BC x) = BC $ censor (\[BCSdsFetch s]->[BCSdsPublish s])
-                       (listen x >>= \(_, [BCSdsFetch s])->modify (publish s)) >>| tell mempty
-               where
-                       publish i st = {st & sdss=[if (i == s.sdsi) {s & sdspub=True} s \\s<-st.sdss]}
+       pub (BC x) = BC $ censor (\[BCSdsFetch s]->[BCSdsPublish s]) x
 
 instance assign ByteCode where
        (=.) (BC v) (BC e) = BC $ e >>| censor makeStore v