Nicer nonce naming; generate PAR

This commit is contained in:
Adam Sampson 2007-04-10 20:13:09 +00:00
parent 8a1094e76a
commit 8d3f8153eb
4 changed files with 30 additions and 15 deletions

View File

@ -271,7 +271,7 @@ genOutputItem c (A.OutCounted m ce ae)
= do genOutputItem c (A.OutExpression m ce)
missing "genOutputItem counted"
genOutputItem c (A.OutExpression m e)
= do n <- makeNonce
= do n <- makeNonce "output_item"
ps <- get
let t = fromJust $ typeOfExpression ps e
case t of
@ -308,7 +308,7 @@ genReplicator rep body
-- of loop a C programmer would normally write.
genReplicatorLoop :: A.Replicator -> CGen ()
genReplicatorLoop (A.For m n base count)
= do counter <- makeNonce
= do counter <- makeNonce "replicator_count"
tell ["int ", counter, " = "]
genExpression count
tell [", "]
@ -338,7 +338,7 @@ introduceSpec (n, A.Declaration m A.Timer) = return ()
introduceSpec (n, A.Declaration m t)
= do case t of
A.Chan _ ->
do cn <- makeNonce
do cn <- makeNonce "channel"
tell ["Channel ", cn, ";\n"]
tell ["ChanInit (&", cn, ");\n"]
tell ["Channel *"]
@ -457,7 +457,7 @@ genAssign vs el
tell [";\n"]
vs ->
do tell ["{\n"]
ns <- mapM (\_ -> makeNonce) vs
ns <- mapM (\_ -> makeNonce "assign_tmp") vs
mapM (\(v, n, e) -> do st <- get
let t = typeOfVariable st v
genType (fromJust t)
@ -484,7 +484,7 @@ genInput c im
genTimerRead :: A.Variable -> CGen ()
genTimerRead v
= do n <- makeNonce
= do n <- makeNonce "time"
tell ["{\n"]
tell ["Time ", n, ";\n"]
tell ["ProcTime (&", n, ");\n"]
@ -508,7 +508,7 @@ genStop = tell ["SetErr ();\n"]
-- that aren't replicated and don't have specs.
genIf :: A.Structured -> CGen ()
genIf s
= do label <- makeNonce
= do label <- makeNonce "if_end"
genIfBody label s
genStop
tell [label, ":\n;\n"]
@ -534,12 +534,27 @@ genWhile e p
genProcess p
tell ["}\n"]
-- FIXME Stubbed out for now so I can see what the branches look like...
genPar :: A.ParMode -> [A.Process] -> CGen ()
genPar pm ps
= do tell ["#error PAR not implemented\n"]
sequence_ $ map genProcess ps
tell ["#error end PAR\n"]
= do pids <- mapM (\_ -> makeNonce "pid") ps
sequence_ $ map genProcAlloc (zip pids ps)
case pm of
A.PlainPar ->
do tell ["ProcPar ("]
sequence_ $ [tell [pid, ", "] | pid <- pids]
tell ["NULL);\n"]
_ -> missing $ "genPar " ++ show pm
sequence_ $ [tell ["ProcAllocClean (", pid, ");\n"] | pid <- pids]
genProcAlloc :: (String, A.Process) -> CGen ()
genProcAlloc (pid, A.ProcCall m n as)
= do tell ["Process *", pid, " = ProcAlloc ("]
genName n
-- FIXME stack size fixed here
tell [", 4096"]
sequence_ $ map (\a -> do tell [", "]
genActual a) as
tell [");\n"]
genProcCall :: A.Name -> [A.Actual] -> CGen ()
genProcCall n as

View File

@ -322,7 +322,7 @@ findName thisN
scopeIn :: A.Name -> A.SpecType -> A.AbbrevMode -> OccParser A.Name
scopeIn n@(A.Name m nt s) t am
= do st <- getState
let s' = s ++ "_" ++ (show $ psNameCounter st)
let s' = s ++ "_u" ++ (show $ psNameCounter st)
let n' = n { A.nameName = s' }
let nd = A.NameDef {
A.ndMeta = m,

View File

@ -36,10 +36,10 @@ psLookupName :: ParseState -> A.Name -> Maybe A.NameDef
psLookupName ps n = lookup (A.nameName n) (psNames ps)
-- | Generate a throwaway unique name.
makeNonce :: MonadState ParseState m => m String
makeNonce
makeNonce :: MonadState ParseState m => String -> m String
makeNonce s
= do ps <- get
let i = psNonceCounter ps
put ps { psNonceCounter = i + 1 }
return $ "nonce" ++ show i
return $ s ++ "_n" ++ show i

View File

@ -16,7 +16,7 @@ type UnM a = StateT ParseState IO a
-- | Generate and define a no-arg wrapper PROC around a process.
makeNonceProc :: Meta -> A.Process -> UnM A.Specification
makeNonceProc m p
= do ns <- makeNonce
= do ns <- makeNonce "wrapper_proc"
let n = A.Name m A.ProcName ns
let st = A.Proc m [] p
let nd = A.NameDef {