ContentsIndex
Gulik.Types
Contents
Basic types
Interp monad and error handling
Description
Haskell types related to Gulik.
Synopsis
data Expr
= ExprDouble {
exprDouble :: Double
}
| ExprInteger {
exprInteger :: Integer
}
| ExprString {
exprString :: String
}
| ExprApply
| ExprName {
exprName :: String
}
| ExprBind {
exprBind :: String
}
| ExprBody {
exprBody :: [Expr]
}
type Env = Map String Value
data Value
= ValueDouble {
valueDouble :: Double
}
| ValueInteger {
valueInteger :: Integer
}
| ValueBool {
valueBool :: Bool
}
| ValueString {
valueString :: String
}
| ValueNil
| ValuePair {
valueCar :: Value
valueCdr :: Value
}
| ValueClosure {
valueEnv :: Env
valueBody :: [Expr]
}
| ValueBuiltin {
valueBuiltin :: (Interp ())
valueBuiltinName :: String
}
type Interp = StateT InterpState (Either InterpError)
data InterpState = InterpState {
stateStack :: [Value]
stateEnv :: Env
}
data InterpError
= UndefinedSymbol {
errorSymbolName :: String
}
| StackUnderflow
| InvalidApply {
errorApplyValue :: Value
}
| BuiltinTypeError {
errorBuiltinName :: String
}
| UserError {
errorUserString :: String
}
| UnknownError
Basic types
data Expr
Algebraic data type for Gulik expressions.
Constructors
ExprDoubleA double-valued literal.
exprDouble :: Double
ExprIntegerAn integer-valued literal.
exprInteger :: Integer
ExprStringA string-valued literal.
exprString :: String
ExprApplyAn application.
ExprNameA name.
exprName :: String
ExprBindA bind to a name.
exprBind :: String
ExprBodyA body (list of expressions in {...}).
exprBody :: [Expr]
show/hide Instances
Eq Expr
Show Expr
type Env = Map String Value
An environment, mapping names to values.
data Value
Algebraic data type for Gulik run-time values.
Constructors
ValueDoubleA double value
valueDouble :: DoubleExtract the double.
ValueIntegerAn integer value.
valueInteger :: IntegerExtract the integer.
ValueBoolA Boolean value.
valueBool :: BoolExtract the Boolean.
ValueStringA string value.
valueString :: StringExtract the string.
ValueNilA nil pair.
ValuePairA (non-nil) pair.
valueCar :: ValueThe car of the pair.
valueCdr :: ValueThe cdr of the pair.
ValueClosureA function closure, written in Gulik.
valueEnv :: EnvThe environment for the closure.
valueBody :: [Expr]The body of the closure.
ValueBuiltinA function closure, written in Haskell.
valueBuiltin :: (Interp ())The Interp monad action for the builtin.
valueBuiltinName :: StringThe name of the builtin (used for superficial things).
show/hide Instances
Eq Value
Show Value
Interp monad and error handling
type Interp = StateT InterpState (Either InterpError)
Monad for the stack machine operations, combining state and error handling.
data InterpState
State of the interpreter stack machine.
Constructors
InterpState
stateStack :: [Value]Current stack.
stateEnv :: EnvCurrent environment.
show/hide Instances
data InterpError
Errors thrown by the stack machine.
Constructors
UndefinedSymbolA symbol was accessed before being defined.
errorSymbolName :: StringName of the undefined symbol.
StackUnderflowA pop was executed on an empty stack.
InvalidApplyA non-closure was applied.
errorApplyValue :: ValueValue for which apply was attempted.
BuiltinTypeErrorA builtin function was applied with bad types.
errorBuiltinName :: StringThe name of the builtin applied.
UserErrorA user-defined error occurred.
errorUserString :: StringA string describing the error.
UnknownErrorAn unknown error occurred.
show/hide Instances
Produced by Haddock version 0.7