3 import qualified Control.Monad.State as State
5 -- | A datatype that maps each of the single values in a haskell structure to
6 -- a mapto. The map has the same structure as the haskell type mapped, ie
8 data HsValueMap mapto =
9 Tuple [HsValueMap mapto]
14 data FlatFunction = FlatFunction {
15 args :: [SignalDefMap],
17 --sigs :: [SignalDef],
22 type SignalUseMap = HsValueMap SignalUse
23 type SignalDefMap = HsValueMap SignalDef
25 data SignalUse = SignalUse {
29 data SignalDef = SignalDef {
34 appFunc :: HsFunction,
35 appArgs :: [SignalUseMap],
36 appRes :: SignalDefMap
39 data CondDef = CondDef {
46 -- | How is a given (single) value in a function's type (ie, argument or
47 -- return value) used?
49 Port -- ^ Use it as a port (input or output)
50 | State Int -- ^ Use it as state (input or output). The int is used to
51 -- match input state to output state.
52 | HighOrder { -- ^ Use it as a high order function input
53 hoName :: String, -- ^ Which function is passed in?
54 hoArgs :: [HsUseMap] -- ^ Which arguments are already applied? This
55 -- ^ map should only contain Port and other
60 type HsUseMap = HsValueMap HsValueUse
62 data HsFunction = HsFunction {
64 hsFuncArgs :: [HsUseMap],
69 String, -- ^ The bind name
70 Either -- ^ The bind value which is either
71 SignalUse -- ^ a signal
73 HsValueUse, -- ^ or a HighOrder function
74 [SignalUse] -- ^ With these signals already applied to it
78 type FlattenState = State.State ([App], [CondDef], Int)
80 -- | Flatten a haskell function
82 HsFunction -- ^ The function to flatten
83 -> CoreBind -- ^ The function value
84 -> FlatFunction -- ^ The resulting flat function
86 flattenFunction _ (Rec _) = error "Recursive binders not supported"
87 flattenFunction hsfunc bind@(NonRec var expr) =
88 FlatFunction args res apps conds
90 init_state = ([], [], 0)
91 (fres, end_state) = State.runState (flattenExpr expr) init_state
93 (apps, conds, _) = end_state
97 -> FlattenState ([SignalDefMap], SignalUseMap)
100 return ([], Tuple [])
105 -- vim: set ts=8 sw=2 sts=2 expandtab: