Safe Haskell | None |
---|---|
Language | Haskell2010 |
- type MOO = ReaderT Environment (ContT TaskDisposition (StateT TaskState VTx))
- data Environment = Env {
- task :: Task
- interruptHandler :: InterruptHandler
- exceptionHandler :: ExceptionHandler
- indexLength :: MOO Value
- initEnvironment :: Task -> Environment
- liftVTx :: VTx a -> MOO a
- liftSTM :: STM a -> MOO a
- data World = World {
- writeLog :: Text -> STM ()
- persistence :: Persistence
- checkpoint :: STM ()
- database :: Database
- tasks :: Map TaskId Task
- listeners :: Map Point Listener
- connections :: Map ObjId Connection
- nextConnectionId :: ObjId
- outboundNetwork :: Bool
- bindAddress :: Maybe HostName
- shutdownMessage :: MVar Text
- newWorld :: (Text -> STM ()) -> Persistence -> Bool -> IO (TVar World)
- getWorld :: MOO World
- getWorld' :: MOO (TVar World)
- putWorld :: World -> MOO ()
- modifyWorld :: (World -> World) -> MOO ()
- updateConnections :: TVar World -> (Map ObjId Connection -> Map ObjId Connection) -> VTx ()
- getDatabase :: MOO Database
- putDatabase :: Database -> MOO ()
- getVSpace :: MOO VSpace
- serverOption :: (ServerOptions -> a) -> MOO a
- data Task = Task {
- taskId :: TaskId
- taskStatus :: TaskStatus
- taskThread :: ThreadId
- taskWorld :: TVar World
- taskPlayer :: ObjId
- taskState :: TaskState
- taskComputation :: MOO Value
- data TaskStatus
- newtype Wake = Wake (Value -> IO ())
- data TaskState = State {}
- newtype CallStack = Stack [StackFrame]
- newtype DelayedIO = DelayedIO {
- runDelayed :: IO ()
- data TaskDisposition
- newtype Resume a = Resume (a -> MOO Value)
- data Resource
- initState :: TaskState
- newState :: IO TaskState
- initTask :: Task
- newTaskId :: World -> StdGen -> TaskId
- newTask :: TVar World -> ObjId -> MOO Value -> IO Task
- defaultMaxStackDepth :: Num a => a
- defaultFgTicks :: Num a => a
- defaultBgTicks :: Num a => a
- defaultFgSeconds :: Num a => a
- defaultBgSeconds :: Num a => a
- getDelay :: Value -> MOO Integer
- resetLimits :: Bool -> MOO ()
- taskOwner :: Task -> ObjId
- isQueued :: TaskStatus -> Bool
- queuedTasks :: MOO [Task]
- stepTask :: Task -> IO (TaskDisposition, Task)
- runTask :: Task -> IO (Maybe Value)
- forkTask :: TaskId -> Integer -> MOO Value -> MOO ()
- interrupt :: TaskDisposition -> MOO a
- requestIO :: IO a -> MOO a
- delayIO :: IO () -> MOO ()
- unsafeIOtoMOO :: IO a -> MOO a
- catchUnsafeIOtoMOO :: IO a -> (SomeException -> MOO a) -> MOO a
- getTask :: TaskId -> MOO (Maybe Task)
- putTask :: Task -> MOO ()
- purgeTask :: Task -> MOO ()
- getPlayer :: MOO ObjId
- getObject :: ObjId -> MOO (Maybe Object)
- getObjectName :: ObjId -> MOO StrT
- getProperty :: Object -> StrT -> MOO Property
- modifyProperty :: Object -> StrT -> (Property -> MOO Property) -> MOO ()
- modifyVerb :: (ObjId, Object) -> Value -> (Verb -> MOO Verb) -> MOO ()
- readProperty :: ObjId -> StrT -> MOO (Maybe Value)
- writeProperty :: ObjId -> StrT -> Value -> MOO ()
- setBuiltinProperty :: (ObjId, Object) -> StrT -> Value -> MOO ()
- getVerb :: Object -> Value -> MOO Verb
- findVerb :: (Verb -> Bool) -> StrT -> ObjId -> MOO (Maybe ObjId, Maybe Verb)
- callSystemVerb :: StrT -> [Value] -> MOO (Maybe Value)
- callSystemVerb' :: ObjId -> StrT -> [Value] -> StrT -> MOO (Maybe Value)
- callCommandVerb :: ObjId -> (ObjId, Verb) -> ObjId -> Command -> ObjId -> ObjId -> MOO Value
- callVerb :: ObjId -> ObjId -> StrT -> [Value] -> MOO Value
- callFromFunc :: StrT -> LineNo -> (ObjId, StrT) -> [Value] -> MOO (Maybe Value)
- evalFromFunc :: StrT -> LineNo -> MOO Value -> MOO Value
- runVerb :: Verb -> StackFrame -> MOO Value
- runTick :: MOO ()
- data StackFrame = Frame {
- depthLeft :: Int
- contextStack :: [Context]
- variables :: HashMap Id Value
- debugBit :: Bool
- permissions :: ObjId
- verbName :: StrT
- verbFullName :: StrT
- verbLocation :: ObjId
- initialThis :: ObjId
- initialPlayer :: ObjId
- builtinFunc :: Bool
- lineNumber :: LineNo
- newtype Continuation = Continuation (() -> MOO Value)
- initFrame :: StackFrame
- formatFrames :: Bool -> [StackFrame] -> Value
- activeFrame :: Task -> StackFrame
- frame :: (StackFrame -> a) -> MOO a
- caller :: (StackFrame -> a) -> MOO (Maybe a)
- modifyFrame :: (StackFrame -> StackFrame) -> MOO ()
- setLineNumber :: LineNo -> MOO ()
- mkVariables :: [(Id, Value)] -> HashMap Id Value
- pushTryFinallyContext :: MOO Value -> MOO ()
- pushLoopContext :: Maybe Id -> Continuation -> MOO ()
- setLoopContinue :: Continuation -> MOO ()
- popContext :: MOO ()
- breakLoop :: Maybe Id -> MOO Value
- continueLoop :: Maybe Id -> MOO Value
- data Exception = Exception {}
- type Code = Value
- type Message = StrT
- raiseException :: Code -> Message -> Value -> MOO a
- raise :: Error -> MOO a
- catchException :: MOO a -> (Exception -> MOO a) -> MOO a
- passException :: Exception -> MOO a
- handleDebug :: MOO Value -> MOO Value
- timeoutException :: Resource -> CallStack -> Exception
- isWizard :: ObjId -> MOO Bool
- checkFloat :: FltT -> MOO Value
- checkProgrammer :: MOO ()
- checkWizard :: MOO ()
- checkPermission :: ObjId -> MOO ()
- checkValid :: ObjId -> MOO Object
- checkFertile :: ObjId -> MOO ()
- checkProtectedProperty :: Id -> MOO ()
- checkRecurrence :: (Object -> Maybe ObjId) -> ObjId -> ObjId -> MOO ()
- checkQueuedTaskLimit :: MOO ()
- binaryString :: StrT -> MOO ByteString
- random :: Random a => (a, a) -> MOO a
- newRandomGen :: MOO StdGen
- delay :: Integer -> IO ()
- shutdown :: StrT -> MOO ()
- notyet :: StrT -> MOO a
Monad Interface
type MOO = ReaderT Environment (ContT TaskDisposition (StateT TaskState VTx)) Source
data Environment Source
A Reader
environment for state that either doesn't change, or can be
locally modified for subcomputations
Env | |
|
initEnvironment :: Task -> Environment Source
World Interface
The known universe, as far as the MOO server is concerned
World | |
|
modifyWorld :: (World -> World) -> MOO () Source
updateConnections :: TVar World -> (Map ObjId Connection -> Map ObjId Connection) -> VTx () Source
putDatabase :: Database -> MOO () Source
serverOption :: (ServerOptions -> a) -> MOO a Source
Fetch the current setting of a server option obtained from
$server_options
.
Task Interface
A structure representing a queued or running task
Task | |
|
data TaskStatus Source
The running state of a task
The stack of verb and/or built-in function frames
DelayedIO | |
|
data TaskDisposition Source
The intermediate or final result of a running task
A continuation to resume the execution of a task where it left off
newTaskId :: World -> StdGen -> TaskId Source
Generate a (random) TaskId
not currently in use by any existing task.
defaultMaxStackDepth :: Num a => a Source
defaultFgTicks :: Num a => a Source
defaultBgTicks :: Num a => a Source
defaultFgSeconds :: Num a => a Source
defaultBgSeconds :: Num a => a Source
resetLimits :: Bool -> MOO () Source
Reset the number of ticks and seconds available for the current task
based on the latest values obtained from $server_options
.
isQueued :: TaskStatus -> Bool Source
queuedTasks :: MOO [Task] Source
runTask :: Task -> IO (Maybe Value) Source
Run a task in a new Haskell thread, returning either the value produced
by the task, or Nothing
if the task suspends or aborts before producing a
value. If the task suspends, it may continue running after this function
returns. The task is removed from the task queue after it is finished.
interrupt :: TaskDisposition -> MOO a Source
Commit the current task's transaction, and return to the task dispatcher with an interrupt request. The task dispatcher may resume execution of the task later if the request is one which supplies an appropriate continuation.
requestIO :: IO a -> MOO a Source
Interrupt the current task to perform the given IO computation, and
return the result. Note this implies a commit of the task's STM
transaction.
delayIO :: IO () -> MOO () Source
Perform the given IO computation after the current task commits its STM
transaction.
Since general IO can't be performed within a transaction, this is a simple alternative when the value returned by the IO isn't needed.
unsafeIOtoMOO :: IO a -> MOO a Source
A version of catchUnsafeIOtoMOO
that simply propagates any thrown
exception into the calling thread, most likely aborting its execution.
catchUnsafeIOtoMOO :: IO a -> (SomeException -> MOO a) -> MOO a Source
Unsafely perform the given IO action within the current STM
transaction, using the supplied exception handler in case the IO throws an
exception.
Since STM
transactions may be aborted at any time, the IO is performed in
a separate thread in order to guarantee consistency with any finalizers,
brackets, and so forth. The IO must be idempotent as it may be run more
than once.
Note that all the hazards of unsafePerformIO
apply; in particular, it is
incumbent upon the caller to ensure the IO action is executed at least as
many times as desired (and not, say, optimized to a single execution).
Object Interface
getObjectName :: ObjId -> MOO StrT Source
Verb Execution Interface
Verb Frame Interface
data StackFrame Source
The data tracked for each verb and/or built-in function call
Frame | |
|
formatFrames :: Bool -> [StackFrame] -> Value Source
activeFrame :: Task -> StackFrame Source
frame :: (StackFrame -> a) -> MOO a Source
caller :: (StackFrame -> a) -> MOO (Maybe a) Source
modifyFrame :: (StackFrame -> StackFrame) -> MOO () Source
setLineNumber :: LineNo -> MOO () Source
mkVariables :: [(Id, Value)] -> HashMap Id Value Source
Create a variable block for a verb by overriding the default.
Loop and Try/Finally Control Functions
pushTryFinallyContext :: MOO Value -> MOO () Source
pushLoopContext :: Maybe Id -> Continuation -> MOO () Source
setLoopContinue :: Continuation -> MOO () Source
popContext :: MOO () Source
Exception Handling
A MOO exception
Exception | |
|
raiseException :: Code -> Message -> Value -> MOO a Source
Abort execution of the current computation and call the nearest enclosing exception handler.
catchException :: MOO a -> (Exception -> MOO a) -> MOO a Source
Install a local exception handler for the duration of the passed computation.
passException :: Exception -> MOO a Source
Re-raise an exception to the next enclosing handler.
handleDebug :: MOO Value -> MOO Value Source
Execute the passed computation, capturing any exception raised in verb frames with debug bit unset and returning the error code as an ordinary value instead of propagating the exception.
timeoutException :: Resource -> CallStack -> Exception Source
Utility Check Functions
checkFloat :: FltT -> MOO Value Source
checkProgrammer :: MOO () Source
Verify that the current task permissions have programmer privileges,
raising E_PERM
if not.
checkWizard :: MOO () Source
Verify that the current task permissions have wizard privileges, raising
E_PERM
if not.
checkPermission :: ObjId -> MOO () Source
Verify that the current task permissions either have wizard privileges or
are the same as the given object, raising E_PERM
if not.
checkValid :: ObjId -> MOO Object Source
Verify that the given object is valid, raising E_INVARG
if not. Also,
return the referenced object.
checkFertile :: ObjId -> MOO () Source
Verify that the given object is fertile for the current task permissions,
raising E_PERM
if not.
checkProtectedProperty :: Id -> MOO () Source
Verify that the named built-in property is not protected by
$server_options.protect_prop
, or that the current task permissions have
wizard privileges if it is, raising E_PERM
otherwise.
Verify that the given object does not have a recursive relationship
with the given subject, raising E_RECMOVE
if so.
checkQueuedTaskLimit :: MOO () Source
Verify that the programmer has not reached their queued task limit (before creating a new forked, suspended, or reading task).
Miscellaneous
binaryString :: StrT -> MOO ByteString Source
Translate a MOO binary string into a Haskell ByteString
, raising
E_INVARG
if the MOO string is improperly formatted.
random :: Random a => (a, a) -> MOO a Source
Generate and return a pseudorandom value in the given range, modifying the local generator state.
newRandomGen :: MOO StdGen Source
Split the local random number generator state in two, updating the local state with one of them and returning the other.