Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Copilot/Compile/C99/CodeGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ mkstep streams triggers exts = C.FunDef void "step" [] declns stmts where
mktriggercheck (Trigger name guard args) = C.If guard' firetrigger where
guard' = C.Funcall (C.Ident $ guardname name) []
firetrigger = [C.Expr $ C.Funcall (C.Ident name) args'] where
args' = take (length args) (map argcall (argnames name))
argcall name = C.Funcall (C.Ident name) []
args' = map argcall (zip (argnames name) args)
argcall (aname, (maname, arg)) = case maname of
Just aname' -> C.Funcall (C.Ident (name ++ "_arg_" ++ aname')) []
Nothing -> C.Funcall (C.Ident aname) []

-- Code to update the global buffer.
mkupdatebuffer :: Stream -> C.Stmt
Expand Down Expand Up @@ -145,5 +147,5 @@ gatherexprs :: [Stream] -> [Trigger] -> [UExpr]
gatherexprs streams triggers = map streamexpr streams
++ concatMap triggerexpr triggers where
streamexpr (Stream _ _ expr ty) = UExpr ty expr
triggerexpr (Trigger _ guard args) = UExpr Bool guard : args
triggerexpr (Trigger _ guard args) = UExpr Bool guard : (fmap snd args)

10 changes: 7 additions & 3 deletions src/Copilot/Compile/C99/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ compilec spec = C.TransUnit declns funs where
guarddef = genfun (guardname name) guard Bool
argdefs = map arggen (zip (argnames name) args)

arggen :: (String, UExpr) -> C.FunDef
arggen (argname, UExpr ty expr) = genfun argname expr ty
arggen :: (String, (Maybe String, UExpr)) -> C.FunDef
arggen (aname, (maname, UExpr ty expr)) = case maname of
Just aname' -> genfun (name ++ "_arg_" ++ aname') expr ty
Nothing -> genfun aname expr ty

-- | Generate the .h file from a spec.
compileh :: Spec -> C.TransUnit
Expand Down Expand Up @@ -114,7 +116,9 @@ compileh spec = C.TransUnit declns [] where
extfundecln (Trigger name _ args) = C.FunDecln Nothing cty name params where
cty = C.TypeSpec C.Void
params = map mkparam $ zip (argnames name) args
mkparam (name, UExpr ty _) = C.Param (transtype ty) name
mkparam (name, (mname, UExpr ty _)) = case mname of
Just name' -> C.Param (transtype ty) name'
Nothing -> C.Param (transtype ty) name

-- Declaration for the step function.
stepdecln :: C.Decln
Expand Down
4 changes: 2 additions & 2 deletions src/Copilot/Compile/C99/External.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ gatherexts streams triggers = streamsexts `extunion` triggersexts where
guardexts = exprexts guard
argexts = concat $ map uexprexts args

uexprexts :: UExpr -> [External]
uexprexts (UExpr _ expr) = exprexts expr
uexprexts :: (Maybe String, UExpr) -> [External]
uexprexts (_, UExpr _ expr) = exprexts expr

exprexts :: Expr a -> [External]
exprexts expr = let rec = exprexts in case expr of
Expand Down