Introduced a ShareMode in the AST, and used it in the channel attributes (rather than Bool)
This commit is contained in:
parent
7b52565270
commit
8492dc03d4
|
@ -441,7 +441,7 @@ mobileReturn = cOnlyPass "Add MOBILE returns" [] [] recurse
|
||||||
return $ surr $ A.ProcCall m n as'
|
return $ surr $ A.ProcCall m n as'
|
||||||
doProcess p = descend p
|
doProcess p = descend p
|
||||||
|
|
||||||
chanT t = A.Chan (A.ChanAttributes False False) t
|
chanT t = A.Chan (A.ChanAttributes A.Unshared A.Unshared) t
|
||||||
|
|
||||||
addChansAct :: Meta -> [(A.Formal, A.Actual)] -> PassM (A.Process -> A.Process, [A.Actual])
|
addChansAct :: Meta -> [(A.Formal, A.Actual)] -> PassM (A.Process -> A.Process, [A.Actual])
|
||||||
addChansAct _ [] = return (id, [])
|
addChansAct _ [] = return (id, [])
|
||||||
|
|
|
@ -655,10 +655,10 @@ cppgetCType m t am | isChan t
|
||||||
A.ChanEnd A.DirOutput _ innerT -> ("csp::Chanout", innerT)
|
A.ChanEnd A.DirOutput _ innerT -> ("csp::Chanout", innerT)
|
||||||
A.Chan attr innerT -> (
|
A.Chan attr innerT -> (
|
||||||
case (A.caWritingShared attr,A.caReadingShared attr) of
|
case (A.caWritingShared attr,A.caReadingShared attr) of
|
||||||
(False,False) -> "csp::One2OneChannel"
|
(A.Unshared,A.Unshared) -> "csp::One2OneChannel"
|
||||||
(False,True) -> "csp::One2AnyChannel"
|
(A.Unshared,A.Shared) -> "csp::One2AnyChannel"
|
||||||
(True,False) -> "csp::Any2OneChannel"
|
(A.Shared,A.Unshared) -> "csp::Any2OneChannel"
|
||||||
(True,True) -> "csp::Any2AnyChannel"
|
(A.Shared,A.Shared) -> "csp::Any2AnyChannel"
|
||||||
, innerT)
|
, innerT)
|
||||||
innerCT <- cppTypeInsideChannel innerT
|
innerCT <- cppTypeInsideChannel innerT
|
||||||
return $ Template chanType [innerCT]
|
return $ Template chanType [innerCT]
|
||||||
|
|
|
@ -254,10 +254,10 @@ instance ShowOccam A.Type where
|
||||||
where
|
where
|
||||||
shared
|
shared
|
||||||
= case (A.caWritingShared ca, A.caReadingShared ca) of
|
= case (A.caWritingShared ca, A.caReadingShared ca) of
|
||||||
(False, False) -> ""
|
(A.Unshared, A.Unshared) -> ""
|
||||||
(True, False) -> "SHARED! "
|
(A.Shared, A.Unshared) -> "SHARED! "
|
||||||
(False, True) -> "SHARED? "
|
(A.Unshared, A.Shared) -> "SHARED? "
|
||||||
(True, True) -> "SHARED "
|
(A.Shared, A.Shared) -> "SHARED "
|
||||||
direction
|
direction
|
||||||
= case dir of
|
= case dir of
|
||||||
A.DirInput -> "?"
|
A.DirInput -> "?"
|
||||||
|
@ -267,10 +267,10 @@ instance ShowOccam A.Type where
|
||||||
where
|
where
|
||||||
shared
|
shared
|
||||||
= case (A.caWritingShared ca, A.caReadingShared ca) of
|
= case (A.caWritingShared ca, A.caReadingShared ca) of
|
||||||
(False, False) -> ""
|
(A.Unshared, A.Unshared) -> ""
|
||||||
(True, False) -> "SHARED! "
|
(A.Shared, A.Unshared) -> "SHARED! "
|
||||||
(False, True) -> "SHARED? "
|
(A.Unshared, A.Shared) -> "SHARED? "
|
||||||
(True, True) -> "SHARED "
|
(A.Shared, A.Shared) -> "SHARED "
|
||||||
showOccamM (A.Counted ct et) = showOccamM ct >> tell ["::"] >> showOccamM et
|
showOccamM (A.Counted ct et) = showOccamM ct >> tell ["::"] >> showOccamM et
|
||||||
showOccamM (A.Port t) = tell ["PORT "] >> showOccamM t
|
showOccamM (A.Port t) = tell ["PORT "] >> showOccamM t
|
||||||
showOccamM (A.UserDataType n) = showName n >> helper "{data type}"
|
showOccamM (A.UserDataType n) = showName n >> helper "{data type}"
|
||||||
|
@ -293,12 +293,12 @@ instance ShowRain A.Type where
|
||||||
= tell ["channel ", ao (A.caWritingShared attr),
|
= tell ["channel ", ao (A.caWritingShared attr),
|
||||||
"2", ao (A.caReadingShared attr)," "] >> showRainM t
|
"2", ao (A.caReadingShared attr)," "] >> showRainM t
|
||||||
where
|
where
|
||||||
ao :: Bool -> String
|
ao :: A.ShareMode -> String
|
||||||
ao b = if b then "any" else "one"
|
ao b = if b == A.Shared then "any" else "one"
|
||||||
showRainM (A.ChanEnd dir attr t)
|
showRainM (A.ChanEnd dir attr t)
|
||||||
= case dir of
|
= case dir of
|
||||||
A.DirInput -> tell [if A.caReadingShared attr then "shared" else "", " ?"] >> showRainM t
|
A.DirInput -> tell [if A.caReadingShared attr == A.Shared then "shared" else "", " ?"] >> showRainM t
|
||||||
A.DirOutput -> tell [if A.caWritingShared attr then "shared" else "", " !"] >> showRainM t
|
A.DirOutput -> tell [if A.caWritingShared attr == A.Shared then "shared" else "", " !"] >> showRainM t
|
||||||
where
|
where
|
||||||
ao :: Bool -> String
|
ao :: Bool -> String
|
||||||
ao b = if b then "any" else "one"
|
ao b = if b then "any" else "one"
|
||||||
|
|
|
@ -235,7 +235,7 @@ typeOfVariable (A.DirectedVariable m dir v)
|
||||||
if dir == dir'
|
if dir == dir'
|
||||||
then return t
|
then return t
|
||||||
else dieP m $ "Attempted to reverse direction of a channel-end"
|
else dieP m $ "Attempted to reverse direction of a channel-end"
|
||||||
A.Infer -> return $ A.ChanEnd dir (A.ChanAttributes False False) A.Infer
|
A.Infer -> return $ A.ChanEnd dir (A.ChanAttributes A.Unshared A.Unshared) A.Infer
|
||||||
_ -> diePC m $ formatCode "Direction specified on non-channel variable of type: %" t
|
_ -> diePC m $ formatCode "Direction specified on non-channel variable of type: %" t
|
||||||
|
|
||||||
-- | Get the abbreviation mode of a variable.
|
-- | Get the abbreviation mode of a variable.
|
||||||
|
|
|
@ -80,10 +80,15 @@ data Direction =
|
||||||
| DirOutput -- ^ The output end.
|
| DirOutput -- ^ The output end.
|
||||||
deriving (Show, Eq, Typeable, Data)
|
deriving (Show, Eq, Typeable, Data)
|
||||||
|
|
||||||
|
data ShareMode
|
||||||
|
= Unshared
|
||||||
|
| Shared
|
||||||
|
deriving (Show, Eq, Typeable, Data)
|
||||||
|
|
||||||
-- | Attributes of the type of a channel.
|
-- | Attributes of the type of a channel.
|
||||||
data ChanAttributes = ChanAttributes {
|
data ChanAttributes = ChanAttributes {
|
||||||
caWritingShared :: Bool,
|
caWritingShared :: ShareMode,
|
||||||
caReadingShared :: Bool
|
caReadingShared :: ShareMode
|
||||||
}
|
}
|
||||||
deriving (Show, Eq, Typeable, Data)
|
deriving (Show, Eq, Typeable, Data)
|
||||||
|
|
||||||
|
|
|
@ -433,8 +433,8 @@ checkChannel wantDir c
|
||||||
when (wantDir /= dir) $ dieP m $ "Channel directions do not match"
|
when (wantDir /= dir) $ dieP m $ "Channel directions do not match"
|
||||||
-- Check it's not shared in the direction we're using.
|
-- Check it's not shared in the direction we're using.
|
||||||
case (ws, rs, wantDir) of
|
case (ws, rs, wantDir) of
|
||||||
(False, _, A.DirOutput) -> ok
|
(A.Unshared, _, A.DirOutput) -> ok
|
||||||
(_, False, A.DirInput) -> ok
|
(_, A.Unshared, A.DirInput) -> ok
|
||||||
_ -> dieP m $ "Shared channel must be claimed before use"
|
_ -> dieP m $ "Shared channel must be claimed before use"
|
||||||
|
|
||||||
return innerT
|
return innerT
|
||||||
|
|
|
@ -74,7 +74,7 @@ startState
|
||||||
where
|
where
|
||||||
intsT = A.Array [A.UnknownDimension] A.Int
|
intsT = A.Array [A.UnknownDimension] A.Int
|
||||||
arrayLit = A.ArrayListLiteral m $ A.Several m []
|
arrayLit = A.ArrayListLiteral m $ A.Several m []
|
||||||
chanT t = A.Chan (A.ChanAttributes False False) t
|
chanT t = A.Chan (A.ChanAttributes A.Unshared A.Unshared) t
|
||||||
chanIntT = chanT A.Int
|
chanIntT = chanT A.Int
|
||||||
countedIntsT = chanT $ A.UserProtocol (simpleName "countedInts")
|
countedIntsT = chanT $ A.UserProtocol (simpleName "countedInts")
|
||||||
iirT = chanT $ A.UserProtocol (simpleName "iir")
|
iirT = chanT $ A.UserProtocol (simpleName "iir")
|
||||||
|
@ -564,7 +564,7 @@ testOccamTypes = TestList
|
||||||
coord2E = A.Literal m coord2T coord2
|
coord2E = A.Literal m coord2T coord2
|
||||||
coord3T = A.Record (simpleName "COORD3")
|
coord3T = A.Record (simpleName "COORD3")
|
||||||
coord3 = A.RecordLiteral m [realE, realE, realE]
|
coord3 = A.RecordLiteral m [realE, realE, realE]
|
||||||
chanT t = A.Chan (A.ChanAttributes False False) t
|
chanT t = A.Chan (A.ChanAttributes A.Unshared A.Unshared) t
|
||||||
chanIntT = chanT A.Int
|
chanIntT = chanT A.Int
|
||||||
chansIntT = A.Array [dimension 2] $ chanT A.Int
|
chansIntT = A.Array [dimension 2] $ chanT A.Int
|
||||||
uchansIntT = A.Array [A.UnknownDimension] $ chanT A.Int
|
uchansIntT = A.Array [A.UnknownDimension] $ chanT A.Int
|
||||||
|
|
|
@ -545,7 +545,7 @@ dataType
|
||||||
|
|
||||||
channelType :: OccParser A.Type
|
channelType :: OccParser A.Type
|
||||||
channelType
|
channelType
|
||||||
= do { sCHAN; optional sOF; p <- protocol; return $ A.Chan A.ChanAttributes {A.caWritingShared = False, A.caReadingShared = False} p }
|
= do { sCHAN; optional sOF; p <- protocol; return $ A.Chan A.ChanAttributes {A.caWritingShared = A.Unshared, A.caReadingShared = A.Unshared} p }
|
||||||
<|> arrayType channelType
|
<|> arrayType channelType
|
||||||
<?> "channel type"
|
<?> "channel type"
|
||||||
|
|
||||||
|
|
|
@ -167,9 +167,9 @@ dataType
|
||||||
<|> do {reserved "sint32" ; return A.Int32}
|
<|> do {reserved "sint32" ; return A.Int32}
|
||||||
<|> do {reserved "sint64" ; return A.Int64}
|
<|> do {reserved "sint64" ; return A.Int64}
|
||||||
<|> do {reserved "time" ; return A.Time}
|
<|> do {reserved "time" ; return A.Time}
|
||||||
<|> do {sChannel ; inner <- dataType ; return $ A.Chan (A.ChanAttributes {A.caWritingShared = False, A.caReadingShared = False}) inner}
|
<|> 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 = False, A.caReadingShared = False}) 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 = False, A.caReadingShared = False}) inner}
|
<|> do {sOut ; inner <- dataType ; return $ A.ChanEnd A.DirOutput (A.ChanAttributes {A.caWritingShared = A.Unshared, A.caReadingShared = A.Unshared}) inner}
|
||||||
<|> do {sLeftQ ; inner <- dataType ; sRightQ ; return $ A.List 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}}
|
<|> do {(m,n) <- identifier ; return $ A.UserDataType A.Name {A.nameMeta = m, A.nameName = n}}
|
||||||
<?> "data type"
|
<?> "data type"
|
||||||
|
|
|
@ -531,7 +531,7 @@ testTopLevelDecl =
|
||||||
passTop (ind, input, exp) = pass (input, RP.topLevelDecl, assertPatternMatch ("testTopLevelDecl " ++ show ind) $ pat $ A.Several m exp)
|
passTop (ind, input, exp) = pass (input, RP.topLevelDecl, assertPatternMatch ("testTopLevelDecl " ++ show ind) $ pat $ A.Several m exp)
|
||||||
|
|
||||||
nonShared :: A.ChanAttributes
|
nonShared :: A.ChanAttributes
|
||||||
nonShared = A.ChanAttributes { A.caWritingShared = False, A.caReadingShared = False}
|
nonShared = A.ChanAttributes { A.caWritingShared = A.Unshared, A.caReadingShared = A.Unshared}
|
||||||
|
|
||||||
testDataType :: [ParseTest A.Type]
|
testDataType :: [ParseTest A.Type]
|
||||||
testDataType =
|
testDataType =
|
||||||
|
|
|
@ -283,7 +283,7 @@ markCommTypes = checkDepthM2 checkInputOutput checkAltInput
|
||||||
checkInput :: A.Variable -> A.Variable -> Meta -> a -> RainTypeM ()
|
checkInput :: A.Variable -> A.Variable -> Meta -> a -> RainTypeM ()
|
||||||
checkInput chanVar destVar m p
|
checkInput chanVar destVar m p
|
||||||
= astTypeOf destVar >>= markUnify chanVar . A.ChanEnd A.DirInput (A.ChanAttributes
|
= astTypeOf destVar >>= markUnify chanVar . A.ChanEnd A.DirInput (A.ChanAttributes
|
||||||
False False)
|
A.Unshared A.Unshared)
|
||||||
|
|
||||||
checkWait :: RainTypeCheck A.InputMode
|
checkWait :: RainTypeCheck A.InputMode
|
||||||
checkWait (A.InputTimerFor m exp) = markUnify A.Time exp
|
checkWait (A.InputTimerFor m exp) = markUnify A.Time exp
|
||||||
|
@ -299,7 +299,7 @@ markCommTypes = checkDepthM2 checkInputOutput checkAltInput
|
||||||
checkInputOutput (A.Input _ _ im@(A.InputTimerRead {})) = checkWait im
|
checkInputOutput (A.Input _ _ im@(A.InputTimerRead {})) = checkWait im
|
||||||
checkInputOutput p@(A.Output m chanVar [A.OutExpression m' srcExp])
|
checkInputOutput p@(A.Output m chanVar [A.OutExpression m' srcExp])
|
||||||
= astTypeOf srcExp >>= markUnify chanVar . A.ChanEnd A.DirOutput (A.ChanAttributes
|
= astTypeOf srcExp >>= markUnify chanVar . A.ChanEnd A.DirOutput (A.ChanAttributes
|
||||||
False False)
|
A.Unshared A.Unshared)
|
||||||
checkInputOutput _ = return ()
|
checkInputOutput _ = return ()
|
||||||
|
|
||||||
checkAltInput :: RainTypeCheck A.Alternative
|
checkAltInput :: RainTypeCheck A.Alternative
|
||||||
|
|
Loading…
Reference in New Issue
Block a user