Provides the M interpreter, storing/restoring objects, cues, distributed objects, and more. More...
#include <MObject.h>
Provides the M interpreter, storing/restoring objects, cues, distributed objects, and more.
MObject implements the M interpreter and the essential functions associated with it. M is a language based on functional programming principles which is both that which is processed by the M interpreter directly and at the same time, the basis of the AST (abstract syntax tree) used by the parsers and generators. All M functions begin in upper-case e.g: Add(), Def() -- some M functions evaluate their arguments while others are lazy or may perform partial evaluation, e.g: symbol lookup. Each MObject is effectively an interpreter with state allowing M methods/functions and attributes to be defined within. MObject also provides an interface that supports storing/restoring objects, cues, and distributed functionality. Throughout the documentation, we refer to the client-side of a distributed object as a "remote object." And the server-side as the "distributed object." MObject is fully storeable/restoreable.
The attribute modes used for manipulating attributes.
Raw - set/retrieve directly by value.
Exists - same as Raw but throw an MError when attribute does not exist.
TryProtected - Try to manipulate the value through an accessor or mutator e.g: getX(), setX(value), falling back to raw mode if such a method does not exist.
TryProtectedExists - same as TryProtected but throws an MError when attribute does not exist.
Protected - manipulation must go through an accessor or mutator. If such a method does not exist, an MError is thrown.
| Meta::MObject::MObject | ( | bool | basic = false |
) |
Constructor.
| basic | true if this is a basic object. See MBasicObject. |
| Meta::MObject::MObject | ( | MBrokerBase * | broker | ) |
Constructor that subclasses call to create a remote object.
| Meta::MObject::MObject | ( | const MObject & | object | ) |
Copy constructor.
| Meta::MObject::MObject | ( | const mvar & | v, | |
| RestoreOpt | opt | |||
| ) |
Restore constructor.
| virtual Meta::MObject::~MObject | ( | ) | [virtual] |
Destructor.
Alternative value: if v1 is defined this function is a no-op, else set to v1 to v2.
| mnode Meta::MObject::attribute | ( | size_t | i | ) |
Get the i-th attribute.
| mnode Meta::MObject::attribute | ( | const mstr & | name, | |
| AttributeMode | mode = Raw | |||
| ) |
Get the named attribute.
| size_t Meta::MObject::attributeCount | ( | ) | const |
| mstr Meta::MObject::attributeName | ( | size_t | i | ) | const |
Get the name of the i-th attribute.
| mnode Meta::MObject::Attrs_ | ( | ) |
| mnode Meta::MObject::Break_ | ( | ) |
Break.
| MBrokerBase* Meta::MObject::broker | ( | ) |
| mnode Meta::MObject::Catalan_ | ( | ) |
High precision Catalan constant.
Used for evaluation at the compilation/parsing stage.
| const mstr& Meta::MObject::className | ( | ) | const |
Get this object's class name.
| void Meta::MObject::clearCues | ( | MObject * | receiver | ) |
Remove all cues this object has mappings for involving receiver.
| void Meta::MObject::clearCues | ( | ) |
Remove all cues this object has mappings for.
| void Meta::MObject::clearReceiveCues | ( | MObject * | emitter | ) |
Remove all cues from the specified emitter in which this object is the target.
| void Meta::MObject::clearReceiveCues | ( | ) |
Remove all cues (from other objects) in which this object as receiver.
Functional version of MVar::clearSeq().
| virtual MObject* Meta::MObject::clone | ( | ) | const [virtual] |
Reimplemented in Meta::MAgent, Meta::MMLEntity, and Meta::MRandom.
Used to specifiy code which is to be treated as data and not executed.
Return the result of applying ComplementA to v1 and v2.
Functional version of MVar::complement().
Similar to connectCue(3), this convenience method may be called when source function is identical to target function.
Connect a cue emitted by this object to a receiver.
| source | The source function e.g: update(a) | |
| receiver | The object to receive the cue. | |
| target | The target function for the receive to interpret, which may remap any of the source parameters. e.g: redraw("now",a). |
| mnode Meta::MObject::Continue_ | ( | ) |
Continue.
Identical to Def(2), but define within specified scope.
e.g: Def(Global,x,10)
Lazy definition (v is not evaluated), used for defining a function or aliasing a symbol to a function.
e.g: Def(diff(a,b),Sub(a,b))
Extract an element from a node, e.g: Elem(Add(1,2),0) => 1
| void Meta::MObject::emitCue | ( | mnode | f | ) |
Emit a cue, using the source/target mappings defined by connectCue().
| f | e.g: update(0) |
| void Meta::MObject::enableInterrupts | ( | bool | flag | ) |
Set whether this object periodically checks interrupts. See MInterrupt. For performance reasons, the default is not to check for interrupts.
| mnode Meta::MObject::Euler_ | ( | ) |
High precision Euler constant.
Process code data at the head of an mvar. If the result contains symbolic data, it is converted to code data and returned.
| mnode Meta::MObject::Finish_ | ( | ) |
Finish used to stop execution in various contexts.
| mnode Meta::MObject::Functions_ | ( | ) |
Index n with nk, creating the entry at nk if it doesn't exist.
Functional version of MVar::hasKey().
Index n at nk, nk must be a valid key or an MError is thrown.
Functional version of MVar::index().
Functional version of MVar::index().
Functional version of MVar::index().
Functional version of MVar::indexMap().
Info embeds information in M code which is ignored by the interpreter.
| virtual bool Meta::MObject::instanceOf | ( | ClassIdType | classId | ) | const [virtual] |
Reimplemented in Meta::MMLEntity, and Meta::MScope.
Functional version of MVar::intersect().
Functional version of MVar::intersect().
| bool Meta::MObject::inVirtual | ( | ) |
| bool Meta::MObject::isBasic | ( | ) | const |
| bool Meta::MObject::isConnected | ( | ) | const |
Called on the client-side of a distributed object.
| bool Meta::MObject::isDistributed | ( | ) | const |
Functional version of MVar::isEmpty().
| bool Meta::MObject::isExact | ( | ) | const |
| bool Meta::MObject::isLocal | ( | ) | const |
| bool Meta::MObject::isRemote | ( | ) | const |
| static bool Meta::MObject::isStandardType | ( | const mstr & | type | ) | [static] |
| bool Meta::MObject::isStrict | ( | ) | const |
Functional version of MVar::join().
Functional version of MVar::keys().
Functional version of MMath::listRange().
Functional version of MMath::listRange().
Functional version of MMath::listRange().
| bool Meta::MObject::lock | ( | const MTime & | timeout | ) |
Lock the object's general-purpose mutex with timeout.
| void Meta::MObject::lock | ( | ) |
Lock the object's general-purpose mutex.
Use left-recursion to convert n to k-arity nested functions.
Use left-recursion to convert n to nested binary functions, e.g: Add(1,2,3) => Add(Add(1,2),3)
| mnode Meta::MObject::method | ( | size_t | i | ) |
| size_t Meta::MObject::methodCount | ( | ) | const |
| mnode Meta::MObject::Methods_ | ( | ) |
| mnode Meta::MObject::NoOp_ | ( | ) |
A no-op, which may be erased from the M code.
Used to execute a function f once, leaving behind the value as evaluated.
| virtual void Meta::MObject::onClientClosed | ( | const mvar & | session | ) | [virtual] |
Called on the server-side of a distributed object when a connection to client is closed.
| session | The session data associated with the client. |
| virtual void Meta::MObject::onServerClosed | ( | ) | [virtual] |
Called on the client-side of a distributed object when the connection to server is closed.
Outer merge scope (s2's symbols/functions take precedence).
Typically called when n is a parameter passed to a function to be partially evaluated, e.g: for symbol lookup.
| mnode Meta::MObject::Pass_ | ( | ) |
A no-op placeholder.
| mnode Meta::MObject::Pi_ | ( | ) |
High precision constant pi.
| mnode Meta::MObject::PopScope_ | ( | ) |
Pop a scope from the current call stack.
Process method for processing a node through the M interpreter.
Implements Meta::MProcessor.
Reimplemented in Meta::MAgent, Meta::MLib, Meta::MMLEntity, Meta::MMLGraphScene, Meta::MMLGrid, Meta::MMLGridScene, Meta::MMLRobotScene, Meta::MMLRoot, Meta::MMLScene, Meta::MMLSceneBase, Meta::MMLSharedVar, Meta::MMLSpaceScene, Meta::MRandom, and Meta::MVideoEncoder.
Functional version of MMath::vectorRange().
Functional version of MMath::vectorRange().
Functional version of MMath::vectorRange().
Redefine a symbol or function. Redefines the first matching symbol or function on the stack.
| bool Meta::MObject::release | ( | ) |
From the client-side, release a remote object.
If this is a remote object (checked through isRemote()) then dispatch a request through a broker to process a method on the server-side of the object.
| block | false in order to not wait for the response. | |
| fail | The node to return upon failure, e.g: if a disconnect occurs during processing. |
Replace symbols in f with those mapped in m.
| mnode Meta::MObject::Reset_ | ( | ) |
Reset the interpreter, clearing all state.
| mnode Meta::MObject::ResetGlobal_ | ( | ) |
Reset the global scope and other global state.
Use right-recursion to convert n to k-arity nested functions/
Use right-recursion to convert n to nested binary functions, e.g: Add(1,2,3) => Add(1,Add(2,3))
| MScope* Meta::MObject::scope | ( | ) |
| mnode Meta::MObject::Scope_ | ( | ) |
Execute f from within a new scope pushed onto the call stack.
| const mvar& Meta::MObject::session | ( | ) | const |
Called on the server-side of a distributed object.
| mvar& Meta::MObject::session | ( | ) |
Called on the server-side of a distributed object.
| void Meta::MObject::setAttribute | ( | const mstr & | name, | |
| mnode | n, | |||
| AttributeMode | mode = Raw | |||
| ) |
Set the named attribute.
| void Meta::MObject::setClassName | ( | const mstr & | name | ) |
Set this object's class name. This is done automatically for MFactory-constructed objects.
| void Meta::MObject::setExact | ( | bool | flag | ) |
Set whether the interpreter uses exact math rather than returning floating point approximations (in some cases), e.g: an exact interpreter returns Sqrt(2) when Sqrt(2) is requested while non-exact mode would return 1.41421. The initial behavior of the object is to use non-exact math.
| sig | e.g: sum(a,b) | |
| body | e.g: Ret(Add(a,b,)) |
| void Meta::MObject::setStrict | ( | bool | flag | ) |
Set whether to enable strict interpretation (default is true). Strict interpreters throw an MProcessError when they attempt to process an undefined symbol or function. Non-strict interpreters leave it untouched, returning the unknown symbol or function.
Functional version of MVar::size().
Functional version of MVar::split().
Functional version of MVar::split().
| virtual void Meta::MObject::store | ( | mvar & | v | ) | const [virtual] |
Store this object to v.
Reimplemented in Meta::MAgent, Meta::MAuth, Meta::MHub, Meta::MMLEntity, Meta::MMLRoot, Meta::MPackage, Meta::MRandom, Meta::MScope, and Meta::MTime.
| mnode Meta::MObject::Symbols_ | ( | ) |
Throw an MError with the specified type and message. Node n contains the filename/line number.
Throw an MError with specified message. Node n contains the filename/line number.
| bool Meta::MObject::tryLock | ( | ) |
Attempt to lock the object's general-purpose mutex.
Construct a type with initial value.
Functional version of MVar::unite().
Functional version of MVar::unite().
Functional version of MVar::unite().
| void Meta::MObject::unlock | ( | ) |
Unlock the object's general-purpose mutex.
1.6.1