Safe HaskellNone




Monad Interface

type MOO = ReaderT Environment (ContT TaskDisposition (StateT TaskState VTx)) Source

This is the basic MOO monad transformer stack. A computation of type MOO a is a VTx transaction (layered on STM) that returns a value of type a within an environment that supports state, continuations, and local modification.

data Environment Source

A Reader environment for state that either doesn't change, or can be locally modified for subcomputations




task :: Task
interruptHandler :: InterruptHandler
exceptionHandler :: ExceptionHandler
indexLength :: MOO Value

liftVTx :: VTx a -> MOO a Source

Lift a VTx transaction into the MOO monad.

liftSTM :: STM a -> MOO a Source

Lift an STM transaction into the MOO monad.

World Interface

data World Source

The known universe, as far as the MOO server is concerned




writeLog :: Text -> STM ()

Logging function

persistence :: Persistence

Persistent storage

checkpoint :: STM ()

Database checkpoint signal

database :: Database

The database of objects

tasks :: Map TaskId Task

Queued and running tasks

listeners :: Map Point Listener

Network listening points

connections :: Map ObjId Connection

Network connections

nextConnectionId :: ObjId

The (negative) object number to be assigned to the next inbound or outbound connection

outboundNetwork :: Bool

Is open_network_connection() enabled?

bindAddress :: Maybe HostName

Interface address to bind to for incoming connections

shutdownMessage :: MVar Text

Shutdown signal

newWorld :: (Text -> STM ()) -> Persistence -> Bool -> IO (TVar World) Source

getVSpace :: MOO VSpace Source

serverOption :: (ServerOptions -> a) -> MOO a Source

Fetch the current setting of a server option obtained from $server_options.

Task Interface

data Task Source

A structure representing a queued or running task

data TaskStatus Source

The running state of a task

newtype Wake Source

A function to call in order to wake a suspended task


Wake (Value -> IO ()) 

data TaskState Source

A State structure for data that may normally change during computation



newtype CallStack Source

The stack of verb and/or built-in function frames


Stack [StackFrame] 

newtype DelayedIO Source

An IO computation to be performed after the current task commits its STM transaction




runDelayed :: IO ()

data TaskDisposition Source

The intermediate or final result of a running task

newtype Resume a Source

A continuation to resume the execution of a task where it left off


Resume (a -> MOO Value) 

data Resource Source

Task resource limits



newTaskId :: World -> StdGen -> TaskId Source

Generate a (random) TaskId not currently in use by any existing task.

newTask :: TVar World -> ObjId -> MOO Value -> IO Task Source

Create a pending Task for the given computation on behalf of the given player. A new TaskId is reserved for the task and the task is added to the World. (The task will not actually run until passed to runTask.)

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.

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.

forkTask :: TaskId -> Integer -> MOO Value -> MOO () Source

Create and queue a task to run the given computation after the given microsecond delay. E_INVARG may be raised if the delay is out of acceptable range. (The given TaskId should have been reserved by a call to newTaskId.)

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).

getTask :: TaskId -> MOO (Maybe Task) Source

Object Interface

modifyVerb :: (ObjId, Object) -> Value -> (Verb -> MOO Verb) -> MOO () Source

Verb Execution Interface

Verb Frame Interface

data StackFrame Source

The data tracked for each verb and/or built-in function call

newtype Continuation Source

A local continuation for loop constructs


Continuation (() -> MOO Value) 

frame :: (StackFrame -> a) -> MOO a Source

caller :: (StackFrame -> a) -> MOO (Maybe a) 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

Exception Handling

data Exception Source

A MOO exception




exceptionCode :: Code
exceptionMessage :: Message
exceptionValue :: Value
exceptionCallStack :: CallStack
exceptionDebugBit :: Bool

A copy of the debug bit from the verb frame in which the exception was raised

raiseException :: Code -> Message -> Value -> MOO a Source

Abort execution of the current computation and call the nearest enclosing exception handler.

raise :: Error -> MOO a Source

Create and raise an exception for the given MOO error.

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.

Utility Check Functions

isWizard :: ObjId -> MOO Bool Source

Determine whether the given object has its wizard bit set.

checkFloat :: FltT -> MOO Value Source

Verify that the given floating point number is neither infinite nor NaN, raising E_FLOAT or E_INVARG respectively if so. Also, return the corresponding MOO value.

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.

checkRecurrence Source


:: (Object -> Maybe ObjId)

relationship projection

-> ObjId


-> ObjId

object to check

-> MOO () 

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).


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.

delay :: Integer -> IO () Source

Wait for the given number of microseconds to elapse.

shutdown :: StrT -> MOO () Source

Begin the server shutdown process.

notyet :: StrT -> MOO a Source

Placeholder for features not yet implemented