diff --git a/common/ShowCode.hs b/common/ShowCode.hs index 74ad611..f76d4ef 100644 --- a/common/ShowCode.hs +++ b/common/ShowCode.hs @@ -255,11 +255,9 @@ instance ShowOccam A.Type where = tell [shared, "CHAN", direction, " "] >> showOccamM t where shared - = case (A.caWritingShared ca, A.caReadingShared ca) of - (A.Unshared, A.Unshared) -> "" - (A.Shared, A.Unshared) -> "SHARED! " - (A.Unshared, A.Shared) -> "SHARED? " - (A.Shared, A.Shared) -> "SHARED " + = case ca of + A.Unshared -> "" + A.Shared -> "SHARED " direction = case dir of A.DirInput -> "?" @@ -303,8 +301,8 @@ instance ShowRain A.Type where ao b = if b == A.Shared then "any" else "one" showRainM (A.ChanEnd dir attr t) = case dir of - A.DirInput -> tell [if A.caReadingShared attr == A.Shared then "shared" else "", " ?"] >> showRainM t - A.DirOutput -> tell [if A.caWritingShared attr == A.Shared then "shared" else "", " !"] >> showRainM t + A.DirInput -> tell [if attr == A.Shared then "shared" else "", " ?"] >> showRainM t + A.DirOutput -> tell [if attr == A.Shared then "shared" else "", " !"] >> showRainM t where ao :: Bool -> String ao b = if b then "any" else "one" diff --git a/common/Types.hs b/common/Types.hs index b529c4b..b0e97c0 100644 --- a/common/Types.hs +++ b/common/Types.hs @@ -29,7 +29,7 @@ module Types mulExprs, divExprs , addDimensions, applyDimension, removeFixedDimensions, trivialSubscriptType, subscriptType, unsubscriptType , applyDirection - , recordFields, recordAttr, protocolItems + , recordFields, recordAttr, protocolItems, dirAttr , leastGeneralSharedTypeRain @@ -133,6 +133,9 @@ recordAttr m (A.Record rec) _ -> dieP m "not record type" recordAttr m _ = dieP m "not record type" +dirAttr :: A.Direction -> A.ChanAttributes -> A.ShareMode +dirAttr A.DirInput = A.caReadingShared +dirAttr A.DirOutput = A.caWritingShared -- | Get the type of a record field. typeOfRecordField :: (CSMR m, Die m) => Meta -> A.Type -> A.Name -> m A.Type @@ -228,14 +231,14 @@ typeOfVariable (A.DirectedVariable m dir v) if dir == dir' then return t else dieP m $ "Attempted to reverse direction of a channel-end" - A.Chan attr innerT -> return $ A.ChanEnd dir attr innerT + A.Chan attr innerT -> return $ A.ChanEnd dir (dirAttr dir attr) innerT A.Array ds (A.Chan attr innerT) - -> return $ A.Array ds (A.ChanEnd dir attr innerT) + -> return $ A.Array ds (A.ChanEnd dir (dirAttr dir attr) innerT) A.Array _ (A.ChanEnd dir' _ _) -> if dir == dir' then return t else dieP m $ "Attempted to reverse direction of a channel-end" - A.Infer -> return $ A.ChanEnd dir (A.ChanAttributes A.Unshared A.Unshared) A.Infer + A.Infer -> return $ A.ChanEnd dir A.Unshared A.Infer _ -> diePC m $ formatCode "Direction specified on non-channel variable of type: %" t -- | Get the abbreviation mode of a variable. @@ -415,7 +418,7 @@ applyDirection :: Die m => Meta -> A.Direction -> A.Type -> m A.Type applyDirection m dir (A.Array ds t) = applyDirection m dir t >>* A.Array ds applyDirection m dir (A.Chan ca t) - = return $ A.ChanEnd dir ca t + = return $ A.ChanEnd dir (dirAttr dir ca) t applyDirection m _ t = dieP m "Direction specified on non-channel type" diff --git a/data/AST.hs b/data/AST.hs index dd29174..828fad1 100644 --- a/data/AST.hs +++ b/data/AST.hs @@ -133,7 +133,7 @@ data Type = -- | A channel of the specified type. | Chan ChanAttributes Type -- | A channel end of the specified type. - | ChanEnd Direction ChanAttributes Type + | ChanEnd Direction ShareMode Type -- | A counted input or output. -- The first type is that of the count; the second is that of the array. -- (For example, @INT::[]BYTE@ would be @A.Counted A.Int (A.Array ...)@). diff --git a/frontends/OccamTypes.hs b/frontends/OccamTypes.hs index 4d99e5c..41b4a42 100644 --- a/frontends/OccamTypes.hs +++ b/frontends/OccamTypes.hs @@ -428,14 +428,13 @@ checkChannel wantDir c = do -- Check it's a channel. t <- astTypeOf c >>= resolveUserType m case t of - A.ChanEnd dir (A.ChanAttributes ws rs) innerT -> + A.ChanEnd dir sh innerT -> do -- Check the direction is appropriate when (wantDir /= dir) $ dieP m $ "Channel directions do not match" -- Check it's not shared in the direction we're using. - case (ws, rs, wantDir) of - (A.Unshared, _, A.DirOutput) -> ok - (_, A.Unshared, A.DirInput) -> ok - _ -> dieP m $ "Shared channel must be claimed before use" + case sh of + A.Unshared -> ok + A.Shared -> dieP m $ "Shared channel must be claimed before use" return innerT _ -> diePC m $ formatCode ("Expected channel " ++ exp ++ "; found %") t @@ -851,7 +850,7 @@ inferTypes = occamOnlyPass "Infer types" do dirs <- ask >>= (lift . findDir n) case nub dirs of [dir] -> - do let tEnd = A.ChanEnd dir attr innerT + do let tEnd = A.ChanEnd dir (dirAttr dir attr) innerT return (tEnd, A.DirectedVariable m dir v') _ -> return (vt, v') -- no direction, or two (A.Infer, _) -> return (vt, v') @@ -870,7 +869,7 @@ inferTypes = occamOnlyPass "Infer types" do dirs <- ask >>= (lift . findDir n) case nub dirs of [dir] -> - do let tEnd = A.ChanEnd dir attr innerT + do let tEnd = A.ChanEnd dir (dirAttr dir attr) innerT return (tEnd, A.DirectedVariable m dir v') _ -> return (t', v') -- no direction, or two _ -> return (t', v') @@ -904,7 +903,7 @@ inferTypes = occamOnlyPass "Infer types" A.Array ds (A.Chan attr innerT) -> do dirs <- ask >>= (lift . findDir n) case nub dirs of - [dir] -> return (A.Array ds $ A.ChanEnd dir attr innerT + [dir] -> return (A.Array ds $ A.ChanEnd dir (dirAttr dir attr) innerT ,A.DirectedVariable m dir) _ -> return (t'', id) _ -> return (t'', id) @@ -931,7 +930,7 @@ inferTypes = occamOnlyPass "Infer types" do dirs <- findDir n body case nub dirs of [dir] -> - do let t' = A.ChanEnd dir attr innerT + do let t' = A.ChanEnd dir (dirAttr dir attr) innerT f' = A.Formal am t' n modifyName n (\nd -> nd {A.ndSpecType = A.Declaration m t'}) diff --git a/frontends/ParseOccam.hs b/frontends/ParseOccam.hs index 0cbde60..5438a25 100644 --- a/frontends/ParseOccam.hs +++ b/frontends/ParseOccam.hs @@ -1182,7 +1182,7 @@ definition dir <- direction sColon eol - return (n, A.ChanEnd dir (A.ChanAttributes A.Unshared A.Unshared) t) + return (n, A.ChanEnd dir A.Unshared t) retypesAbbrev :: OccParser NameSpec retypesAbbrev diff --git a/frontends/ParseRain.hs b/frontends/ParseRain.hs index f42c0c1..706b49a 100644 --- a/frontends/ParseRain.hs +++ b/frontends/ParseRain.hs @@ -168,8 +168,8 @@ dataType <|> do {reserved "sint64" ; return A.Int64} <|> do {reserved "time" ; return A.Time} <|> do {sChannel ; inner <- dataType ; return $ A.Chan (A.ChanAttributes {A.caWritingShared = A.Unshared, A.caReadingShared = A.Unshared}) inner} - <|> do {sIn ; inner <- dataType ; return $ A.ChanEnd A.DirInput (A.ChanAttributes {A.caWritingShared = A.Unshared, A.caReadingShared = A.Unshared}) inner} - <|> do {sOut ; inner <- dataType ; return $ A.ChanEnd A.DirOutput (A.ChanAttributes {A.caWritingShared = A.Unshared, A.caReadingShared = A.Unshared}) inner} + <|> do {sIn ; inner <- dataType ; return $ A.ChanEnd A.DirInput A.Unshared inner} + <|> do {sOut ; inner <- dataType ; return $ A.ChanEnd A.DirOutput A.Unshared inner} <|> do {sLeftQ ; inner <- dataType ; sRightQ ; return $ A.List inner} <|> do {(m,n) <- identifier ; return $ A.UserDataType A.Name {A.nameMeta = m, A.nameName = n}} "data type" diff --git a/frontends/RainTypes.hs b/frontends/RainTypes.hs index 0a851cc..e076acc 100644 --- a/frontends/RainTypes.hs +++ b/frontends/RainTypes.hs @@ -282,8 +282,7 @@ markCommTypes = checkDepthM2 checkInputOutput checkAltInput where checkInput :: A.Variable -> A.Variable -> Meta -> a -> RainTypeM () checkInput chanVar destVar m p - = astTypeOf destVar >>= markUnify chanVar . A.ChanEnd A.DirInput (A.ChanAttributes - A.Unshared A.Unshared) + = astTypeOf destVar >>= markUnify chanVar . A.ChanEnd A.DirInput A.Unshared checkWait :: RainTypeCheck A.InputMode checkWait (A.InputTimerFor m exp) = markUnify A.Time exp @@ -298,8 +297,7 @@ markCommTypes = checkDepthM2 checkInputOutput checkAltInput checkInputOutput (A.Input _ _ im@(A.InputTimerAfter {})) = checkWait im checkInputOutput (A.Input _ _ im@(A.InputTimerRead {})) = checkWait im checkInputOutput p@(A.Output m chanVar [A.OutExpression m' srcExp]) - = astTypeOf srcExp >>= markUnify chanVar . A.ChanEnd A.DirOutput (A.ChanAttributes - A.Unshared A.Unshared) + = astTypeOf srcExp >>= markUnify chanVar . A.ChanEnd A.DirOutput A.Unshared checkInputOutput _ = return () checkAltInput :: RainTypeCheck A.Alternative diff --git a/transformations/SimplifyExprs.hs b/transformations/SimplifyExprs.hs index 9379714..b84c02d 100644 --- a/transformations/SimplifyExprs.hs +++ b/transformations/SimplifyExprs.hs @@ -460,7 +460,7 @@ pullUp pullUpArraysInsideRecords = pass "Pull up definitions" n) v) innerV (replicate i $ makeConstant m 0) | (d, i) <- zip ds [0..]] spec@(A.Specification _ n _) <- makeNonceIs "dir_array" m - (A.Array ds' $ A.ChanEnd dir attr innerT) A.Abbrev v + (A.Array ds' $ A.ChanEnd dir (dirAttr dir attr) innerT) A.Abbrev v addPulled $ (m, Left spec) return $ A.Variable m n _ -> descend v