Changeset 88180d in git
- Timestamp:
- Sep 4, 2012, 11:35:14 PM (12 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- d94836e0b38201eda7edf1d2094a7376a0090806
- Parents:
- cda275f5c6745c233d1ee5261720c388c5286ec9
- git-author:
- Alexander Dreyer <alexander.dreyer@itwm.fraunhofer.de>2012-09-04 23:35:14+02:00
- git-committer:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-09-05 15:52:17+02:00
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/countedref.cc
rcda275f r88180d 48 48 /** @class CountedRefData 49 49 * This class stores a reference counter as well as a Singular interpreter object. 50 * It also take care of the context, e.g. the current ring, indexedobject, etc.50 * It also take care of the context, e.g. the current ring, wrap object, etc. 51 51 **/ 52 52 class CountedRefData: … … 59 59 60 60 /// Generate object linked to other reference (e.g. for subscripts) 61 CountedRefData(leftv wrap ped, back_ptr back):62 base(), m_data(wrap ped), m_ring(back->m_ring), m_back(back) {61 CountedRefData(leftv wrapid, back_ptr back): 62 base(), m_data(wrapid), m_ring(back->m_ring), m_back(back) { 63 63 } 64 64 … … 101 101 102 102 /// Generate object for indexing 103 ptr_type subscripted() { return new self(m_data.idify(root()), weakref()); }103 ptr_type wrapid() { return new self(m_data.idify(root()), weakref()); } 104 104 105 105 /// Gerenate weak (but managed) reference to @c *this … … 151 151 152 152 /// Reassign actual object 153 BOOLEAN assign(leftv result, leftv arg) { 153 BOOLEAN assign(leftv result, leftv arg) { 154 154 155 if (!m_data.isid()) { 155 156 (*this) = arg; … … 183 184 ring_ptr m_ring; 184 185 185 /// Reference to actual object for indexedstructures186 /// Reference to actual object for wrap structures 186 187 back_ptr m_back; 187 188 }; … … 192 193 193 194 /// blackbox support - initialization 194 /// @note deals as marker for compatible references, too.195 195 void* countedref_Init(blackbox*) 196 196 { … … 237 237 } 238 238 239 BOOLEAN assign(leftv result, leftv arg) { 239 BOOLEAN assign(leftv result, leftv arg) { 240 240 return m_data->assign(result,arg); 241 241 } … … 317 317 /// Recover the actual object from Singular interpreter object 318 318 static self cast(leftv arg) { 319 assume( (arg != NULL) &&is_ref(arg));319 assume(arg != NULL); assume(is_ref(arg)); 320 320 return self::cast(arg->Data()); 321 321 } … … 348 348 } 349 349 350 351 350 protected: 352 351 /// Store pointer to actual data … … 380 379 // Case: replace assignment behind reference 381 380 if (result->Data() != NULL) { 382 return CountedRef::resolve(arg) ||383 CountedRef::cast(result).assign(result, arg);381 CountedRef ref = CountedRef::cast(result); 382 return CountedRef::resolve(arg) || ref.assign(result, arg); 384 383 } 385 384 … … 409 408 if(op == TYPEOF_CMD) 410 409 return blackboxDefaultOp1(op, res, head); 411 412 410 413 411 if (countedref_CheckInit(res, head)) return TRUE; … … 418 416 } 419 417 420 if(op == LINK_CMD) { 421 res->rtyp = DEF_CMD; 422 return CountedRef::cast(head).dereference(head) || iiAssign(res, head); 423 } 424 425 return CountedRef::cast(head).dereference(head) || iiExprArith1(res, head, op); 426 } 427 428 /// blackbox support - binary operations 418 CountedRef ref = CountedRef::cast(head); 419 return ref.dereference(head) || 420 iiExprArith1(res, head, op == LINK_CMD? head->Typ(): op); 421 } 422 423 424 425 /// blackbox support - binary operations (resolve seocnd argument) 426 static BOOLEAN countedref_Op2_(int op, leftv res, leftv head, leftv arg) 427 { 428 if (CountedRef::is_ref(arg)) { 429 CountedRef ref = CountedRef::cast(arg); 430 return ref.dereference(arg) || iiExprArith2(res, head, op, arg); 431 } 432 return iiExprArith2(res, head, op, arg); 433 } 434 429 435 BOOLEAN countedref_Op2(int op, leftv res, leftv head, leftv arg) 430 436 { 431 return countedref_CheckInit(res, head) || 432 CountedRef::cast(head).dereference(head) || 433 CountedRef::resolve(arg) || 434 iiExprArith2(res, head, op, arg); 437 if (countedref_CheckInit(res, head)) return TRUE; 438 if (CountedRef::is_ref(head)) { 439 CountedRef ref = CountedRef::cast(head); 440 return ref.dereference(head) || countedref_Op2_(op, res, head, arg); 441 } 442 return countedref_Op2_(op, res, head, arg); 443 } 444 445 static BOOLEAN countedref_Op3__(int op, leftv res, leftv head, leftv arg1, leftv arg2) 446 { 447 448 if (CountedRef::is_ref(arg2)) { 449 CountedRef ref = CountedRef::cast(arg2); 450 return ref.dereference(arg2) || iiExprArith3(res, op, head, arg1, arg2); 451 } 452 return iiExprArith3(res, op, head, arg1, arg2); 453 } 454 455 static BOOLEAN countedref_Op3_(int op, leftv res, leftv head, leftv arg1, leftv arg2) 456 { 457 if (CountedRef::is_ref(arg1)) { 458 CountedRef ref = CountedRef::cast(arg1); 459 return ref.dereference(arg1) || countedref_Op3__(op, res, head, arg1, arg2); 460 } 461 return countedref_Op3__(op, res, head, arg1, arg2); 435 462 } 436 463 … … 439 466 BOOLEAN countedref_Op3(int op, leftv res, leftv head, leftv arg1, leftv arg2) 440 467 { 441 return countedref_CheckInit(res, head) || 442 CountedRef::cast(head).dereference(head) || 443 CountedRef::resolve(arg1) || CountedRef::resolve(arg2) || 444 iiExprArith3(res, op, head, arg1, arg2); 468 if (countedref_CheckInit(res, head)) return TRUE; 469 if (CountedRef::is_ref(head)) { 470 CountedRef ref = CountedRef::cast(head); 471 return ref.dereference(head) || countedref_Op3_(op, res, head, arg1, arg2); 472 } 473 return countedref_Op3_(op, res, head, arg1, arg2); 445 474 } 446 475 … … 489 518 490 519 /// Temporarily wrap with identifier for '[' and '.' operation 491 self subscripted() { return self(m_data->subscripted()); }492 493 /// 520 self wrapid() { return self(m_data->wrapid()); } 521 522 /// Generate weak reference (may get invalid) 494 523 data_type::back_ptr weakref() { return m_data->weakref(); } 495 524 525 /// Recover more information (e.g. subexpression data) from computed result 496 526 BOOLEAN retrieve(leftv res, int typ) { 497 527 return (m_data->retrieve(res) && outcast(res, typ)); … … 505 535 } 506 536 537 /// Blackbox support - unary operation for shared data 538 BOOLEAN countedref_Op1Shared(int op, leftv res, leftv head) 539 { 540 if(op == TYPEOF_CMD) 541 return blackboxDefaultOp1(op, res, head); 542 543 if (countedref_CheckInit(res, head)) return TRUE; 544 545 if ((op == DEF_CMD) || (op == head->Typ())) { 546 res->rtyp = head->Typ(); 547 return iiAssign(res, head); 548 } 549 550 CountedRefShared ref = CountedRefShared::cast(head); 551 CountedRefShared wrap = ref.wrapid(); 552 int typ = head->Typ(); 553 return wrap.dereference(head) || 554 iiExprArith1(res, head, op == LINK_CMD? head->Typ(): op) || 555 wrap.retrieve(res, typ); 556 } 557 558 507 559 /// blackbox support - binary operations 508 560 BOOLEAN countedref_Op2Shared(int op, leftv res, leftv head, leftv arg) 509 561 { 510 if ((op == '[') || (op == '.')) {511 if (countedref_CheckInit(res, head)) return TRUE; 512 CountedRefShared indexed = CountedRefShared::cast(head).subscripted();513 562 if (countedref_CheckInit(res, head)) return TRUE; 563 564 if (CountedRefShared::is_ref(head)) { 565 CountedRefShared wrap = CountedRefShared::cast(head).wrapid(); 514 566 int typ = head->Typ(); 515 return indexed.dereference(head) || CountedRefShared::resolve(arg) ||516 iiExprArith2(res, head, op, arg) || indexed.retrieve(res, typ);517 } 518 519 return countedref_Op2 (op, res, head, arg);567 return wrap.dereference(head) || countedref_Op2_(op, res, head, arg) || 568 wrap.retrieve(res, typ); 569 } 570 571 return countedref_Op2_(op, res, head, arg); 520 572 } 521 573 … … 566 618 return jjLIST_PL(res, args); 567 619 } 568 569 return CountedRef::cast(args).dereference(args) || iiExprArithM(res, args, op);620 CountedRef ref = CountedRef::cast(args); 621 return ref.dereference(args) || iiExprArithM(res, args, op); 570 622 } 571 623 … … 575 627 /// Case: replace assignment behind reference 576 628 if ((result->Data() != NULL) && !CountedRefShared::cast(result).unassigned()) { 577 if (CountedRefShared::resolve(arg)) return TRUE; 578 return CountedRefShared::cast(result).assign(result, arg); 579 return FALSE; 629 CountedRef ref = CountedRef::cast(result); 630 return CountedRef::resolve(arg) || ref.assign(result, arg); 580 631 } 581 632 … … 587 638 } 588 639 if(CountedRefShared::cast(result).unassigned()) { 589 // CountedRefShared::cast(result) = arg;590 640 return CountedRefShared::cast(result).assign(result, arg); 591 641 … … 649 699 bbxshared->blackbox_Assign = countedref_AssignShared; 650 700 bbxshared->blackbox_destroy = countedref_destroyShared; 701 bbxshared->blackbox_Op1 = countedref_Op1Shared; 651 702 bbxshared->blackbox_Op2 = countedref_Op2Shared; 652 703 bbxshared->blackbox_Init = countedref_InitShared;
Note: See TracChangeset
for help on using the changeset viewer.