Skip to content

Commit

Permalink
copilot-c99: Add specific Trigger representation. Refs Copilot-Lang…
Browse files Browse the repository at this point in the history
…uage#296.

A backend specific representation of triggers allows us to keep track of
the internal name for a trigger.
  • Loading branch information
fdedden committed Dec 20, 2024
1 parent cdf807d commit 3cc456d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions copilot-c99/copilot-c99.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ library
, Copilot.Compile.C99.External
, Copilot.Compile.C99.Compile
, Copilot.Compile.C99.Settings
, Copilot.Compile.C99.Representation

test-suite unit-tests
type:
Expand Down
22 changes: 22 additions & 0 deletions copilot-c99/src/Copilot/Compile/C99/Representation.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- | C99 backend specific versions of selected `Copilot.Core` datatypes.
module Copilot.Compile.C99.Representation
(
UniqueTrigger (..)
, UniqueTriggerId
, mkUniqueTriggers
)
where

import Copilot.Core ( Trigger (..) )

-- | Internal unique name for a trigger.
type UniqueTriggerId = String

-- | A `Copilot.Core.Trigger` with an unique name.
data UniqueTrigger = UniqueTrigger UniqueTriggerId Trigger

-- | Given a list of triggers, make their names unique.
mkUniqueTriggers :: [Trigger] -> [UniqueTrigger]
mkUniqueTriggers ts = zipWith mkUnique ts [0..]
where
mkUnique t@(Trigger name _ _) n = UniqueTrigger (name ++ "_" ++ show n) t

0 comments on commit 3cc456d

Please sign in to comment.