Portability | portable |
---|---|
Stability | provisional |
Transforming a Sindre program into a callable function.
- compileSindre :: MonadBackend m => Program -> ClassMap m -> ObjectMap m -> FuncMap m -> GlobMap m -> ([SindreOption], Arguments -> m ExitCode)
- type ClassMap m = Map Identifier (Constructor m)
- type ObjectMap m = Map Identifier (ObjectRef -> m (NewObject m))
- type FuncMap m = Map Identifier (Compiler m ([Value] -> Sindre m Value))
- type GlobMap m = Map Identifier (m Value)
- data NewWidget m = forall s . Widget m s => NewWidget s
- data NewObject m = forall s . Object m s => NewObject s
- type Constructor m = WidgetRef -> [(Maybe Value, ObjectRef)] -> ConstructorM m (NewWidget m)
- data ConstructorM m a
- class MonadBackend m => Param m a where
- paramM :: (Param m a, MonadBackend m) => Identifier -> ConstructorM m a
- paramAs :: MonadBackend m => Identifier -> (Value -> Maybe a) -> ConstructorM m a
- param :: (Mold a, MonadBackend m) => Identifier -> ConstructorM m a
- noParam :: String -> ConstructorM m a
- badValue :: String -> Value -> ConstructorM m a
- type Compiler m a = RWS (CompilerEnv m) (Initialisation m) (CompilerState m) a
- value :: MonadBackend m => Identifier -> Compiler m (Execution m Value)
- setValue :: MonadBackend m => Identifier -> Compiler m (Value -> Execution m ())
Main Entry Point
compileSindre :: MonadBackend m => Program -> ClassMap m -> ObjectMap m -> FuncMap m -> GlobMap m -> ([SindreOption], Arguments -> m ExitCode)Source
Given a Sindre program and its environment, compile the program and return a pair of command-line options accepted by the program, and a startup function. The program can be executed by calling the startup function with the command-like arguments and an initial value for the root widget. If compilation fails, an IO exception is raised.
type ClassMap m = Map Identifier (Constructor m)Source
Mapping from class names to constructors.
type ObjectMap m = Map Identifier (ObjectRef -> m (NewObject m))Source
Mapping from object names to object constructor functions.
type FuncMap m = Map Identifier (Compiler m ([Value] -> Sindre m Value))Source
Mapping from function names to built-in functions. These must
first be executed in the Compiler
monad as they may have specific
requirements of the environment.
type GlobMap m = Map Identifier (m Value)Source
Mapping from names of global variables to computations that yield their initial values.
Object Construction
Container wrapping a newly created widget.
Container wrapping a newly created object.
type Constructor m = WidgetRef -> [(Maybe Value, ObjectRef)] -> ConstructorM m (NewWidget m)Source
Function that, given an initial value, the name of itself if any, and a list of children, yields a computation that constructs a new widget.
data ConstructorM m a Source
The monad in which widget construction takes place. You can only
execute this by defining a Constructor
that is then used in a
Sindre program (see also ClassMap
). An example usage could be:
myWidget ::Constructor
MyBackEnd myWidget w k cs : do -- ConstructorM is an instance ofAlternative
, so we can provide -- defaults or fallbacks for missing parameters. arg - 'param' \"myParam\" <| return 12 rest of construction
MonadBackend im => MonadSindre im ConstructorM | |
MonadError ParamError (ConstructorM m) | |
Monad (ConstructorM m) | |
Functor (ConstructorM m) | |
Applicative (ConstructorM m) | |
MonadBackend m => Alternative (ConstructorM m) | |
(MonadIO m, MonadBackend m) => MonadIO (ConstructorM m) | |
MonadState (Map Identifier Value) (ConstructorM m) |
class MonadBackend m => Param m a whereSource
Class of types that a given backend can convert to from Value
s.
In effect, a monadic version of Mold
.
paramM :: (Param m a, MonadBackend m) => Identifier -> ConstructorM m aSource
paramAs :: MonadBackend m => Identifier -> (Value -> Maybe a) -> ConstructorM m aSource
param :: (Mold a, MonadBackend m) => Identifier -> ConstructorM m aSource
noParam :: String -> ConstructorM m aSource
noParam k
signals that parameter k
is missing.
badValue :: String -> Value -> ConstructorM m aSource
badValue k v
signals that parameter k
is present with value
v
, but that v
is an invalid value.
Compiler Interface
These definitions can be used in builtin functions that may need to change global variables.
type Compiler m a = RWS (CompilerEnv m) (Initialisation m) (CompilerState m) aSource
Monad inside which compilation takes place.
value :: MonadBackend m => Identifier -> Compiler m (Execution m Value)Source
Given a variable name, return a computation that will yield the value of the variable when executed.
setValue :: MonadBackend m => Identifier -> Compiler m (Value -> Execution m ())Source
Given a variable name, return a computation that can be used to set the value of the variable when executed.