CXXR (C++ R)
|
Mechanism for deferred evaluation. More...
#include <Promise.h>
Public Member Functions | |
Promise (RObject *valgen, Environment *env) | |
Environment * | environment () const |
Access the environment of the Promise. | |
RObject * | force () |
Force the Promise. | |
bool | isMissingSymbol () const |
Not for general use. | |
void | setValue (RObject *val) |
Set value of the Promise. | |
RObject * | value () |
Access the value of a Promise. | |
const RObject * | valueGenerator () const |
RObject to be evaluated by the Promise. | |
RObject * | evaluate (Environment *env) |
Evaluate object in a specified Environment. | |
const char * | typeName () const |
Name within R of this type of object. | |
void | visitReferents (const_visitor *v) const |
Conduct a visitor to the nodes referred to by this one. | |
Public Member Functions inherited from CXXR::RObject | |
virtual const PairList * | attributes () const |
Get object attributes. | |
virtual void | clearAttributes () |
Remove all attributes. | |
virtual RObject * | clone () const |
Return pointer to a copy of this object. | |
void | copyAttribute (const Symbol *name, const RObject *source) |
Copy an attribute from one RObject to another. | |
void | copyAttributes (const RObject *source, bool copyS4) |
Copy attributes from one RObject to another. | |
virtual RObject * | getAttribute (const Symbol *name) const |
Get the value a particular attribute. | |
virtual bool | hasAttributes () const |
Has this object any attributes? | |
bool | hasClass () const |
Has this object the class attribute? | |
bool | isS4Object () const |
Is this an S4 object? | |
void | maybeTraceMemory (const RObject *src) |
Carry out memory tracing. | |
void | maybeTraceMemory (const RObject *src1, const RObject *src2) |
Carry out memory tracing. | |
void | maybeTraceMemory (const RObject *src1, const RObject *src2, const RObject *src3) |
Carry out memory tracing. | |
bool | memoryTraced () const |
Is copying etc. of this object being traced? | |
virtual unsigned int | packGPBits () const |
Reproduce the gp bits field used in CR. | |
virtual void | setAttribute (const Symbol *name, RObject *value) |
Set or remove an attribute. | |
void | setAttributes (const PairList *new_attributes) |
Replace the attributes of an object. | |
void | setMemoryTracing (bool on) |
Enable/disable tracing of copying etc. | |
void | setS4Object (bool on) |
Set the status of this RObject as an S4 object. | |
SEXPTYPE | sexptype () const |
Get an object's SEXPTYPE. | |
virtual void | unpackGPBits (unsigned int gpbits) |
Interpret the gp bits field used in CR. | |
Public Member Functions inherited from CXXR::GCNode | |
void | expose () const |
Record that construction of a node is complete. | |
bool | isExposed () const |
Has this node been exposed to garbage collection? | |
Public Member Functions inherited from CXXR::HeterogeneousListBase::Link | |
Link () | |
Default constructor. | |
Link (HeterogeneousListBase *list) | |
Appending constructor. | |
void | freeLink () |
Detach Link from any list. |
Static Public Member Functions | |
static const char * | staticTypeName () |
The name by which this type is known in R. | |
Static Public Member Functions inherited from CXXR::RObject | |
template<class T > | |
static T * | clone (const T *pattern) |
Return a pointer to a copy of an object. | |
Static Public Member Functions inherited from CXXR::GCNode | |
static void * | operator new (size_t bytes) |
Allocate memory. | |
static void * | operator new (size_t, void *where) |
Placement new for GCNode. | |
static void | operator delete (void *p, size_t bytes) |
Deallocate memory. | |
static bool | check () |
Integrity check. | |
template<class T > | |
static T * | expose (T *node) |
Record that construction of a node is complete. | |
static void | gc () |
Initiate a garbage collection. | |
static void | gclite () |
Lightweight garbage collection. | |
static void | maybeCheckExposed (const GCNode *node) |
Subject to configuration, check that a GCNode is exposed. | |
static size_t | numNodes () |
Number of GCNode objects in existence. |
Protected Member Functions | |
void | detachReferents () |
Null out all references from this node to other nodes. | |
Protected Member Functions inherited from CXXR::RObject | |
RObject (SEXPTYPE stype=CXXSXP) | |
RObject (const RObject &pattern) | |
Copy constructor. | |
Protected Member Functions inherited from CXXR::GCNode | |
virtual | ~GCNode () |
Protected Member Functions inherited from CXXR::HeterogeneousListBase::Link | |
virtual | ~Link () |
Friends | |
class | boost::serialization::access |
Additional Inherited Members | |
Public Attributes inherited from CXXR::RObject | |
unsigned char | m_named |
unsigned | m_missing: 2 |
unsigned | m_argused: 2 |
bool | m_active_binding: 1 |
bool | m_binding_locked: 1 |
Mechanism for deferred evaluation.
This class is used to handle function arguments within R's lazy evaluation scheme. A Promise object encapsulates a pointer to an arbitrary RObject (typically a Symbol or an Expression), and a pointer to an Environment. When the Promise is first evaluated, the RObject is evaluated within the Environment, and the result of evaluation returned as the value of the Promise.
After the first evaluation, the result of evaluation is cached within the Promise object, and the Environment pointer is set null (thus possibly allowing the Environment to be garbage-collected). Subsequent evaluations of the Promise object simply return the cached value.
|
inline |
valgen | pointer to RObject to be evaluated to provide the value of the Promise. Can be null. |
env | pointer to the Environment in which valgen is to be evaluated. If this pointer is null, the value of the Promise is immediately set to be valgen itself. |
|
protectedvirtual |
Null out all references from this node to other nodes.
The referents of this node are those objects (derived from GCNode) designated by a GCEdge within this object. This function changes all GCEdges within this object to encapsulate a null pointer. It is used during the sweep phase of a mark-sweep garbage collection to break up unreachable subgraphs, and in particular to remove reference loops from them. After the application of this method, the GCNode should be regarded as a 'zombie', kept in existence only so other nodes can detach their references to it cleanly (using decRefCount()).
Reimplemented from CXXR::RObject.
|
inline |
|
virtual |
Evaluate object in a specified Environment.
env | Pointer to the environment in which evaluation is to take place. |
Reimplemented from CXXR::RObject.
|
inline |
Force the Promise.
i.e. evaluate the value generator of the Promise within the Environment of the Promise. Following this, the environment pointer is set null, thus possibly allowing the Environment to be garbage-collected.
If this function is used on a Promise that has already been forced, it simply returns the previously computed value.
bool Promise::isMissingSymbol | ( | ) | const |
Not for general use.
This function is used by isMissingArgument(). It implements some logic from CR's R_isMissing() which I don't fully understand.
void Promise::setValue | ( | RObject * | val | ) |
Set value of the Promise.
Once the value is set to something other than Symbol::unboundValue(), the environment pointer is set null.
val | Value to be associated with the Promise. |
|
inlinestatic |
The name by which this type is known in R.
|
virtual |
Name within R of this type of object.
Reimplemented from CXXR::RObject.
|
inline |
Access the value of a Promise.
|
inline |
|
virtual |
Conduct a visitor to the nodes referred to by this one.
The referents of this node are those objects (derived from GCNode) designated by a GCEdge within this object.
v | Pointer to the visitor object. |
Reimplemented from CXXR::RObject.