sindre-0.6: A programming language for simple GUIs
LicenseMIT-style (see LICENSE)
Stabilityprovisional
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Sindre.Compiler

Description

Transforming a Sindre program into a callable function.

Synopsis

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 of Alternative, so we can provide
  -- defaults or fallbacks for missing parameters.
  arg 'param' "myParam" <| return 12
  rest of construction

Instances

Instances details
MonadBackend im => MonadSindre im ConstructorM Source # 
Instance details

Defined in Sindre.Compiler

Methods

sindre :: Sindre im a -> ConstructorM im a Source #

back :: im a -> ConstructorM im a Source #

Monad (ConstructorM m) Source # 
Instance details

Defined in Sindre.Compiler

Methods

(>>=) :: ConstructorM m a -> (a -> ConstructorM m b) -> ConstructorM m b #

(>>) :: ConstructorM m a -> ConstructorM m b -> ConstructorM m b #

return :: a -> ConstructorM m a #

Functor (ConstructorM m) Source # 
Instance details

Defined in Sindre.Compiler

Methods

fmap :: (a -> b) -> ConstructorM m a -> ConstructorM m b #

(<$) :: a -> ConstructorM m b -> ConstructorM m a #

MonadFail (ConstructorM m) Source # 
Instance details

Defined in Sindre.Compiler

Methods

fail :: String -> ConstructorM m a #

Applicative (ConstructorM m) Source # 
Instance details

Defined in Sindre.Compiler

Methods

pure :: a -> ConstructorM m a #

(<*>) :: ConstructorM m (a -> b) -> ConstructorM m a -> ConstructorM m b #

liftA2 :: (a -> b -> c) -> ConstructorM m a -> ConstructorM m b -> ConstructorM m c #

(*>) :: ConstructorM m a -> ConstructorM m b -> ConstructorM m b #

(<*) :: ConstructorM m a -> ConstructorM m b -> ConstructorM m a #

MonadBackend m => Alternative (ConstructorM m) Source # 
Instance details

Defined in Sindre.Compiler

Methods

empty :: ConstructorM m a #

(<|>) :: ConstructorM m a -> ConstructorM m a -> ConstructorM m a #

some :: ConstructorM m a -> ConstructorM m [a] #

many :: ConstructorM m a -> ConstructorM m [a] #

(MonadIO m, MonadBackend m) => MonadIO (ConstructorM m) Source # 
Instance details

Defined in Sindre.Compiler

Methods

liftIO :: IO a -> ConstructorM m a #

MonadState (Map Identifier Value) (ConstructorM m) Source # 
Instance details

Defined in Sindre.Compiler

class MonadBackend m => Param m a where Source #

Class of types that a given backend can convert to from Values. In effect, a monadic version of Mold.

Methods

moldM :: Value -> m (Maybe a) Source #

Attempt to convert the given Sindre value to the relevant Haskell value.

Instances

Instances details
Param SindreX11M Font Source # 
Instance details

Defined in Sindre.X11

Param SindreX11M Color Source # 
Instance details

Defined in Sindre.X11

paramM :: (Param m a, MonadBackend m) => Identifier -> ConstructorM m a Source #

As paramM, but moldM is always used for conversion.

paramAs :: MonadBackend m => Identifier -> (Value -> Maybe a) -> ConstructorM m a Source #

k paramAs f yields the value of the widget parameter k, using f to convert it to the proper Haskell type. If f returns Nothing, badValue k is called. If k does not exist, noParam k is called.

param :: (Mold a, MonadBackend m) => Identifier -> ConstructorM m a Source #

As param, but mold is always used for conversion.

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.