Loading...
Searching...
No Matches
countedref.cc
Go to the documentation of this file.
// -*- c++ -*-
//*****************************************************************************
/** @file countedref.cc
*
* @author Alexander Dreyer
* @date 2012-08-15
*
* This file defines reference countes interpreter objects and adds the
* @c blackbox operations for high-level types 'reference' and 'shared'.
*
* @note This works was supported by the "Industrial Algebra" project.
*
* @par Copyright:
* (c) 2012 by The Singular Team, see LICENSE file
**/
//*****************************************************************************
#include "kernel/mod2.h"
#include "ipid.h"
#include "countedref.h"
#include "blackbox.h"
#include "newstruct.h"
#include "ipshell.h"
/// Overloading ring destruction
inline void CountedRefPtr_kill(ring r) { rKill(r); }
/** @class CountedRefData
* This class stores a reference counter as well as a Singular interpreter object.
* It also take care of the context, e.g. the current ring, wrap object, etc.
**/
class CountedRefData:
public RefCounter {
typedef CountedRefData self;
public:
typedef CountedRefWeakPtr<self*> back_ptr;
private:
typedef RefCounter base;
/// Generate object linked to other reference (e.g. for subscripts)
CountedRefData(leftv wrapid, back_ptr back):
base(), m_data(wrapid), m_ring(back->m_ring), m_back(back) {
}
/// @name Disallow copying to avoid inconsistence
//@{
self& operator=(const self&);
CountedRefData(const self&);
//@}
public:
typedef LeftvDeep::copy_tag copy_tag;
/// Fix smart pointer type to referenced data
typedef back_ptr::ptr_type ptr_type;
/// Fix smart pointer type to ring
typedef CountedRefPtr<ring, true> ring_ptr;
/// Construct shared memory empty Singular object
explicit CountedRefData():
base(), m_data(), m_ring(), m_back() { }
/// Reference Singular object
explicit CountedRefData(leftv data):
base(), m_data(data), m_ring(parent(data)), m_back() { }
/// Construct reference for Singular object
CountedRefData(leftv data, copy_tag do_copy):
base(), m_data(data, do_copy), m_ring(parent(data)), m_back() { }
/// Destruct
~CountedRefData() {
if (!m_back.unassigned()) {
if (m_back == this)
m_back.invalidate();
else
m_data.clearid(root());
}
}
/// Generate object for indexing
ptr_type wrapid() { return new self(m_data.idify(root()), weakref()); }
/// Gerenate weak (but managed) reference to @c *this
back_ptr weakref() {
if (m_back.unassigned())
m_back = this;
return m_back;
}
/// Replace with other Singular data
self& operator=(leftv rhs) {
m_data = rhs;
m_ring = parent(rhs);
return *this;
}
/// Write (shallow) copy to given handle
BOOLEAN put(leftv res) { return broken() || m_data.put(res); }
/// Extract (shallow) copy of stored data
LeftvShallow operator*() { return (broken()? LeftvShallow(): LeftvShallow(m_data)); }
/// Determine active ring when ring dependency changes
BOOLEAN rering() {
if (m_ring ^ m_data.ringed()) m_ring = (m_ring? NULL: currRing);
return (m_back && (m_back != this) && m_back->rering());
}
/// Get the current context
idhdl* root() { return (m_ring? &m_ring->idroot: &IDROOT); }
/// Check whether identifier became invalid
BOOLEAN broken() const {
if (!m_back.unassigned() && !m_back)
return complain("Back-reference broken");
if (m_ring) {
if (m_ring != currRing)
return complain("Referenced identifier not from current ring");
return m_data.isid() && m_data.brokenid(currRing->idroot) &&
complain("Referenced identifier not available in ring anymore");
}
if (!m_data.isid()) return FALSE;
return m_data.brokenid(IDROOT) &&
((currPack == basePack) || m_data.brokenid(basePack->idroot)) &&
complain("Referenced identifier not available in current context");
}
/// Reassign actual object
BOOLEAN assign(leftv result, leftv arg) {
if (!m_data.isid()) {
(*this) = arg;
return FALSE;
}
return put(result) || iiAssign(result, arg) || rering();
}
/// Recover additional information (e.g. subexpression) from likewise object
BOOLEAN retrieve(leftv res) { return m_data.retrieve(res); }
/// Check whether data is all-zero
BOOLEAN unassigned() const { return m_data.unassigned(); }
private:
/// Raise error message and return @c TRUE
BOOLEAN complain(const char* text) const
{
WerrorS(text);
return TRUE;
}
/// Store ring for ring-dependent objects
static ring parent(leftv rhs)
{
return (rhs->RingDependend()? currRing: NULL);
}
protected:
/// Singular object
LeftvDeep m_data;
/// Store namespace for ring-dependent objects
ring_ptr m_ring;
/// Reference to actual object for wrap structures
back_ptr m_back;
};
/// Supporting smart pointer @c CountedRefPtr
inline void CountedRefPtr_kill(CountedRefData* data) { delete data; }
/// blackbox support - initialization
void* countedref_Init(blackbox*)
{
return NULL;
}
/// We use the function pointer as a marker of reference types
/// for CountedRef::is_ref(leftv), see the latter for details
BOOLEAN countedref_CheckAssign(blackbox */*b*/, leftv /*L*/, leftv /*R*/)
{
return FALSE;
}
class CountedRef {
typedef CountedRef self;
public:
/// name type for identifiers
typedef int id_type;
/// Name type for handling referenced data
typedef CountedRefData data_type;
/// Fix smart pointer type to referenced data
typedef CountedRefPtr<CountedRefData*> data_ptr;
/// Check whether argument is already a reference type
/// @note We check for the function pointer @c countedref_CheckAssign here,
/// that we (ab-)use as a unique marker. This avoids to check a bunch of
/// of runtime-varying @c typ IDs for identifying reference-like types.
static BOOLEAN is_ref(leftv arg) {
int typ = arg->Typ();
return ((typ > MAX_TOK) &&
(getBlackboxStuff(typ)->blackbox_CheckAssign == countedref_CheckAssign));
}
/// Reference given Singular data
explicit CountedRef(leftv arg): m_data(new data_type(arg)) { }
protected:
/// Recover previously constructed reference
CountedRef(data_ptr arg): m_data(arg) { assume(arg); }
public:
/// Construct copy
CountedRef(const self& rhs): m_data(rhs.m_data) { }
/// Replace reference
self& operator=(const self& rhs) {
m_data = rhs.m_data;
return *this;
}
BOOLEAN assign(leftv result, leftv arg) {
return m_data->assign(result,arg);
}
/// Extract (shallow) copy of stored data
LeftvShallow operator*() { return m_data->operator*(); }
/// Construct reference data object marked by given identifier number
BOOLEAN outcast(leftv res, int typ) {
res->rtyp = typ;
return outcast(res);
}
/// Construct reference data object from *this
BOOLEAN outcast(leftv res) {
if (res->rtyp == IDHDL)
IDDATA((idhdl)res->data) = (char *)outcast();
else
res->data = (void *)outcast();
return FALSE;
}
/// Construct raw reference data
data_type* outcast() {
m_data.reclaim();
return m_data;
}
/// Kills a link to the referenced object
void destruct() { m_data.release(); }
/// Kills the link to the referenced object
~CountedRef() { }
/// Replaces argument by a shallow copy of the references data
BOOLEAN dereference(leftv arg) {
m_data.reclaim();
BOOLEAN b= m_data->put(arg) || ((arg->next != NULL) && resolve(arg->next));
m_data.release();
return b;
}
/// Check whether object in valid in current context
BOOLEAN broken() {return m_data->broken(); }
/// Check whether (shared) data was initialized but not assigned yet.
BOOLEAN unassigned() const { return m_data->unassigned(); }
/// Get number of references pointing here, too
BOOLEAN count(leftv res) { return construct(res, m_data.count() - 1); }
// Get internal identifier
BOOLEAN enumerate(leftv res) { return construct(res, (long)(data_type*)m_data); }
/// Check for likewise identifiers
BOOLEAN likewise(leftv res, leftv arg) {
return resolve(arg) || construct(res, operator*()->data == arg->data);
}
/// Check for identical reference objects
BOOLEAN same(leftv res, leftv arg) {
return construct(res, m_data == arg->Data());
}
/// Get type of references data
BOOLEAN type(leftv res) {
return construct(res, Tok2Cmdname(operator*()->Typ()));
};
/// Get (possibly) internal identifier name
BOOLEAN name(leftv res) { return construct(res, operator*()->Name()); }
/// Recover the actual object from raw Singular data
static self cast(void* data) {
assume(data != NULL);
return self(static_cast<data_type*>(data));
}
/// Recover the actual object from Singular interpreter object
static self cast(leftv arg) {
assume(arg != NULL); assume(is_ref(arg));
return self::cast(arg->Data());
}
/// If necessary dereference.
static BOOLEAN resolve(leftv arg) {
assume(arg != NULL);
while (is_ref(arg)) { if(CountedRef::cast(arg).dereference(arg)) return TRUE; };
return (arg->next != NULL) && resolve(arg->next);
}
/// Construct integer value
static BOOLEAN construct(leftv res, long data) {
res->data = (void*) data;
res->rtyp = INT_CMD;
return FALSE;
}
/// Construct string
static BOOLEAN construct(leftv res, const char* data) {
res->data = (void*)omStrDup(data);
res->rtyp = STRING_CMD;
return FALSE;
}
/// Construct void-style object
static BOOLEAN construct(leftv res) {
res->data = NULL;
res->rtyp = NONE;
return FALSE;
}
protected:
/// Store pointer to actual data
data_ptr m_data;
};
/// blackbox support - convert to string representation
void countedref_Print(blackbox */*b*/, void* ptr)
{
if (ptr) (*CountedRef::cast(ptr))->Print();
else PrintS("<unassigned reference or shared memory>");
}
/// blackbox support - convert to string representation
char* countedref_String(blackbox */*b*/, void* ptr)
{
if (ptr == NULL) return omStrDup(sNoName_fe);
return (*CountedRef::cast(ptr))->String();
}
/// blackbox support - copy element
void* countedref_Copy(blackbox*/*b*/, void* ptr)
{
if (ptr) return CountedRef::cast(ptr).outcast();
return NULL;
}
/// blackbox support - assign element
BOOLEAN countedref_Assign(leftv result, leftv arg)
{
// Case: replace assignment behind reference
if (result->Data() != NULL) {
CountedRef ref = CountedRef::cast(result);
return CountedRef::resolve(arg) || ref.assign(result, arg);
}
// Case: copy reference
if (result->Typ() == arg->Typ())
return CountedRef::cast(arg).outcast(result);
// Case: new reference
if ((arg->rtyp == IDHDL) || CountedRef::is_ref(arg))
return CountedRef(arg).outcast(result);
WerrorS("Can only take reference from identifier");
return TRUE;
}
BOOLEAN countedref_CheckInit(leftv res, leftv arg)
{
if (arg->Data() != NULL) return FALSE;
res->rtyp = NONE;
WerrorS("Noninitialized access");
return TRUE;
}
/// blackbox support - unary operations
BOOLEAN countedref_Op1(int op, leftv res, leftv head)
{
if(op == TYPEOF_CMD)
return blackboxDefaultOp1(op, res, head);
if (countedref_CheckInit(res, head)) return TRUE;
if ((op == DEF_CMD) || (op == head->Typ()))
{
res->rtyp = head->Typ();
return iiAssign(res, head);
}
CountedRef ref = CountedRef::cast(head);
return ref.dereference(head) ||
iiExprArith1(res, head, op == LINK_CMD? head->Typ(): op);
}
/// blackbox support - binary operations (resolve seocnd argument)
static BOOLEAN countedref_Op2_(int op, leftv res, leftv head, leftv arg)
{
if (CountedRef::is_ref(arg))
{
CountedRef ref = CountedRef::cast(arg);
return ref.dereference(arg) || iiExprArith2(res, head, op, arg);
}
return iiExprArith2(res, head, op, arg);
}
BOOLEAN countedref_Op2(int op, leftv res, leftv head, leftv arg)
{
if (countedref_CheckInit(res, head)) return TRUE;
if (CountedRef::is_ref(head))
{
CountedRef ref = CountedRef::cast(head);
return ref.dereference(head) || countedref_Op2_(op, res, head, arg);
}
return countedref_Op2_(op, res, head, arg);
}
static BOOLEAN countedref_Op3__(int op, leftv res, leftv head, leftv arg1, leftv arg2)
{
if (CountedRef::is_ref(arg2))
{
CountedRef ref = CountedRef::cast(arg2);
return ref.dereference(arg2) || iiExprArith3(res, op, head, arg1, arg2);
}
return iiExprArith3(res, op, head, arg1, arg2);
}
static BOOLEAN countedref_Op3_(int op, leftv res, leftv head, leftv arg1, leftv arg2)
{
if (CountedRef::is_ref(arg1))
{
CountedRef ref = CountedRef::cast(arg1);
return ref.dereference(arg1) || countedref_Op3__(op, res, head, arg1, arg2);
}
return countedref_Op3__(op, res, head, arg1, arg2);
}
/// blackbox support - ternary operations
BOOLEAN countedref_Op3(int op, leftv res, leftv head, leftv arg1, leftv arg2)
{
if (countedref_CheckInit(res, head)) return TRUE;
if (CountedRef::is_ref(head))
{
CountedRef ref = CountedRef::cast(head);
return ref.dereference(head) || countedref_Op3_(op, res, head, arg1, arg2);
}
return countedref_Op3_(op, res, head, arg1, arg2);
}
/// blackbox support - destruction
void countedref_destroy(blackbox */*b*/, void* ptr)
{
if (ptr) CountedRef::cast(ptr).destruct();
}
class CountedRefShared:
public CountedRef
{
typedef CountedRefShared self;
typedef CountedRef base;
/// Reinterprete @c CountedRef as @c CountedRefShared
CountedRefShared(const base& rhs): base(rhs) { }
/// Generate from data pointer
CountedRefShared(data_ptr rhs): base(rhs) { }
public:
/// Default constructor for initialized, but all-zero, shared data object
CountedRefShared(): base(new data_type) { }
/// Construct internal copy of Singular interpreter object
explicit CountedRefShared(leftv arg): base(new data_type(arg, data_type::copy_tag())) { }
/// Construct new reference to internal data
CountedRefShared(const self& rhs): base(rhs) { }
/// Desctruct
~CountedRefShared() { }
/// Change reference to shared data
self& operator=(const self& rhs) {
return static_cast<self&>(base::operator=(rhs));
}
/// Recovering outcasted @c CountedRefShared object from interpreter object
static self cast(leftv arg) { return base::cast(arg); }
/// Recovering outcasted @c CountedRefShared object from raw data
static self cast(void* arg) { return base::cast(arg); }
/// Temporarily wrap with identifier for '[' and '.' operation
self wrapid() { return self(m_data->wrapid()); }
/// Generate weak reference (may get invalid)
data_type::back_ptr weakref() { return m_data->weakref(); }
/// Recover more information (e.g. subexpression data) from computed result
BOOLEAN retrieve(leftv res, int typ)
{
return (m_data->retrieve(res) && outcast(res, typ));
}
};
/// Blackbox support - generate initialized, but all-zero - shared data
void* countedref_InitShared(blackbox*)
{
return CountedRefShared().outcast();
}
/// Blackbox support - unary operation for shared data
BOOLEAN countedref_Op1Shared(int op, leftv res, leftv head)
{
if(op == TYPEOF_CMD)
return blackboxDefaultOp1(op, res, head);
if (countedref_CheckInit(res, head)) return TRUE;
if ((op == DEF_CMD) || (op == head->Typ()))
{
res->rtyp = head->Typ();
return iiAssign(res, head);
}
CountedRefShared ref = CountedRefShared::cast(head);
if (op == LINK_CMD)
{
if (ref.dereference(head)) return TRUE;
res->Copy(head);
return (res->Typ() == NONE);
}
CountedRefShared wrap = ref.wrapid();
int typ = head->Typ();
return wrap.dereference(head) || iiExprArith1(res, head, op) ||
wrap.retrieve(res, typ);
}
/// blackbox support - binary operations
BOOLEAN countedref_Op2Shared(int op, leftv res, leftv head, leftv arg)
{
if (countedref_CheckInit(res, head)) return TRUE;
if (CountedRefShared::is_ref(head))
{
CountedRefShared wrap = CountedRefShared::cast(head).wrapid();
int typ = head->Typ();
return wrap.dereference(head) || countedref_Op2_(op, res, head, arg) ||
wrap.retrieve(res, typ);
}
return countedref_Op2_(op, res, head, arg);
}
/// blackbox support - n-ary operations
BOOLEAN countedref_OpM(int op, leftv res, leftv args)
{
if (args->Data() == NULL) return FALSE;
if(op == SYSTEM_CMD)
{
if (args->next)
{
leftv next = args->next;
args->next = NULL;
char* name = (next->Typ() == STRING_CMD?
(char*) next->Data(): (char*)next->Name());
next = next->next;
if (strcmp(name, "help") == 0)
{
PrintS("system(<ref>, ...): extended functionality for reference/shared data <ref>\n");
PrintS(" system(<ref>, count) - number of references pointing to <ref>\n");
PrintS(" system(<ref>, enumerate) - unique number for identifying <ref>\n");
PrintS(" system(<ref>, undefined) - checks whether <ref> had been assigned\n");
PrintS(" system(<ref>, \"help\") - prints this information message\n");
PrintS(" system(<ref>, \"typeof\") - actual type referenced by <ref>\n");
PrintS(" system(<ref1>, same, <ref2>) - tests for identic reference objects\n");
return CountedRef::construct(res);
}
if (strncmp(name, "undef", 5) == 0)
{
return CountedRef::construct(res, args->Data()?
(CountedRef::cast(args).unassigned()? 1: 2): 0);
}
CountedRef obj = CountedRef::cast(args);
if (next)
{
if (strcmp(name, "same") == 0) return obj.same(res, next);
// likewise may be hard to interprete, so we not not document it above
if (strncmp(name, "like", 4) == 0) return obj.likewise(res, next);
}
if (strncmp(name, "count", 5) == 0) return obj.count(res);
if (strncmp(name, "enum", 4) == 0) return obj.enumerate(res);
if (strcmp(name, "name") == 0) return obj.name(res); // undecumented
if (strncmp(name, "typ", 3) == 0) return obj.type(res);
}
return TRUE;
}
if (op == LIST_CMD)
{
res->rtyp = op;
return jjLIST_PL(res, args);
}
CountedRef ref = CountedRef::cast(args);
return ref.dereference(args) || iiExprArithM(res, args, op);
}
/// blackbox support - assign element
BOOLEAN countedref_AssignShared(leftv result, leftv arg)
{
/// Case: replace assignment behind reference
if ((result->Data() != NULL) && !CountedRefShared::cast(result).unassigned()) {
CountedRef ref = CountedRef::cast(result);
return CountedRef::resolve(arg) || ref.assign(result, arg);
}
/// Case: new reference to already shared data
if (result->Typ() == arg->Typ())
{
if (result->Data() != NULL)
CountedRefShared::cast(result).destruct();
return CountedRefShared::cast(arg).outcast(result);
}
if(CountedRefShared::cast(result).unassigned())
{
return CountedRefShared::cast(result).assign(result, arg);
}
/// Case: new shared data
return CountedRefShared(arg).outcast(result);
}
/// blackbox support - destruction
void countedref_destroyShared(blackbox */*b*/, void* ptr)
{
if (ptr) CountedRefShared::cast(ptr).destruct();
}
BOOLEAN countedref_serialize(blackbox */*b*/, void *d, si_link f)
{
sleftv l;
memset(&l,0,sizeof(l));
l.rtyp = STRING_CMD;
l.data = (void*)omStrDup("shared"); // references are converted
f->m->Write(f, &l);
CountedRefShared::cast(d).dereference(&l);
f->m->Write(f, &l);
return FALSE;
}
BOOLEAN countedref_deserialize(blackbox **/*b*/, void **d, si_link f)
{
// rtyp must be set correctly (to the blackbox id) by routine calling
leftv data=f->m->Read(f);
CountedRefShared sh(data);
*d = sh.outcast();
return FALSE;
}
void countedref_reference_load()
{
int tok;
if (blackboxIsCmd("reference", tok) == ROOT_DECL)
return;
blackbox *bbx = (blackbox*)omAlloc0(sizeof(blackbox));
bbx->blackbox_CheckAssign = countedref_CheckAssign;
bbx->blackbox_destroy = countedref_destroy;
bbx->blackbox_String = countedref_String;
bbx->blackbox_Print = countedref_Print;
bbx->blackbox_Init = countedref_Init;
bbx->blackbox_Copy = countedref_Copy;
bbx->blackbox_Assign = countedref_Assign;
bbx->blackbox_Op1 = countedref_Op1;
bbx->blackbox_Op2 = countedref_Op2;
bbx->blackbox_Op3 = countedref_Op3;
bbx->blackbox_OpM = countedref_OpM;
bbx->blackbox_serialize = countedref_serialize;
bbx->blackbox_deserialize = countedref_deserialize;
bbx->data = omAlloc0(newstruct_desc_size());
setBlackboxStuff(bbx, "reference");
}
void countedref_shared_load()
{
int tok;
if (blackboxIsCmd("shared", tok) == ROOT_DECL)
return;
blackbox *bbxshared = (blackbox*)omAlloc0(sizeof(blackbox));
bbxshared->blackbox_String = countedref_String;
bbxshared->blackbox_Print = countedref_Print;
bbxshared->blackbox_Copy = countedref_Copy;
bbxshared->blackbox_Op3 = countedref_Op3;
bbxshared->blackbox_OpM = countedref_OpM;
bbxshared->blackbox_serialize = countedref_serialize;
bbxshared->blackbox_deserialize = countedref_deserialize;
bbxshared->blackbox_CheckAssign = countedref_CheckAssign;
bbxshared->blackbox_Assign = countedref_AssignShared;
bbxshared->blackbox_destroy = countedref_destroyShared;
bbxshared->blackbox_Op1 = countedref_Op1Shared;
bbxshared->blackbox_Op2 = countedref_Op2Shared;
bbxshared->blackbox_Init = countedref_InitShared;
bbxshared->data = omAlloc0(newstruct_desc_size());
setBlackboxStuff(bbxshared, "shared");
}
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
setBlackboxStuff
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
Definition blackbox.cc:143
getBlackboxStuff
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition blackbox.cc:17
blackboxIsCmd
int blackboxIsCmd(const char *n, int &tok)
used by scanner: returns ROOT_DECL for known types (and the type number in tok)
Definition blackbox.cc:219
blackboxDefaultOp1
BOOLEAN blackboxDefaultOp1(int op, leftv l, leftv r)
default procedure blackboxDefaultOp1, to be called as "default:" branch
Definition blackbox.cc:78
blackbox.h
head
CanonicalForm head(const CanonicalForm &f)
Definition canonicalform.h:360
l
int l
Definition cfEzgcd.cc:100
b
CanonicalForm b
Definition cfModGcd.cc:4111
f
FILE * f
Definition checklibs.c:9
CountedRefData
This class stores a reference counter as well as a Singular interpreter object.
Definition countedref.cc:42
CountedRefData::copy_tag
LeftvDeep::copy_tag copy_tag
Fix smart pointer type to referenced data.
Definition countedref.cc:61
CountedRefData::back_ptr
CountedRefWeakPtr< self * > back_ptr
Definition countedref.cc:45
CountedRefData::m_ring
ring_ptr m_ring
Store namespace for ring-dependent objects.
Definition countedref.cc:175
CountedRefData::operator=
self & operator=(leftv rhs)
Replace with other Singular data.
Definition countedref.cc:101
CountedRefData::parent
static ring parent(leftv rhs)
Store ring for ring-dependent objects.
Definition countedref.cc:165
CountedRefData::broken
BOOLEAN broken() const
Check whether identifier became invalid.
Definition countedref.cc:123
CountedRefData::~CountedRefData
~CountedRefData()
Destruct.
Definition countedref.cc:82
CountedRefData::m_data
LeftvDeep m_data
Singular object.
Definition countedref.cc:172
CountedRefData::CountedRefData
CountedRefData(const self &)
Fix smart pointer type to referenced data.
CountedRefData::operator*
LeftvShallow operator*()
Extract (shallow) copy of stored data.
Definition countedref.cc:111
CountedRefData::ptr_type
back_ptr::ptr_type ptr_type
Fix smart pointer type to referenced data.
Definition countedref.cc:64
CountedRefData::root
idhdl * root()
Get the current context.
Definition countedref.cc:120
CountedRefData::CountedRefData
CountedRefData(leftv data)
Reference Singular object.
Definition countedref.cc:74
CountedRefData::CountedRefData
CountedRefData(leftv wrapid, back_ptr back)
Generate object linked to other reference (e.g. for subscripts).
Definition countedref.cc:50
CountedRefData::CountedRefData
CountedRefData()
Construct shared memory empty Singular object.
Definition countedref.cc:70
CountedRefData::base
RefCounter base
Definition countedref.cc:47
CountedRefData::m_back
back_ptr m_back
Reference to actual object for wrap structures.
Definition countedref.cc:178
CountedRefData::ring_ptr
CountedRefPtr< ring, true > ring_ptr
Fix smart pointer type to ring.
Definition countedref.cc:67
CountedRefData::complain
BOOLEAN complain(const char *text) const
Raise error message and return TRUE.
Definition countedref.cc:158
CountedRefData::rering
BOOLEAN rering()
Determine active ring when ring dependency changes.
Definition countedref.cc:114
CountedRefData::retrieve
BOOLEAN retrieve(leftv res)
Recover additional information (e.g. subexpression) from likewise object.
Definition countedref.cc:151
CountedRefData::self
CountedRefData self
Definition countedref.cc:43
CountedRefData::put
BOOLEAN put(leftv res)
Write (shallow) copy to given handle.
Definition countedref.cc:108
CountedRefData::operator=
self & operator=(const self &)
Fix smart pointer type to referenced data.
CountedRefData::weakref
back_ptr weakref()
Gerenate weak (but managed) reference to *this.
Definition countedref.cc:95
CountedRefData::unassigned
BOOLEAN unassigned() const
Check whether data is all-zero.
Definition countedref.cc:154
CountedRefData::assign
BOOLEAN assign(leftv result, leftv arg)
Reassign actual object.
Definition countedref.cc:142
CountedRefData::CountedRefData
CountedRefData(leftv data, copy_tag do_copy)
Construct reference for Singular object.
Definition countedref.cc:78
CountedRefData::wrapid
ptr_type wrapid()
Generate object for indexing.
Definition countedref.cc:92
CountedRefPtr
This class implements a smart pointer which handles pointer-style access to a reference-counted struc...
Definition countedref.h:43
CountedRefShared
Definition countedref.cc:492
CountedRefShared::~CountedRefShared
~CountedRefShared()
Desctruct.
Definition countedref.cc:513
CountedRefShared::retrieve
BOOLEAN retrieve(leftv res, int typ)
Recover more information (e.g. subexpression data) from computed result.
Definition countedref.cc:533
CountedRefShared::weakref
data_type::back_ptr weakref()
Generate weak reference (may get invalid).
Definition countedref.cc:530
CountedRefShared::CountedRefShared
CountedRefShared(data_ptr rhs)
Generate from data pointer.
Definition countedref.cc:500
CountedRefShared::CountedRefShared
CountedRefShared(leftv arg)
Construct internal copy of Singular interpreter object.
Definition countedref.cc:507
CountedRefShared::operator=
self & operator=(const self &rhs)
Change reference to shared data.
Definition countedref.cc:516
CountedRefShared::CountedRefShared
CountedRefShared()
Default constructor for initialized, but all-zero, shared data object.
Definition countedref.cc:504
CountedRefShared::base
CountedRef base
Definition countedref.cc:494
CountedRefShared::CountedRefShared
CountedRefShared(const self &rhs)
Construct new reference to internal data.
Definition countedref.cc:510
CountedRefShared::cast
static self cast(leftv arg)
Recovering outcasted CountedRefShared object from interpreter object.
Definition countedref.cc:521
CountedRefShared::cast
static self cast(void *arg)
Recovering outcasted CountedRefShared object from raw data.
Definition countedref.cc:524
CountedRefShared::self
CountedRefShared self
Definition countedref.cc:493
CountedRefShared::wrapid
self wrapid()
Temporarily wrap with identifier for '[' and '.' operation.
Definition countedref.cc:527
CountedRefShared::CountedRefShared
CountedRefShared(const base &rhs)
Reinterprete CountedRef as CountedRefShared.
Definition countedref.cc:497
CountedRefWeakPtr
Definition countedref.h:154
CountedRefWeakPtr< self * >::ptr_type
self * ptr_type
Definition countedref.h:161
CountedRef
Definition countedref.cc:199
CountedRef::type
BOOLEAN type(leftv res)
Get type of references data.
Definition countedref.cc:304
CountedRef::resolve
static BOOLEAN resolve(leftv arg)
If necessary dereference.
Definition countedref.cc:324
CountedRef::dereference
BOOLEAN dereference(leftv arg)
Replaces argument by a shallow copy of the references data.
Definition countedref.cc:274
CountedRef::unassigned
BOOLEAN unassigned() const
Check whether (shared) data was initialized but not assigned yet.
Definition countedref.cc:285
CountedRef::operator*
LeftvShallow operator*()
Extract (shallow) copy of stored data.
Definition countedref.cc:244
CountedRef::cast
static self cast(leftv arg)
Recover the actual object from Singular interpreter object.
Definition countedref.cc:318
CountedRef::outcast
BOOLEAN outcast(leftv res, int typ)
Construct reference data object marked by given identifier number.
Definition countedref.cc:247
CountedRef::likewise
BOOLEAN likewise(leftv res, leftv arg)
Check for likewise identifiers.
Definition countedref.cc:294
CountedRef::broken
BOOLEAN broken()
Check whether object in valid in current context.
Definition countedref.cc:282
CountedRef::id_type
int id_type
name type for identifiers
Definition countedref.cc:204
CountedRef::CountedRef
CountedRef(const self &rhs)
Construct copy.
Definition countedref.cc:231
CountedRef::enumerate
BOOLEAN enumerate(leftv res)
Definition countedref.cc:291
CountedRef::outcast
BOOLEAN outcast(leftv res)
Construct reference data object from *this.
Definition countedref.cc:253
CountedRef::assign
BOOLEAN assign(leftv result, leftv arg)
Definition countedref.cc:239
CountedRef::~CountedRef
~CountedRef()
Kills the link to the referenced object.
Definition countedref.cc:271
CountedRef::operator=
self & operator=(const self &rhs)
Replace reference.
Definition countedref.cc:234
CountedRef::destruct
void destruct()
Kills a link to the referenced object.
Definition countedref.cc:268
CountedRef::construct
static BOOLEAN construct(leftv res, const char *data)
Construct string.
Definition countedref.cc:338
CountedRef::CountedRef
CountedRef(leftv arg)
Reference given Singular data.
Definition countedref.cc:223
CountedRef::m_data
data_ptr m_data
Store pointer to actual data.
Definition countedref.cc:352
CountedRef::same
BOOLEAN same(leftv res, leftv arg)
Check for identical reference objects.
Definition countedref.cc:299
CountedRef::construct
static BOOLEAN construct(leftv res, long data)
Construct integer value.
Definition countedref.cc:331
CountedRef::outcast
data_type * outcast()
Construct raw reference data.
Definition countedref.cc:262
CountedRef::data_ptr
CountedRefPtr< CountedRefData * > data_ptr
Fix smart pointer type to referenced data.
Definition countedref.cc:210
CountedRef::CountedRef
CountedRef(data_ptr arg)
Recover previously constructed reference.
Definition countedref.cc:227
CountedRef::is_ref
static BOOLEAN is_ref(leftv arg)
Check whether argument is already a reference type.
Definition countedref.cc:216
CountedRef::data_type
CountedRefData data_type
Name type for handling referenced data.
Definition countedref.cc:207
CountedRef::name
BOOLEAN name(leftv res)
Get (possibly) internal identifier name.
Definition countedref.cc:309
CountedRef::self
CountedRef self
Definition countedref.cc:200
CountedRef::construct
static BOOLEAN construct(leftv res)
Construct void-style object.
Definition countedref.cc:344
CountedRef::cast
static self cast(void *data)
Recover the actual object from raw Singular data.
Definition countedref.cc:312
CountedRef::count
BOOLEAN count(leftv res)
Get number of references pointing here, too.
Definition countedref.cc:288
LeftvDeep
This class wraps leftv by taking into account memory allocation, destruction as well as deeply copyin...
Definition countedref.h:335
LeftvDeep::copy_tag
Construct even deeper copy: Skip identifier (if any) and take care of the data on our own.
Definition countedref.h:357
LeftvShallow
This class wraps leftv by taking into account memory allocation, destruction as well as shallowly cop...
Definition countedref.h:285
RefCounter::CountedRefPtr
friend class CountedRefPtr
Allow our smart pointer to access internals.
Definition countedref.h:119
RefCounter::RefCounter
RefCounter(...)
Any Constructor resets the counter.
Definition countedref.h:122
sleftv
Class used for (list of) interpreter objects.
Definition subexpr.h:83
sleftv::Typ
int Typ()
Definition subexpr.cc:1048
sleftv::rtyp
int rtyp
Definition subexpr.h:91
sleftv::Data
void * Data()
Definition subexpr.cc:1192
sleftv::RingDependend
BOOLEAN RingDependend()
Definition subexpr.cc:421
sleftv::next
leftv next
Definition subexpr.h:86
sleftv::data
void * data
Definition subexpr.h:88
CountedRefPtr_kill
void CountedRefPtr_kill(ring r)
Overloading ring destruction.
Definition countedref.cc:34
countedref_String
char * countedref_String(blackbox *, void *ptr)
blackbox support - convert to string representation
Definition countedref.cc:363
countedref_CheckInit
BOOLEAN countedref_CheckInit(leftv res, leftv arg)
Definition countedref.cc:397
countedref_Op2Shared
BOOLEAN countedref_Op2Shared(int op, leftv res, leftv head, leftv arg)
blackbox support - binary operations
Definition countedref.cc:576
countedref_serialize
BOOLEAN countedref_serialize(blackbox *, void *d, si_link f)
Definition countedref.cc:679
countedref_destroyShared
void countedref_destroyShared(blackbox *, void *ptr)
blackbox support - destruction
Definition countedref.cc:673
countedref_Print
void countedref_Print(blackbox *, void *ptr)
blackbox support - convert to string representation
Definition countedref.cc:356
countedref_deserialize
BOOLEAN countedref_deserialize(blackbox **, void **d, si_link f)
Definition countedref.cc:691
countedref_InitShared
void * countedref_InitShared(blackbox *)
Blackbox support - generate initialized, but all-zero - shared data.
Definition countedref.cc:540
countedref_Op2_
static BOOLEAN countedref_Op2_(int op, leftv res, leftv head, leftv arg)
blackbox support - binary operations (resolve seocnd argument)
Definition countedref.cc:427
countedref_AssignShared
BOOLEAN countedref_AssignShared(leftv result, leftv arg)
blackbox support - assign element
Definition countedref.cc:648
countedref_OpM
BOOLEAN countedref_OpM(int op, leftv res, leftv args)
blackbox support - n-ary operations
Definition countedref.cc:592
countedref_Op3
BOOLEAN countedref_Op3(int op, leftv res, leftv head, leftv arg1, leftv arg2)
blackbox support - ternary operations
Definition countedref.cc:471
countedref_Op3__
static BOOLEAN countedref_Op3__(int op, leftv res, leftv head, leftv arg1, leftv arg2)
Definition countedref.cc:448
countedref_Assign
BOOLEAN countedref_Assign(leftv result, leftv arg)
blackbox support - assign element
Definition countedref.cc:377
countedref_Op2
BOOLEAN countedref_Op2(int op, leftv res, leftv head, leftv arg)
Definition countedref.cc:437
countedref_Init
void * countedref_Init(blackbox *)
blackbox support - initialization
Definition countedref.cc:186
countedref_destroy
void countedref_destroy(blackbox *, void *ptr)
blackbox support - destruction
Definition countedref.cc:484
countedref_Op1Shared
BOOLEAN countedref_Op1Shared(int op, leftv res, leftv head)
Blackbox support - unary operation for shared data.
Definition countedref.cc:546
countedref_Op3_
static BOOLEAN countedref_Op3_(int op, leftv res, leftv head, leftv arg1, leftv arg2)
Definition countedref.cc:459
countedref_reference_load
void countedref_reference_load()
Initialize blackbox types 'reference' and 'shared', or both.
Definition countedref.cc:700
countedref_Op1
BOOLEAN countedref_Op1(int op, leftv res, leftv head)
blackbox support - unary operations
Definition countedref.cc:406
countedref_CheckAssign
BOOLEAN countedref_CheckAssign(blackbox *, leftv, leftv)
We use the function pointer as a marker of reference types for CountedRef::is_ref(leftv),...
Definition countedref.cc:193
countedref_shared_load
void countedref_shared_load()
Definition countedref.cc:724
countedref_Copy
void * countedref_Copy(blackbox *, void *ptr)
blackbox support - copy element
Definition countedref.cc:370
countedref.h
This file defines reusable classes supporting reference counted interpreter objects and initiates the...
Print
#define Print
Definition emacs.cc:80
result
return result
Definition facAbsBiFact.cc:76
res
CanonicalForm res
Definition facAbsFact.cc:60
name
char name(const Variable &v)
Definition factory.h:189
WerrorS
void WerrorS(const char *s)
Definition feFopen.cc:24
sNoName_fe
const char sNoName_fe[]
Definition fevoices.cc:57
Tok2Cmdname
const char * Tok2Cmdname(int tok)
Definition gentable.cc:137
ROOT_DECL
@ ROOT_DECL
Definition grammar.cc:320
iiExprArith2
BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
Definition iparith.cc:9176
iiExprArith1
BOOLEAN iiExprArith1(leftv res, leftv a, int op)
Definition iparith.cc:9365
iiExprArithM
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
Definition iparith.cc:9666
iiExprArith3
BOOLEAN iiExprArith3(leftv res, int op, leftv a, leftv b, leftv c)
Definition iparith.cc:9575
jjLIST_PL
BOOLEAN jjLIST_PL(leftv res, leftv v)
Definition iparith.cc:8250
iiAssign
BOOLEAN iiAssign(leftv l, leftv r, BOOLEAN toplevel)
Definition ipassign.cc:2099
basePack
VAR package basePack
Definition ipid.cc:56
currPack
VAR package currPack
Definition ipid.cc:55
ipid.h
IDDATA
#define IDDATA(a)
Definition ipid.h:126
IDROOT
#define IDROOT
Definition ipid.h:19
rKill
void rKill(ring r)
Definition ipshell.cc:6181
ipshell.h
next
ListNode * next
Definition janet.h:31
mod2.h
assume
#define assume(x)
Definition mod2.h:389
newstruct_desc_size
int newstruct_desc_size()
Definition newstruct.cc:42
newstruct.h
omStrDup
#define omStrDup(s)
Definition omAllocDecl.h:263
omAlloc0
#define omAlloc0(size)
Definition omAllocDecl.h:211
NULL
#define NULL
Definition omList.c:12
currRing
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
PrintS
void PrintS(const char *s)
Definition reporter.cc:288
idhdl
idrec * idhdl
Definition ring.h:22
si_link
ip_link * si_link
Definition silink.h:20
leftv
sleftv * leftv
Definition structs.h:53
IDHDL
#define IDHDL
Definition tok.h:31
LIST_CMD
@ LIST_CMD
Definition tok.h:118
DEF_CMD
@ DEF_CMD
Definition tok.h:58
LINK_CMD
@ LINK_CMD
Definition tok.h:117
TYPEOF_CMD
@ TYPEOF_CMD
Definition tok.h:196
STRING_CMD
@ STRING_CMD
Definition tok.h:187
INT_CMD
@ INT_CMD
Definition tok.h:96
SYSTEM_CMD
@ SYSTEM_CMD
Definition tok.h:189
MAX_TOK
@ MAX_TOK
Definition tok.h:220
NONE
#define NONE
Definition tok.h:223