My Project
Loading...
Searching...
No Matches
countedref.cc
Go to the documentation of this file.
1// -*- c++ -*-
2//*****************************************************************************
3/** @file countedref.cc
4 *
5 * @author Alexander Dreyer
6 * @date 2012-08-15
7 *
8 * This file defines reference countes interpreter objects and adds the
9 * @c blackbox operations for high-level types 'reference' and 'shared'.
10 *
11 * @note This works was supported by the "Industrial Algebra" project.
12 *
13 * @par Copyright:
14 * (c) 2012 by The Singular Team, see LICENSE file
15**/
16//*****************************************************************************
17
18
19
20
21
22#include "kernel/mod2.h"
23
24#include "ipid.h"
25
26#include "countedref.h"
27
28#include "blackbox.h"
29#include "newstruct.h"
30#include "ipshell.h"
31
32
33/// Overloading ring destruction
34inline void CountedRefPtr_kill(ring r) { rKill(r); }
35
36
37/** @class CountedRefData
38 * This class stores a reference counter as well as a Singular interpreter object.
39 * It also take care of the context, e.g. the current ring, wrap object, etc.
40 **/
42 public RefCounter {
44public:
46private:
48
49 /// Generate object linked to other reference (e.g. for subscripts)
51 base(), m_data(wrapid), m_ring(back->m_ring), m_back(back) {
52 }
53
54 /// @name Disallow copying to avoid inconsistence
55 //@{
58 //@}
59
60public:
62
63 /// Fix smart pointer type to referenced data
65
66 /// Fix smart pointer type to ring
68
69 /// Construct shared memory empty Singular object
70 explicit CountedRefData():
71 base(), m_data(), m_ring(), m_back() { }
72
73 /// Reference Singular object
74 explicit CountedRefData(leftv data):
75 base(), m_data(data), m_ring(parent(data)), m_back() { }
76
77 /// Construct reference for Singular object
79 base(), m_data(data, do_copy), m_ring(parent(data)), m_back() { }
80
81 /// Destruct
83 if (!m_back.unassigned()) {
84 if (m_back == this)
86 else
88 }
89 }
90
91 /// Generate object for indexing
92 ptr_type wrapid() { return new self(m_data.idify(root()), weakref()); }
93
94 /// Gerenate weak (but managed) reference to @c *this
96 if (m_back.unassigned())
97 m_back = this;
98 return m_back;
99 }
100 /// Replace with other Singular data
102 m_data = rhs;
103 m_ring = parent(rhs);
104 return *this;
105 }
106
107 /// Write (shallow) copy to given handle
108 BOOLEAN put(leftv res) { return broken() || m_data.put(res); }
109
110 /// Extract (shallow) copy of stored data
111 LeftvShallow operator*() const { return (broken()? LeftvShallow(): (const LeftvShallow&)m_data); }
112
113 /// Determine active ring when ring dependency changes
116 return (m_back && (m_back != this) && m_back->rering());
117 }
118
119 /// Get the current context
120 idhdl* root() { return (m_ring? &m_ring->idroot: &IDROOT); }
121
122 /// Check whether identifier became invalid
123 BOOLEAN broken() const {
124 if (!m_back.unassigned() && !m_back)
125 return complain("Back-reference broken");
126
127 if (m_ring) {
128 if (m_ring != currRing)
129 return complain("Referenced identifier not from current ring");
130
131 return m_data.isid() && m_data.brokenid(currRing->idroot) &&
132 complain("Referenced identifier not available in ring anymore");
133 }
134
135 if (!m_data.isid()) return FALSE;
136 return m_data.brokenid(IDROOT) &&
137 ((currPack == basePack) || m_data.brokenid(basePack->idroot)) &&
138 complain("Referenced identifier not available in current context");
139 }
140
141 /// Reassign actual object
143
144 if (!m_data.isid()) {
145 (*this) = arg;
146 return FALSE;
147 }
148 return put(result) || iiAssign(result, arg) || rering();
149 }
150 /// Recover additional information (e.g. subexpression) from likewise object
152
153 /// Check whether data is all-zero
154 BOOLEAN unassigned() const { return m_data.unassigned(); }
155
156private:
157 /// Raise error message and return @c TRUE
158 BOOLEAN complain(const char* text) const
159 {
160 WerrorS(text);
161 return TRUE;
162 }
163
164 /// Store ring for ring-dependent objects
165 static ring parent(leftv rhs)
166 {
167 return (rhs->RingDependend()? currRing: NULL);
168 }
169
170protected:
171 /// Singular object
173
174 /// Store namespace for ring-dependent objects
176
177 /// Reference to actual object for wrap structures
179};
180
181/// Supporting smart pointer @c CountedRefPtr
182inline void CountedRefPtr_kill(CountedRefData* data) { delete data; }
183
184
185/// blackbox support - initialization
186void* countedref_Init(blackbox*)
187{
188 return NULL;
189}
190
191/// We use the function pointer as a marker of reference types
192/// for CountedRef::is_ref(leftv), see the latter for details
193BOOLEAN countedref_CheckAssign(blackbox */*b*/, leftv /*L*/, leftv /*R*/)
194{
195 return FALSE;
196}
197
198
201
202public:
203 /// name type for identifiers
204 typedef int id_type;
205
206 /// Name type for handling referenced data
208
209 /// Fix smart pointer type to referenced data
211
212 /// Check whether argument is already a reference type
213 /// @note We check for the function pointer @c countedref_CheckAssign here,
214 /// that we (ab-)use as a unique marker. This avoids to check a bunch of
215 /// of runtime-varying @c typ IDs for identifying reference-like types.
216 static BOOLEAN is_ref(leftv arg) {
217 int typ = arg->Typ();
218 return ((typ > MAX_TOK) &&
219 (getBlackboxStuff(typ)->blackbox_CheckAssign == countedref_CheckAssign));
220 }
221
222 /// Reference given Singular data
223 explicit CountedRef(leftv arg): m_data(new data_type(arg)) { }
224
225protected:
226 /// Recover previously constructed reference
227 CountedRef(data_ptr arg): m_data(arg) { assume(arg); }
228
229public:
230 /// Construct copy
231 CountedRef(const self& rhs): m_data(rhs.m_data) { }
232
233 /// Replace reference
234 self& operator=(const self& rhs) {
235 m_data = rhs.m_data;
236 return *this;
237 }
238
240 return m_data->assign(result,arg);
241 }
242
243 /// Extract (shallow) copy of stored data
244 LeftvShallow operator*() { return m_data->operator*(); }
245
246 /// Construct reference data object marked by given identifier number
248 res->rtyp = typ;
249 return outcast(res);
250 }
251
252 /// Construct reference data object from *this
254 if (res->rtyp == IDHDL)
255 IDDATA((idhdl)res->data) = (char *)outcast();
256 else
257 res->data = (void *)outcast();
258 return FALSE;
259 }
260
261 /// Construct raw reference data
263 m_data.reclaim();
264 return m_data;
265 }
266
267 /// Kills a link to the referenced object
268 void destruct() { m_data.release(); }
269
270 /// Kills the link to the referenced object
272
273 /// Replaces argument by a shallow copy of the references data
275 m_data.reclaim();
276 BOOLEAN b= m_data->put(arg) || ((arg->next != NULL) && resolve(arg->next));
277 m_data.release();
278 return b;
279 }
280
281 /// Check whether object in valid in current context
282 BOOLEAN broken() {return m_data->broken(); }
283
284 /// Check whether (shared) data was initialized but not assigned yet.
285 BOOLEAN unassigned() const { return m_data->unassigned(); }
286
287 /// Get number of references pointing here, too
289
290 // Get internal indentifier
292
293 /// Check for likewise identifiers
295 return resolve(arg) || construct(res, operator*()->data == arg->data);
296 }
297
298 /// Check for identical reference objects
300 return construct(res, m_data == arg->Data());
301 }
302
303 /// Get type of references data
305 return construct(res, Tok2Cmdname(operator*()->Typ()));
306 };
307
308 /// Get (possibly) internal identifier name
309 BOOLEAN name(leftv res) { return construct(res, operator*()->Name()); }
310
311 /// Recover the actual object from raw Singular data
312 static self cast(void* data) {
313 assume(data != NULL);
314 return self(static_cast<data_type*>(data));
315 }
316
317 /// Recover the actual object from Singular interpreter object
318 static self cast(leftv arg) {
319 assume(arg != NULL); assume(is_ref(arg));
320 auto d = arg->Data();
321 return self::cast(d);
322 }
323
324 /// If necessary dereference.
325 static BOOLEAN resolve(leftv arg) {
326 assume(arg != NULL);
327 while (is_ref(arg)) {
328 CountedRef ref = CountedRef::cast(arg);
329 if (ref.dereference(arg)) return TRUE;
330 }
331 return (arg->next != NULL) && resolve(arg->next);
332 }
333
334 /// Construct integer value
335 static BOOLEAN construct(leftv res, long data) {
336 res->data = (void*) data;
337 res->rtyp = INT_CMD;
338 return FALSE;
339 }
340
341 /// Construct string
342 static BOOLEAN construct(leftv res, const char* data) {
343 res->data = (void*)omStrDup(data);
344 res->rtyp = STRING_CMD;
345 return FALSE;
346 }
347 /// Construct void-style object
349 res->data = NULL;
350 res->rtyp = NONE;
351 return FALSE;
352 }
353
354protected:
355 /// Store pointer to actual data
357};
358
359/// blackbox support - convert to string representation
360void countedref_Print(blackbox */*b*/, void* ptr)
361{
362 if (ptr) (*CountedRef::cast(ptr))->Print();
363 else PrintS("<unassigned reference or shared memory>");
364}
365
366/// blackbox support - convert to string representation
367char* countedref_String(blackbox */*b*/, void* ptr)
368{
369 if (ptr == NULL) return omStrDup(sNoName_fe);
370 return (*CountedRef::cast(ptr))->String();
371}
372
373/// blackbox support - copy element
374void* countedref_Copy(blackbox*/*b*/, void* ptr)
375{
376 if (!ptr) return NULL;
377 CountedRef ref = CountedRef::cast(ptr);
378 return ref.outcast();
379}
380
381/// blackbox support - assign element
383{
384 // Case: replace assignment behind reference
385 if (result->Data() != NULL) {
387 return CountedRef::resolve(arg) || ref.assign(result, arg);
388 }
389
390 // Case: copy reference
391 if (result->Typ() == arg->Typ()) {
392 CountedRef ref = CountedRef::cast(arg);
393 return ref.outcast(result);
394 }
395
396 // Case: new reference
397 if ((arg->rtyp == IDHDL) || CountedRef::is_ref(arg)) {
398 CountedRef ref(arg);
399 return ref.outcast(result);
400 }
401
402 WerrorS("Can only take reference from identifier");
403 return TRUE;
404}
405
407{
408 if (arg->Data() != NULL) return FALSE;
409 res->rtyp = NONE;
410 WerrorS("Noninitialized access");
411 return TRUE;
412}
413
414/// blackbox support - unary operations
416{
417 if(op == TYPEOF_CMD)
418 return blackboxDefaultOp1(op, res, head);
419
420 if (countedref_CheckInit(res, head)) return TRUE;
421
422 if ((op == DEF_CMD) || (op == head->Typ()))
423 {
424 res->rtyp = head->Typ();
425 return iiAssign(res, head);
426 }
427
429 return ref.dereference(head) ||
430 iiExprArith1(res, head, op == LINK_CMD? head->Typ(): op);
431}
432
433
434
435/// blackbox support - binary operations (resolve seocnd argument)
437{
438 if (CountedRef::is_ref(arg))
439 {
440 CountedRef ref = CountedRef::cast(arg);
441 return ref.dereference(arg) || iiExprArith2(res, head, op, arg);
442 }
443 return iiExprArith2(res, head, op, arg);
444}
445
447{
448 if (countedref_CheckInit(res, head)) return TRUE;
450 {
452 return ref.dereference(head) || countedref_Op2_(op, res, head, arg);
453 }
454 return countedref_Op2_(op, res, head, arg);
455}
456
457static BOOLEAN countedref_Op3__(int op, leftv res, leftv head, leftv arg1, leftv arg2)
458{
459
460 if (CountedRef::is_ref(arg2))
461 {
462 CountedRef ref = CountedRef::cast(arg2);
463 return ref.dereference(arg2) || iiExprArith3(res, op, head, arg1, arg2);
464 }
465 return iiExprArith3(res, op, head, arg1, arg2);
466}
467
468static BOOLEAN countedref_Op3_(int op, leftv res, leftv head, leftv arg1, leftv arg2)
469{
470 if (CountedRef::is_ref(arg1))
471 {
472 CountedRef ref = CountedRef::cast(arg1);
473 return ref.dereference(arg1) || countedref_Op3__(op, res, head, arg1, arg2);
474 }
475 return countedref_Op3__(op, res, head, arg1, arg2);
476}
477
478
479/// blackbox support - ternary operations
481{
482 if (countedref_CheckInit(res, head)) return TRUE;
484 {
486 return ref.dereference(head) || countedref_Op3_(op, res, head, arg1, arg2);
487 }
488 return countedref_Op3_(op, res, head, arg1, arg2);
489}
490
491
492/// blackbox support - destruction
493void countedref_destroy(blackbox */*b*/, void* ptr)
494{
495 if (ptr) {
496 CountedRef ref = CountedRef::cast(ptr);
497 ref.destruct();
498 }
499}
500
501
503 public CountedRef
504 {
507
508 /// Reinterprete @c CountedRef as @c CountedRefShared
509 CountedRefShared(const base& rhs): base(rhs) { }
510
511 /// Generate from data pointer
513
514public:
515 /// Default constructor for initialized, but all-zero, shared data object
517
518 /// Construct internal copy of Singular interpreter object
519 explicit CountedRefShared(leftv arg): base(new data_type(arg, data_type::copy_tag())) { }
520
521 /// Construct new reference to internal data
522 CountedRefShared(const self& rhs): base(rhs) { }
523
524 /// Desctruct
526
527 /// Change reference to shared data
528 self& operator=(const self& rhs) {
529 return static_cast<self&>(base::operator=(rhs));
530 }
531
532 /// Recovering outcasted @c CountedRefShared object from interpreter object
533 static self cast(leftv arg) { return base::cast(arg); }
534
535 /// Recovering outcasted @c CountedRefShared object from raw data
536 static self cast(void* arg) { return base::cast(arg); }
537
538 /// Temporarily wrap with identifier for '[' and '.' operation
539 self wrapid() { return self(m_data->wrapid()); }
540
541 /// Generate weak reference (may get invalid)
543
544 /// Recover more information (e.g. subexpression data) from computed result
546 {
547 return (m_data->retrieve(res) && outcast(res, typ));
548 }
549};
550
551/// Blackbox support - generate initialized, but all-zero - shared data
552void* countedref_InitShared(blackbox*)
553{
554 auto ref = CountedRefShared();
555 return ref.outcast();
556}
557
558/// Blackbox support - unary operation for shared data
560{
561 if(op == TYPEOF_CMD)
562 return blackboxDefaultOp1(op, res, head);
563
564 if (countedref_CheckInit(res, head)) return TRUE;
565
566 if ((op == DEF_CMD) || (op == head->Typ()))
567 {
568 res->rtyp = head->Typ();
569 return iiAssign(res, head);
570 }
571
573
574 if (op == LINK_CMD)
575 {
576 if (ref.dereference(head)) return TRUE;
577 res->Copy(head);
578 return (res->Typ() == NONE);
579 }
580
581 CountedRefShared wrap = ref.wrapid();
582 int typ = head->Typ();
583 return wrap.dereference(head) || iiExprArith1(res, head, op) ||
584 wrap.retrieve(res, typ);
585}
586
587
588/// blackbox support - binary operations
590{
591 if (countedref_CheckInit(res, head)) return TRUE;
592
594 {
596 int typ = head->Typ();
597 return wrap.dereference(head) || countedref_Op2_(op, res, head, arg) ||
598 wrap.retrieve(res, typ);
599 }
600
601 return countedref_Op2_(op, res, head, arg);
602}
603
604/// blackbox support - n-ary operations
606{
607 if (args->Data() == NULL) return FALSE;
608
609 if(op == SYSTEM_CMD)
610 {
611 if (args->next)
612 {
613 leftv next = args->next;
614 args->next = NULL;
615
616 char* name = (next->Typ() == STRING_CMD?
617 (char*) next->Data(): (char*)next->Name());
618 next = next->next;
619
620 if (strcmp(name, "help") == 0)
621 {
622 PrintS("system(<ref>, ...): extended functionality for reference/shared data <ref>\n");
623 PrintS(" system(<ref>, count) - number of references pointing to <ref>\n");
624 PrintS(" system(<ref>, enumerate) - unique number for identifying <ref>\n");
625 PrintS(" system(<ref>, undefined) - checks whether <ref> had been assigned\n");
626 PrintS(" system(<ref>, \"help\") - prints this information message\n");
627 PrintS(" system(<ref>, \"typeof\") - actual type referenced by <ref>\n");
628 PrintS(" system(<ref1>, same, <ref2>) - tests for identic reference objects\n");
630 }
631 if (strncmp(name, "undef", 5) == 0)
632 {
633 return CountedRef::construct(res, args->Data()?
634 (CountedRef::cast(args).unassigned()? 1: 2): 0);
635 }
636
637 CountedRef obj = CountedRef::cast(args);
638 if (next)
639 {
640 if (strcmp(name, "same") == 0) return obj.same(res, next);
641 // likewise may be hard to interprete, so we not not document it above
642 if (strncmp(name, "like", 4) == 0) return obj.likewise(res, next);
643 }
644 if (strncmp(name, "count", 5) == 0) return obj.count(res);
645 if (strncmp(name, "enum", 4) == 0) return obj.enumerate(res);
646 if (strcmp(name, "name") == 0) return obj.name(res); // undecumented
647 if (strncmp(name, "typ", 3) == 0) return obj.type(res);
648 }
649 return TRUE;
650 }
651 if (op == LIST_CMD)
652 {
653 res->rtyp = op;
654 return jjLIST_PL(res, args);
655 }
656 CountedRef ref = CountedRef::cast(args);
657 return ref.dereference(args) || iiExprArithM(res, args, op);
658}
659
660/// blackbox support - assign element
662{
663 /// Case: replace assignment behind reference
664 if ((result->Data() != NULL) && !CountedRefShared::cast(result).unassigned()) {
666 return CountedRef::resolve(arg) || ref.assign(result, arg);
667 }
668
669 /// Case: new reference to already shared data
670 if (result->Typ() == arg->Typ())
671 {
672 if (result->Data() != NULL) {
674 ref.destruct();
675 }
677 return ref.outcast(result);
678 }
679 if(CountedRefShared::cast(result).unassigned())
680 {
682 return ref.assign(result, arg);
683 }
684
685 /// Case: new shared data
686 CountedRefShared ref(arg);
687 return ref.outcast(result);
688}
689
690/// blackbox support - destruction
691void countedref_destroyShared(blackbox */*b*/, void* ptr)
692{
693 if (ptr) {
695 ref.destruct();
696 }
697}
698
699
700BOOLEAN countedref_serialize(blackbox */*b*/, void *d, si_link f)
701{
702 sleftv l;
703 memset(&l,0,sizeof(l));
704 l.rtyp = STRING_CMD;
705 l.data = (void*)omStrDup("shared"); // references are converted
706 f->m->Write(f, &l);
708 f->m->Write(f, &l);
709 return FALSE;
710}
711
712BOOLEAN countedref_deserialize(blackbox **/*b*/, void **d, si_link f)
713{
714 // rtyp must be set correctly (to the blackbox id) by routine calling
715 leftv data=f->m->Read(f);
716 CountedRefShared sh(data);
717 *d = sh.outcast();
718 return FALSE;
719}
720
722{
723 int tok;
724 if (blackboxIsCmd("reference", tok) == ROOT_DECL)
725 return;
726
727 blackbox *bbx = (blackbox*)omAlloc0(sizeof(blackbox));
728 bbx->blackbox_CheckAssign = countedref_CheckAssign;
729 bbx->blackbox_destroy = countedref_destroy;
730 bbx->blackbox_String = countedref_String;
731 bbx->blackbox_Print = countedref_Print;
732 bbx->blackbox_Init = countedref_Init;
733 bbx->blackbox_Copy = countedref_Copy;
734 bbx->blackbox_Assign = countedref_Assign;
735 bbx->blackbox_Op1 = countedref_Op1;
736 bbx->blackbox_Op2 = countedref_Op2;
737 bbx->blackbox_Op3 = countedref_Op3;
738 bbx->blackbox_OpM = countedref_OpM;
739 bbx->blackbox_serialize = countedref_serialize;
740 bbx->blackbox_deserialize = countedref_deserialize;
741 bbx->data = omAlloc0(newstruct_desc_size());
742 setBlackboxStuff(bbx, "reference");
743}
744
746{
747 int tok;
748 if (blackboxIsCmd("shared", tok) == ROOT_DECL)
749 return;
750
751 blackbox *bbxshared = (blackbox*)omAlloc0(sizeof(blackbox));
752 bbxshared->blackbox_String = countedref_String;
753 bbxshared->blackbox_Print = countedref_Print;
754 bbxshared->blackbox_Copy = countedref_Copy;
755 bbxshared->blackbox_Op3 = countedref_Op3;
756 bbxshared->blackbox_OpM = countedref_OpM;
757 bbxshared->blackbox_serialize = countedref_serialize;
758 bbxshared->blackbox_deserialize = countedref_deserialize;
759
760 bbxshared->blackbox_CheckAssign = countedref_CheckAssign;
761 bbxshared->blackbox_Assign = countedref_AssignShared;
762 bbxshared->blackbox_destroy = countedref_destroyShared;
763 bbxshared->blackbox_Op1 = countedref_Op1Shared;
764 bbxshared->blackbox_Op2 = countedref_Op2Shared;
765 bbxshared->blackbox_Init = countedref_InitShared;
766 bbxshared->data = omAlloc0(newstruct_desc_size());
767 setBlackboxStuff(bbxshared, "shared");
768}
769
770
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
int setBlackboxStuff(blackbox *bb, const char *n)
define a new type
Definition: blackbox.cc:142
blackbox * getBlackboxStuff(const int t)
return the structure to the type given by t
Definition: blackbox.cc:17
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:218
BOOLEAN blackboxDefaultOp1(int op, leftv l, leftv r)
default procedure blackboxDefaultOp1, to be called as "default:" branch
Definition: blackbox.cc:78
CanonicalForm head(const CanonicalForm &f)
int l
Definition: cfEzgcd.cc:100
CanonicalForm b
Definition: cfModGcd.cc:4102
FILE * f
Definition: checklibs.c:9
This class stores a reference counter as well as a Singular interpreter object.
Definition: countedref.cc:42
LeftvDeep::copy_tag copy_tag
Fix smart pointer type to referenced data.
Definition: countedref.cc:61
LeftvShallow operator*() const
Extract (shallow) copy of stored data.
Definition: countedref.cc:111
CountedRefWeakPtr< self * > back_ptr
Definition: countedref.cc:45
ring_ptr m_ring
Store namespace for ring-dependent objects.
Definition: countedref.cc:175
self & operator=(leftv rhs)
Replace with other Singular data.
Definition: countedref.cc:101
static ring parent(leftv rhs)
Store ring for ring-dependent objects.
Definition: countedref.cc:165
BOOLEAN broken() const
Check whether identifier became invalid.
Definition: countedref.cc:123
~CountedRefData()
Destruct.
Definition: countedref.cc:82
LeftvDeep m_data
Singular object.
Definition: countedref.cc:172
CountedRefData(const self &)
Fix smart pointer type to referenced data.
back_ptr::ptr_type ptr_type
Fix smart pointer type to referenced data.
Definition: countedref.cc:64
idhdl * root()
Get the current context.
Definition: countedref.cc:120
CountedRefData(leftv data)
Reference Singular object.
Definition: countedref.cc:74
CountedRefData(leftv wrapid, back_ptr back)
Generate object linked to other reference (e.g. for subscripts)
Definition: countedref.cc:50
CountedRefData()
Construct shared memory empty Singular object.
Definition: countedref.cc:70
RefCounter base
Definition: countedref.cc:47
back_ptr m_back
Reference to actual object for wrap structures.
Definition: countedref.cc:178
CountedRefPtr< ring, true > ring_ptr
Fix smart pointer type to ring.
Definition: countedref.cc:67
BOOLEAN complain(const char *text) const
Raise error message and return TRUE.
Definition: countedref.cc:158
BOOLEAN rering()
Determine active ring when ring dependency changes.
Definition: countedref.cc:114
BOOLEAN retrieve(leftv res)
Recover additional information (e.g. subexpression) from likewise object.
Definition: countedref.cc:151
CountedRefData self
Definition: countedref.cc:43
BOOLEAN put(leftv res)
Write (shallow) copy to given handle.
Definition: countedref.cc:108
self & operator=(const self &)
Fix smart pointer type to referenced data.
back_ptr weakref()
Gerenate weak (but managed) reference to *this.
Definition: countedref.cc:95
BOOLEAN unassigned() const
Check whether data is all-zero.
Definition: countedref.cc:154
BOOLEAN assign(leftv result, leftv arg)
Reassign actual object.
Definition: countedref.cc:142
CountedRefData(leftv data, copy_tag do_copy)
Construct reference for Singular object.
Definition: countedref.cc:78
ptr_type wrapid()
Generate object for indexing.
Definition: countedref.cc:92
This class implements a smart pointer which handles pointer-style access to a reference-counted struc...
Definition: countedref.h:43
count_type count() const
Store actual pointer.
Definition: countedref.h:95
void release()
Store actual pointer.
Definition: countedref.h:97
void reclaim()
Store actual pointer.
Definition: countedref.h:96
~CountedRefShared()
Desctruct.
Definition: countedref.cc:525
BOOLEAN retrieve(leftv res, int typ)
Recover more information (e.g. subexpression data) from computed result.
Definition: countedref.cc:545
data_type::back_ptr weakref()
Generate weak reference (may get invalid)
Definition: countedref.cc:542
CountedRefShared(data_ptr rhs)
Generate from data pointer.
Definition: countedref.cc:512
CountedRefShared(leftv arg)
Construct internal copy of Singular interpreter object.
Definition: countedref.cc:519
self & operator=(const self &rhs)
Change reference to shared data.
Definition: countedref.cc:528
CountedRefShared()
Default constructor for initialized, but all-zero, shared data object.
Definition: countedref.cc:516
CountedRef base
Definition: countedref.cc:506
CountedRefShared(const self &rhs)
Construct new reference to internal data.
Definition: countedref.cc:522
static self cast(leftv arg)
Recovering outcasted CountedRefShared object from interpreter object.
Definition: countedref.cc:533
static self cast(void *arg)
Recovering outcasted CountedRefShared object from raw data.
Definition: countedref.cc:536
CountedRefShared self
Definition: countedref.cc:505
self wrapid()
Temporarily wrap with identifier for '[' and '.' operation.
Definition: countedref.cc:539
CountedRefShared(const base &rhs)
Reinterprete CountedRef as CountedRefShared.
Definition: countedref.cc:509
bool unassigned() const
Test whether reference was never used.
Definition: countedref.h:181
void invalidate()
Mark weak reference as invalid.
Definition: countedref.h:178
BOOLEAN type(leftv res)
Get type of references data.
Definition: countedref.cc:304
static BOOLEAN resolve(leftv arg)
If necessary dereference.
Definition: countedref.cc:325
BOOLEAN dereference(leftv arg)
Replaces argument by a shallow copy of the references data.
Definition: countedref.cc:274
BOOLEAN unassigned() const
Check whether (shared) data was initialized but not assigned yet.
Definition: countedref.cc:285
LeftvShallow operator*()
Extract (shallow) copy of stored data.
Definition: countedref.cc:244
static self cast(leftv arg)
Recover the actual object from Singular interpreter object.
Definition: countedref.cc:318
BOOLEAN outcast(leftv res, int typ)
Construct reference data object marked by given identifier number.
Definition: countedref.cc:247
BOOLEAN likewise(leftv res, leftv arg)
Check for likewise identifiers.
Definition: countedref.cc:294
BOOLEAN broken()
Check whether object in valid in current context.
Definition: countedref.cc:282
int id_type
name type for identifiers
Definition: countedref.cc:204
CountedRef(const self &rhs)
Construct copy.
Definition: countedref.cc:231
BOOLEAN enumerate(leftv res)
Definition: countedref.cc:291
BOOLEAN outcast(leftv res)
Construct reference data object from *this.
Definition: countedref.cc:253
BOOLEAN assign(leftv result, leftv arg)
Definition: countedref.cc:239
~CountedRef()
Kills the link to the referenced object.
Definition: countedref.cc:271
self & operator=(const self &rhs)
Replace reference.
Definition: countedref.cc:234
void destruct()
Kills a link to the referenced object.
Definition: countedref.cc:268
static BOOLEAN construct(leftv res, const char *data)
Construct string.
Definition: countedref.cc:342
CountedRef(leftv arg)
Reference given Singular data.
Definition: countedref.cc:223
data_ptr m_data
Store pointer to actual data.
Definition: countedref.cc:356
BOOLEAN same(leftv res, leftv arg)
Check for identical reference objects.
Definition: countedref.cc:299
static BOOLEAN construct(leftv res, long data)
Construct integer value.
Definition: countedref.cc:335
data_type * outcast()
Construct raw reference data.
Definition: countedref.cc:262
CountedRefPtr< CountedRefData * > data_ptr
Fix smart pointer type to referenced data.
Definition: countedref.cc:210
CountedRef(data_ptr arg)
Recover previously constructed reference.
Definition: countedref.cc:227
static BOOLEAN is_ref(leftv arg)
Check whether argument is already a reference type.
Definition: countedref.cc:216
CountedRefData data_type
Name type for handling referenced data.
Definition: countedref.cc:207
BOOLEAN name(leftv res)
Get (possibly) internal identifier name.
Definition: countedref.cc:309
CountedRef self
Definition: countedref.cc:200
static BOOLEAN construct(leftv res)
Construct void-style object.
Definition: countedref.cc:348
static self cast(void *data)
Recover the actual object from raw Singular data.
Definition: countedref.cc:312
BOOLEAN count(leftv res)
Get number of references pointing here, too.
Definition: countedref.cc:288
This class wraps leftv by taking into acount memory allocation, destruction as well as deeply copying...
Definition: countedref.h:335
void clearid(idhdl *root)
Erase identifier handles by *this.
Definition: countedref.h:442
BOOLEAN isid() const
Check for being an identifier.
Definition: countedref.h:426
BOOLEAN ringed()
Test whether we reference to ring-dependent data.
Definition: countedref.h:428
BOOLEAN brokenid(idhdl context) const
Check a given context for our identifier.
Definition: countedref.h:389
BOOLEAN unassigned() const
Check whether (all-zero) initialized data was never assigned.
Definition: countedref.h:430
BOOLEAN retrieve(leftv res)
Get additional data (e.g. subexpression data) from likewise instances.
Definition: countedref.h:414
leftv idify(idhdl *root)
Wrap data by identifier, if not done yet.
Definition: countedref.h:433
BOOLEAN put(leftv result)
Put a shallow copy to given leftv.
Definition: countedref.h:396
Construct even deeper copy: Skip identifier (if any) and take care of the data on our own.
Definition: countedref.h:357
Ths class wraps leftv by taking into acount memory allocation, destruction as well as shallowly copyi...
Definition: countedref.h:285
This class implements implements a refernce counter which we can use as a public base of objects mana...
Definition: countedref.h:112
Definition: idrec.h:35
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
int Typ()
Definition: subexpr.cc:1011
int rtyp
Definition: subexpr.h:91
void * Data()
Definition: subexpr.cc:1154
BOOLEAN RingDependend()
Definition: subexpr.cc:418
leftv next
Definition: subexpr.h:86
void * data
Definition: subexpr.h:88
void CountedRefPtr_kill(ring r)
Overloading ring destruction.
Definition: countedref.cc:34
char * countedref_String(blackbox *, void *ptr)
blackbox support - convert to string representation
Definition: countedref.cc:367
BOOLEAN countedref_CheckInit(leftv res, leftv arg)
Definition: countedref.cc:406
BOOLEAN countedref_Op2Shared(int op, leftv res, leftv head, leftv arg)
blackbox support - binary operations
Definition: countedref.cc:589
BOOLEAN countedref_serialize(blackbox *, void *d, si_link f)
Definition: countedref.cc:700
void countedref_destroyShared(blackbox *, void *ptr)
blackbox support - destruction
Definition: countedref.cc:691
void countedref_Print(blackbox *, void *ptr)
blackbox support - convert to string representation
Definition: countedref.cc:360
BOOLEAN countedref_deserialize(blackbox **, void **d, si_link f)
Definition: countedref.cc:712
void * countedref_InitShared(blackbox *)
Blackbox support - generate initialized, but all-zero - shared data.
Definition: countedref.cc:552
static BOOLEAN countedref_Op2_(int op, leftv res, leftv head, leftv arg)
blackbox support - binary operations (resolve seocnd argument)
Definition: countedref.cc:436
BOOLEAN countedref_AssignShared(leftv result, leftv arg)
blackbox support - assign element
Definition: countedref.cc:661
BOOLEAN countedref_OpM(int op, leftv res, leftv args)
blackbox support - n-ary operations
Definition: countedref.cc:605
BOOLEAN countedref_Op3(int op, leftv res, leftv head, leftv arg1, leftv arg2)
blackbox support - ternary operations
Definition: countedref.cc:480
static BOOLEAN countedref_Op3__(int op, leftv res, leftv head, leftv arg1, leftv arg2)
Definition: countedref.cc:457
BOOLEAN countedref_Assign(leftv result, leftv arg)
blackbox support - assign element
Definition: countedref.cc:382
BOOLEAN countedref_Op2(int op, leftv res, leftv head, leftv arg)
Definition: countedref.cc:446
void * countedref_Init(blackbox *)
blackbox support - initialization
Definition: countedref.cc:186
void countedref_destroy(blackbox *, void *ptr)
blackbox support - destruction
Definition: countedref.cc:493
BOOLEAN countedref_Op1Shared(int op, leftv res, leftv head)
Blackbox support - unary operation for shared data.
Definition: countedref.cc:559
static BOOLEAN countedref_Op3_(int op, leftv res, leftv head, leftv arg1, leftv arg2)
Definition: countedref.cc:468
void countedref_reference_load()
Initialize blackbox types 'reference' and 'shared', or both.
Definition: countedref.cc:721
BOOLEAN countedref_Op1(int op, leftv res, leftv head)
blackbox support - unary operations
Definition: countedref.cc:415
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
void countedref_shared_load()
Definition: countedref.cc:745
void * countedref_Copy(blackbox *, void *ptr)
blackbox support - copy element
Definition: countedref.cc:374
This file defines reusable classes supporting reference counted interpreter objects and initiates the...
#define Print
Definition: emacs.cc:80
return result
Definition: facAbsBiFact.cc:75
CanonicalForm res
Definition: facAbsFact.cc:60
char name(const Variable &v)
Definition: factory.h:189
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char sNoName_fe[]
Definition: fevoices.cc:57
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:140
@ ROOT_DECL
Definition: grammar.cc:319
BOOLEAN iiExprArith2(leftv res, leftv a, int op, leftv b, BOOLEAN proccall)
Definition: iparith.cc:8902
BOOLEAN iiExprArith1(leftv res, leftv a, int op)
Definition: iparith.cc:9091
BOOLEAN iiExprArithM(leftv res, leftv a, int op)
Definition: iparith.cc:9392
BOOLEAN iiExprArith3(leftv res, int op, leftv a, leftv b, leftv c)
Definition: iparith.cc:9301
BOOLEAN jjLIST_PL(leftv res, leftv v)
Definition: iparith.cc:7976
BOOLEAN iiAssign(leftv l, leftv r, BOOLEAN toplevel)
Definition: ipassign.cc:1963
VAR package basePack
Definition: ipid.cc:58
VAR package currPack
Definition: ipid.cc:57
#define IDDATA(a)
Definition: ipid.h:126
#define IDROOT
Definition: ipid.h:19
void rKill(ring r)
Definition: ipshell.cc:6170
ListNode * next
Definition: janet.h:31
#define assume(x)
Definition: mod2.h:389
int newstruct_desc_size()
Definition: newstruct.cc:42
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define NULL
Definition: omList.c:12
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
void PrintS(const char *s)
Definition: reporter.cc:284
#define IDHDL
Definition: tok.h:31
@ LIST_CMD
Definition: tok.h:118
@ DEF_CMD
Definition: tok.h:58
@ LINK_CMD
Definition: tok.h:117
@ TYPEOF_CMD
Definition: tok.h:194
@ STRING_CMD
Definition: tok.h:185
@ INT_CMD
Definition: tok.h:96
@ SYSTEM_CMD
Definition: tok.h:187
@ MAX_TOK
Definition: tok.h:218
#define NONE
Definition: tok.h:221