atom-0.0.2: Language/Atom/Example.hs
-- | An example atom design.
module Language.Atom.Example
( compileExample
, example
) where
import Language.Atom
-- | Invoke the atom compiler.
compileExample :: IO ()
compileExample = compile "example" example
-- | Example design introduces a unsigned 16-bit variable,
-- and declares two rules: one to increment the variable,
-- one to reset the variable back to zero when it hits 100.
example :: Atom ()
example = period 2 $ do -- Set execution period as a factor of 2 of the base rate.
-- A local state variable.
count <- word64 "count" 0
-- An external variable.
reset <- bool' "reset"
-- A rule to increment the count.
atom "increment" $ do
cond $ value count <. 100
count <== value count + 1
-- A rule to reset the count.
atom "reset" $ do
cond $ value count ==. 100
cond $ value reset
count <== 0