Changed Rain to use the new timer type rather than things like the GetTime statement
This commit is contained in:
parent
c68aa42277
commit
cbbafffbd2
|
@ -202,14 +202,22 @@ genCPPCSPChannelOutput var
|
||||||
--Since this is too large to be contained in an int once it has been multiplied,
|
--Since this is too large to be contained in an int once it has been multiplied,
|
||||||
--the remainder is taken to trim the timer back down to something that will be useful in an int
|
--the remainder is taken to trim the timer back down to something that will be useful in an int
|
||||||
cppgenTimerRead :: A.Variable -> A.Variable -> CGen ()
|
cppgenTimerRead :: A.Variable -> A.Variable -> CGen ()
|
||||||
cppgenTimerRead c v
|
cppgenTimerRead c v = do
|
||||||
= do tell ["csp::CurrentTime (&"]
|
tt <- typeOfVariable c
|
||||||
|
case tt of
|
||||||
|
A.Timer A.RainTimer ->
|
||||||
|
do tell ["csp::CurrentTime (&"]
|
||||||
|
call genVariable v
|
||||||
|
tell [");"]
|
||||||
|
A.Timer A.OccamTimer ->
|
||||||
|
do tell ["csp::CurrentTime (&"]
|
||||||
call genVariable c
|
call genVariable c
|
||||||
tell [");\n"]
|
tell [");\n"]
|
||||||
call genVariable v
|
call genVariable v
|
||||||
tell [" = (int)(unsigned)remainder(1000000.0 * csp::GetSeconds("]
|
tell [" = (int)(unsigned)remainder(1000000.0 * csp::GetSeconds("]
|
||||||
call genVariable c
|
call genVariable c
|
||||||
tell ["),4294967296.0);\n"]
|
tell ["),4294967296.0);"]
|
||||||
|
_ -> call genMissing $ "Unsupported timer type: " ++ show tt
|
||||||
|
|
||||||
cppgenGetTime :: A.Variable -> CGen ()
|
cppgenGetTime :: A.Variable -> CGen ()
|
||||||
cppgenGetTime v
|
cppgenGetTime v
|
||||||
|
|
|
@ -460,6 +460,9 @@ data InputMode =
|
||||||
| InputTimerRead Meta InputItem
|
| InputTimerRead Meta InputItem
|
||||||
-- | Wait for a particular time to go past on a timer.
|
-- | Wait for a particular time to go past on a timer.
|
||||||
| InputTimerAfter Meta Expression
|
| InputTimerAfter Meta Expression
|
||||||
|
-- | Wait for a specified amount of time on a timer.
|
||||||
|
-- Equivalent to a timer-read followed by a timer-after
|
||||||
|
| InputTimerFor Meta Expression
|
||||||
deriving (Show, Eq, Typeable, Data)
|
deriving (Show, Eq, Typeable, Data)
|
||||||
|
|
||||||
-- | Abbreviation mode.
|
-- | Abbreviation mode.
|
||||||
|
|
|
@ -320,3 +320,11 @@ findAllProcesses
|
||||||
= case A.ndType nd of
|
= case A.ndType nd of
|
||||||
A.Proc _ _ _ p -> Just (n, p)
|
A.Proc _ _ _ p -> Just (n, p)
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
|
-- | A prefix put on all ghost variables, such as Rain's timers
|
||||||
|
ghostVarPrefix :: String
|
||||||
|
ghostVarPrefix = "##"
|
||||||
|
|
||||||
|
-- | A suffix put on all ghost variables, such as Rain's timers
|
||||||
|
ghostVarSuffix :: String
|
||||||
|
ghostVarSuffix = "_##"
|
|
@ -390,9 +390,10 @@ alt = do {m <- sPri ; sAlt ; m' <- sLeftC ; cases <- many altCase ; optElseCase
|
||||||
case input of
|
case input of
|
||||||
A.Input m lv im -> do { body <- block ; return $ A.Only m $ A.Alternative m lv im body }
|
A.Input m lv im -> do { body <- block ; return $ A.Only m $ A.Alternative m lv im body }
|
||||||
_ -> dieP (findMeta input) $ "communication type not supported in an alt: \"" ++ show input ++ "\""
|
_ -> dieP (findMeta input) $ "communication type not supported in an alt: \"" ++ show input ++ "\""
|
||||||
<|> do (m, wm, e) <- waitStatement True
|
<|> do (m, wm) <- waitStatement True
|
||||||
body <- block
|
body <- block
|
||||||
return $ A.Only m $ A.AlternativeWait m wm e body
|
return $ A.Only m $ A.Alternative m (A.Variable m rainTimerName)
|
||||||
|
wm body
|
||||||
elseCase :: RainParser (A.Structured A.Alternative)
|
elseCase :: RainParser (A.Structured A.Alternative)
|
||||||
elseCase = do m <- sElse
|
elseCase = do m <- sElse
|
||||||
body <- block
|
body <- block
|
||||||
|
@ -412,11 +413,13 @@ runProcess = do m <- sRun
|
||||||
convertItem (A.ExprVariable _ v) = A.ActualVariable A.Original A.Any v
|
convertItem (A.ExprVariable _ v) = A.ActualVariable A.Original A.Any v
|
||||||
convertItem e = A.ActualExpression A.Any e
|
convertItem e = A.ActualExpression A.Any e
|
||||||
|
|
||||||
waitStatement :: Bool -> RainParser (Meta, A.WaitMode, A.Expression)
|
waitStatement :: Bool -> RainParser (Meta, A.InputMode)
|
||||||
waitStatement isAlt
|
waitStatement isAlt
|
||||||
= do { m <- sWait ;
|
= do { m <- sWait ;
|
||||||
do { sFor ; e <- expression ; possSemiColon ; return (m, A.WaitFor, e)}
|
do { sFor ; e <- expression ; possSemiColon ;
|
||||||
<|> do { sUntil ; e <- expression ; possSemiColon ; return (m, A.WaitUntil, e)}
|
return (m, A.InputTimerFor m e)}
|
||||||
|
<|> do { sUntil ; e <- expression ; possSemiColon ;
|
||||||
|
return (m, A.InputTimerAfter m e)}
|
||||||
<?> "reserved word \"for\" or \"until\" should follow reserved word \"wait\""
|
<?> "reserved word \"for\" or \"until\" should follow reserved word \"wait\""
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
|
@ -433,8 +436,10 @@ statement
|
||||||
<|> block
|
<|> block
|
||||||
<|> each
|
<|> each
|
||||||
<|> runProcess
|
<|> runProcess
|
||||||
<|> do {m <- reserved "now" ; dest <- lvalue ; sSemiColon ; return $ A.GetTime m dest}
|
<|> do {m <- reserved "now" ; dest <- lvalue ; sSemiColon ; return $ A.Input
|
||||||
<|> do {(m,wm,exp) <- waitStatement False ; return $ A.Wait m wm exp}
|
m (A.Variable m rainTimerName) $ A.InputTimerRead m $ A.InVariable m dest}
|
||||||
|
<|> do {(m,wm) <- waitStatement False; return $ A.Input m (A.Variable m
|
||||||
|
rainTimerName) wm}
|
||||||
<|> try (comm False)
|
<|> try (comm False)
|
||||||
<|> alt
|
<|> alt
|
||||||
<|> try (do { lv <- lvalue ; op <- assignOp ; exp <- expression ; sSemiColon ;
|
<|> try (do { lv <- lvalue ; op <- assignOp ; exp <- expression ; sSemiColon ;
|
||||||
|
@ -486,6 +491,10 @@ rainSourceFile
|
||||||
s <- getState
|
s <- getState
|
||||||
return (p, s)
|
return (p, s)
|
||||||
|
|
||||||
|
rainTimerName :: A.Name
|
||||||
|
rainTimerName = A.Name {A.nameName = ghostVarPrefix ++ "raintimer" ++ ghostVarSuffix,
|
||||||
|
A.nameMeta = emptyMeta, A.nameType = A.TimerName}
|
||||||
|
|
||||||
-- | Load and parse a Rain source file.
|
-- | Load and parse a Rain source file.
|
||||||
parseRainProgram :: String -> PassM A.AST
|
parseRainProgram :: String -> PassM A.AST
|
||||||
parseRainProgram filename
|
parseRainProgram filename
|
||||||
|
@ -494,7 +503,13 @@ parseRainProgram filename
|
||||||
case lexOut of
|
case lexOut of
|
||||||
Left merr -> dieP merr $ "Parse (lexing) error"
|
Left merr -> dieP merr $ "Parse (lexing) error"
|
||||||
Right toks ->
|
Right toks ->
|
||||||
do cs <- get
|
do defineName rainTimerName $ A.NameDef {A.ndMeta = emptyMeta,
|
||||||
|
A.ndName = A.nameName rainTimerName,
|
||||||
|
A.ndOrigName = A.nameName rainTimerName,
|
||||||
|
A.ndNameType = A.TimerName, A.ndType = A.Declaration emptyMeta
|
||||||
|
(A.Timer A.RainTimer),
|
||||||
|
A.ndAbbrevMode = A.Original, A.ndPlacement = A.Unplaced}
|
||||||
|
cs <- get
|
||||||
case runParser rainSourceFile cs filename toks of
|
case runParser rainSourceFile cs filename toks of
|
||||||
Left err -> dieP (sourcePosToMeta $ errorPos err) $ "Parse error: " ++ show err
|
Left err -> dieP (sourcePosToMeta $ errorPos err) $ "Parse error: " ++ show err
|
||||||
Right (p, cs') ->
|
Right (p, cs') ->
|
||||||
|
|
|
@ -298,7 +298,6 @@ excludeNonRainFeatures = excludeConstr
|
||||||
[ con0 A.Real32
|
[ con0 A.Real32
|
||||||
,con0 A.Real64
|
,con0 A.Real64
|
||||||
,con2 A.Counted
|
,con2 A.Counted
|
||||||
,con1 A.Timer
|
|
||||||
,con1 A.Port
|
,con1 A.Port
|
||||||
,con2 A.BytesInExpr
|
,con2 A.BytesInExpr
|
||||||
,con2 A.BytesInType
|
,con2 A.BytesInType
|
||||||
|
@ -306,8 +305,6 @@ excludeNonRainFeatures = excludeConstr
|
||||||
,con0 A.After
|
,con0 A.After
|
||||||
,con3 A.InCounted
|
,con3 A.InCounted
|
||||||
,con3 A.OutCounted
|
,con3 A.OutCounted
|
||||||
,con2 A.InputTimerRead
|
|
||||||
,con2 A.InputTimerAfter
|
|
||||||
,con2 A.Place
|
,con2 A.Place
|
||||||
,con3 A.IsChannelArray
|
,con3 A.IsChannelArray
|
||||||
,con4 A.Retypes
|
,con4 A.Retypes
|
||||||
|
|
|
@ -21,6 +21,7 @@ module Unnest (unnest) where
|
||||||
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import Data.Generics
|
import Data.Generics
|
||||||
|
import Data.List
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
|
||||||
|
@ -55,7 +56,9 @@ freeNamesIn = doGeneric
|
||||||
ignore s = Map.empty
|
ignore s = Map.empty
|
||||||
|
|
||||||
doName :: A.Name -> NameMap
|
doName :: A.Name -> NameMap
|
||||||
doName n = Map.singleton (A.nameName n) n
|
doName n | ghostVarPrefix `isPrefixOf` (A.nameName n)
|
||||||
|
&& ghostVarSuffix `isSuffixOf` (A.nameName n) = Map.empty
|
||||||
|
| otherwise = Map.singleton (A.nameName n) n
|
||||||
|
|
||||||
doStructured :: Data a => A.Structured a -> NameMap
|
doStructured :: Data a => A.Structured a -> NameMap
|
||||||
doStructured (A.Rep _ rep s) = doRep rep s
|
doStructured (A.Rep _ rep s) = doRep rep s
|
||||||
|
|
Loading…
Reference in New Issue
Block a user