License | MIT-style (see LICENSE) |
---|---|
Stability | provisional |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Transforming a Sindre program into a callable function.
Synopsis
- 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)
- 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 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
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
Instances
class MonadBackend m => Param m a where Source #
Class of types that a given backend can convert to from Value
s.
In effect, a monadic version of Mold
.
moldM :: Value -> m (Maybe a) Source #
Attempt to convert the given Sindre value to the relevant Haskell value.
Instances
Param SindreX11M Font Source # | |
Defined in Sindre.X11 | |
Param SindreX11M Color Source # | |
Defined in Sindre.X11 |
paramM :: (Param m a, MonadBackend m) => Identifier -> ConstructorM m a Source #
paramAs :: MonadBackend m => Identifier -> (Value -> Maybe a) -> ConstructorM m a Source #
param :: (Mold a, MonadBackend m) => Identifier -> ConstructorM m a Source #
noParam :: String -> ConstructorM m a Source #
noParam k
signals that parameter k
is missing.
badValue :: String -> Value -> ConstructorM m a Source #
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 a Source #
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.