00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef Fennel_BoolInstruction_Included
00027 #define Fennel_BoolInstruction_Included
00028
00029 #include "fennel/calculator/Instruction.h"
00030
00031 FENNEL_BEGIN_NAMESPACE
00032
00033 class FENNEL_CALCULATOR_EXPORT BoolInstruction
00034 : public Instruction
00035 {
00036 public:
00037 explicit
00038 BoolInstruction(RegisterRef<bool>* result)
00039 : mResult(result),
00040 mOp1(),
00041 mOp2()
00042 {}
00043 explicit
00044 BoolInstruction(RegisterRef<bool>* result, RegisterRef<bool>* op1)
00045 : mResult(result),
00046 mOp1(op1),
00047 mOp2()
00048 {}
00049 explicit
00050 BoolInstruction(
00051 RegisterRef<bool>* &result,
00052 RegisterRef<bool>* &op1,
00053 RegisterRef<bool>* &op2)
00054 : mResult(result),
00055 mOp1(op1),
00056 mOp2(op2)
00057 {}
00058
00059 virtual
00060 ~BoolInstruction()
00061 {}
00062
00063 protected:
00064 RegisterRef<bool>* mResult;
00065 RegisterRef<bool>* mOp1;
00066 RegisterRef<bool>* mOp2;
00067
00068 static vector<StandardTypeDescriptorOrdinal>
00069 regDesc(uint args) {
00070 vector<StandardTypeDescriptorOrdinal> v;
00071 uint i;
00072 for (i = 0; i < args; i++) {
00073 v.push_back(STANDARD_TYPE_BOOL);
00074 }
00075 return v;
00076 }
00077 };
00078
00079 class FENNEL_CALCULATOR_EXPORT BoolOr
00080 : public BoolInstruction
00081 {
00082 public:
00083 explicit
00084 BoolOr(
00085 RegisterRef<bool>* result,
00086 RegisterRef<bool>* op1,
00087 RegisterRef<bool>* op2)
00088 : BoolInstruction(result, op1, op2)
00089 {}
00090
00091 virtual
00092 ~BoolOr() {}
00093
00094 static const char* longName();
00095 static const char* shortName();
00096 static int numArgs();
00097 void describe(string& out, bool values) const;
00098
00099 virtual void exec(TProgramCounter& pc) const {
00100
00101 pc++;
00102
00103 if (mOp1->isNull()) {
00104 if (mOp2->isNull() || mOp2->value() == false) {
00105 mResult->toNull();
00106 } else {
00107 mResult->value(true);
00108 }
00109 } else {
00110 if (mOp2->isNull()) {
00111 if (mOp1->value() == true) {
00112 mResult->value(true);
00113 } else {
00114 mResult->toNull();
00115 }
00116 } else {
00117 if (mOp1->value() == true || mOp2->value() == true) {
00118 mResult->value(true);
00119 } else {
00120 mResult->value(false);
00121 }
00122 }
00123 }
00124 }
00125
00126 static InstructionSignature
00127 signature(StandardTypeDescriptorOrdinal type) {
00128 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00129 return InstructionSignature(shortName(), v);
00130 }
00131
00132 static Instruction*
00133 create(InstructionSignature const & sig)
00134 {
00135 assert(sig.size() == numArgs());
00136 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00137 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00138 assert((sig[2])->type() == STANDARD_TYPE_BOOL);
00139 return new BoolOr(
00140 static_cast<RegisterRef<bool>*> (sig[0]),
00141 static_cast<RegisterRef<bool>*> (sig[1]),
00142 static_cast<RegisterRef<bool>*> (sig[2]));
00143 }
00144 };
00145
00146 class FENNEL_CALCULATOR_EXPORT BoolAnd
00147 : public BoolInstruction
00148 {
00149 public:
00150 explicit
00151 BoolAnd(
00152 RegisterRef<bool>* result,
00153 RegisterRef<bool>* op1,
00154 RegisterRef<bool>* op2)
00155 : BoolInstruction(result, op1, op2)
00156 {}
00157
00158 ~BoolAnd() {}
00159
00160 static const char* longName();
00161 static const char* shortName();
00162 static int numArgs();
00163 void describe(string& out, bool values) const;
00164
00165 virtual void exec(TProgramCounter& pc) const {
00166
00167 pc++;
00168 if (mOp1->isNull()) {
00169 if (mOp2->isNull() || mOp2->value() == true) {
00170 mResult->toNull();
00171 } else {
00172 mResult->value(false);
00173 }
00174 } else {
00175 if (mOp2->isNull()) {
00176 if (mOp1->value() == true) {
00177 mResult->toNull();
00178 } else {
00179 mResult->value(false);
00180 }
00181 } else if (mOp1->value() == true && mOp2->value() == true) {
00182 mResult->value(true);
00183 } else {
00184 mResult->value(false);
00185 }
00186 }
00187 }
00188
00189 static InstructionSignature
00190 signature(StandardTypeDescriptorOrdinal type) {
00191 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00192 return InstructionSignature(shortName(), v);
00193 }
00194
00195 static Instruction*
00196 create(InstructionSignature const & sig)
00197 {
00198 assert(sig.size() == numArgs());
00199 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00200 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00201 assert((sig[2])->type() == STANDARD_TYPE_BOOL);
00202 return new BoolAnd(
00203 static_cast<RegisterRef<bool>*> (sig[0]),
00204 static_cast<RegisterRef<bool>*> (sig[1]),
00205 static_cast<RegisterRef<bool>*> (sig[2]));
00206 }
00207 };
00208
00209 class FENNEL_CALCULATOR_EXPORT BoolNot
00210 : public BoolInstruction
00211 {
00212 public:
00213 explicit
00214 BoolNot(
00215 RegisterRef<bool>* result,
00216 RegisterRef<bool>* op1)
00217 : BoolInstruction(result, op1)
00218 {}
00219
00220 ~BoolNot() {}
00221
00222 static const char* longName();
00223 static const char* shortName();
00224 static int numArgs();
00225 void describe(string& out, bool values) const;
00226
00227 virtual void exec(TProgramCounter& pc) const {
00228
00229 pc++;
00230 if (mOp1->isNull()) {
00231 mResult->toNull();
00232 } else if (mOp1->value() == true) {
00233 mResult->value(false);
00234 } else {
00235 mResult->value(true);
00236 }
00237 }
00238
00239 static InstructionSignature
00240 signature(StandardTypeDescriptorOrdinal type) {
00241 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00242 return InstructionSignature(shortName(), v);
00243 }
00244
00245 static Instruction*
00246 create(InstructionSignature const & sig)
00247 {
00248 assert(sig.size() == numArgs());
00249 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00250 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00251 return new BoolNot(
00252 static_cast<RegisterRef<bool>*> (sig[0]),
00253 static_cast<RegisterRef<bool>*> (sig[1]));
00254 }
00255 };
00256
00257 class FENNEL_CALCULATOR_EXPORT BoolMove
00258 : public BoolInstruction
00259 {
00260 public:
00261 explicit
00262 BoolMove(
00263 RegisterRef<bool>* result,
00264 RegisterRef<bool>* op1)
00265 : BoolInstruction(result, op1)
00266 {}
00267
00268 ~BoolMove() {}
00269
00270 static const char* longName();
00271 static const char* shortName();
00272 static int numArgs();
00273 void describe(string& out, bool values) const;
00274
00275 virtual void exec(TProgramCounter& pc) const {
00276 pc++;
00277 if (mOp1->isNull()) {
00278 mResult->toNull();
00279 } else {
00280 mResult->value(mOp1->value());
00281 }
00282 }
00283
00284 static InstructionSignature
00285 signature(StandardTypeDescriptorOrdinal type) {
00286 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00287 return InstructionSignature(shortName(), v);
00288 }
00289
00290 static Instruction*
00291 create(InstructionSignature const & sig)
00292 {
00293 assert(sig.size() == numArgs());
00294 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00295 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00296 return new BoolMove(
00297 static_cast<RegisterRef<bool>*> (sig[0]),
00298 static_cast<RegisterRef<bool>*> (sig[1]));
00299 }
00300 };
00301
00302 class FENNEL_CALCULATOR_EXPORT BoolRef
00303 : public BoolInstruction
00304 {
00305 public:
00306 explicit
00307 BoolRef(
00308 RegisterRef<bool>* result,
00309 RegisterRef<bool>* op1)
00310 : BoolInstruction(result, op1)
00311 {}
00312
00313 ~BoolRef() {}
00314
00315 static const char* longName();
00316 static const char* shortName();
00317 static int numArgs();
00318 void describe(string& out, bool values) const;
00319
00320 virtual void exec(TProgramCounter& pc) const {
00321 pc++;
00322 mResult->refer(mOp1);
00323 }
00324
00325 static InstructionSignature
00326 signature(StandardTypeDescriptorOrdinal type) {
00327 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00328 return InstructionSignature(shortName(), v);
00329 }
00330
00331 static Instruction*
00332 create(InstructionSignature const & sig)
00333 {
00334 assert(sig.size() == numArgs());
00335 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00336 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00337 return new BoolRef(
00338 static_cast<RegisterRef<bool>*> (sig[0]),
00339 static_cast<RegisterRef<bool>*> (sig[1]));
00340 }
00341 };
00342
00343 class FENNEL_CALCULATOR_EXPORT BoolIs
00344 : public BoolInstruction
00345 {
00346 public:
00347 explicit
00348 BoolIs(
00349 RegisterRef<bool>* result,
00350 RegisterRef<bool>* op1,
00351 RegisterRef<bool>* op2)
00352 : BoolInstruction(result, op1, op2)
00353 {}
00354
00355 ~BoolIs() {}
00356
00357 static const char* longName();
00358 static const char* shortName();
00359 static int numArgs();
00360 void describe(string& out, bool values) const;
00361
00362 virtual void exec(TProgramCounter& pc) const {
00363
00364 pc++;
00365 if (mOp1->isNull()) {
00366 if (mOp2->isNull()) {
00367 mResult->value(true);
00368 } else {
00369 mResult->value(false);
00370 }
00371 } else if (mOp2->isNull()) {
00372 mResult->value(false);
00373 } else if (mOp1->value() == mOp2->value()) {
00374 mResult->value(true);
00375 } else {
00376 mResult->value(false);
00377 }
00378 }
00379
00380 static InstructionSignature
00381 signature(StandardTypeDescriptorOrdinal type) {
00382 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00383 return InstructionSignature(shortName(), v);
00384 }
00385
00386 static Instruction*
00387 create(InstructionSignature const & sig)
00388 {
00389 assert(sig.size() == numArgs());
00390 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00391 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00392 assert((sig[2])->type() == STANDARD_TYPE_BOOL);
00393 return new BoolIs(
00394 static_cast<RegisterRef<bool>*> (sig[0]),
00395 static_cast<RegisterRef<bool>*> (sig[1]),
00396 static_cast<RegisterRef<bool>*> (sig[2]));
00397 }
00398 };
00399
00400 class FENNEL_CALCULATOR_EXPORT BoolIsNot
00401 : public BoolInstruction
00402 {
00403 public:
00404 explicit
00405 BoolIsNot(
00406 RegisterRef<bool>* result,
00407 RegisterRef<bool>* op1,
00408 RegisterRef<bool>* op2)
00409 : BoolInstruction(result, op1, op2)
00410 {}
00411
00412 ~BoolIsNot() {}
00413
00414 static const char* longName();
00415 static const char* shortName();
00416 static int numArgs();
00417 void describe(string& out, bool values) const;
00418
00419 virtual void exec(TProgramCounter& pc) const {
00420
00421 pc++;
00422 if (mOp1->isNull()) {
00423 if (mOp2->isNull()) {
00424 mResult->value(false);
00425 } else {
00426 mResult->value(true);
00427 }
00428 } else if (mOp2->isNull()) {
00429 mResult->value(true);
00430 } else if (mOp1->value() == mOp2->value()) {
00431 mResult->value(false);
00432 } else {
00433 mResult->value(true);
00434 }
00435 }
00436
00437 static InstructionSignature
00438 signature(StandardTypeDescriptorOrdinal type) {
00439 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00440 return InstructionSignature(shortName(), v);
00441 }
00442
00443 static Instruction*
00444 create(InstructionSignature const & sig)
00445 {
00446 assert(sig.size() == numArgs());
00447 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00448 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00449 assert((sig[2])->type() == STANDARD_TYPE_BOOL);
00450 return new BoolIsNot(
00451 static_cast<RegisterRef<bool>*> (sig[0]),
00452 static_cast<RegisterRef<bool>*> (sig[1]),
00453 static_cast<RegisterRef<bool>*> (sig[2]));
00454 }
00455 };
00456
00457
00458
00459 class FENNEL_CALCULATOR_EXPORT BoolEqual
00460 : public BoolInstruction
00461 {
00462 public:
00463 explicit
00464 BoolEqual(
00465 RegisterRef<bool>* result,
00466 RegisterRef<bool>* op1,
00467 RegisterRef<bool>* op2)
00468 : BoolInstruction(result, op1, op2)
00469 {}
00470
00471 ~BoolEqual() {}
00472
00473 static const char* longName();
00474 static const char* shortName();
00475 static int numArgs();
00476 void describe(string& out, bool values) const;
00477
00478 virtual void exec(TProgramCounter& pc) const {
00479
00480 pc++;
00481 if (mOp1->isNull() || mOp2->isNull()) {
00482 mResult->toNull();
00483 } else {
00484 if (mOp1->value() == mOp2->value()) {
00485 mResult->value(true);
00486 } else {
00487 mResult->value(false);
00488 }
00489 }
00490 }
00491
00492 static InstructionSignature
00493 signature(StandardTypeDescriptorOrdinal type) {
00494 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00495 return InstructionSignature(shortName(), v);
00496 }
00497
00498 static Instruction*
00499 create(InstructionSignature const & sig)
00500 {
00501 assert(sig.size() == numArgs());
00502 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00503 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00504 assert((sig[2])->type() == STANDARD_TYPE_BOOL);
00505 return new BoolEqual(
00506 static_cast<RegisterRef<bool>*> (sig[0]),
00507 static_cast<RegisterRef<bool>*> (sig[1]),
00508 static_cast<RegisterRef<bool>*> (sig[2]));
00509 }
00510 };
00511
00512 class FENNEL_CALCULATOR_EXPORT BoolNotEqual
00513 : public BoolInstruction
00514 {
00515 public:
00516 explicit
00517 BoolNotEqual(
00518 RegisterRef<bool>* result,
00519 RegisterRef<bool>* op1,
00520 RegisterRef<bool>* op2)
00521 : BoolInstruction(result, op1, op2)
00522 {}
00523
00524 ~BoolNotEqual() {}
00525
00526 static const char* longName();
00527 static const char* shortName();
00528 static int numArgs();
00529 void describe(string& out, bool values) const;
00530
00531 virtual void exec(TProgramCounter& pc) const {
00532
00533 pc++;
00534 if (mOp1->isNull() || mOp2->isNull()) {
00535 mResult->toNull();
00536 } else {
00537 if (mOp1->value() == mOp2->value()) {
00538 mResult->value(false);
00539 } else {
00540 mResult->value(true);
00541 }
00542 }
00543 }
00544
00545 static InstructionSignature
00546 signature(StandardTypeDescriptorOrdinal type) {
00547 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00548 return InstructionSignature(shortName(), v);
00549 }
00550
00551 static Instruction*
00552 create(InstructionSignature const & sig)
00553 {
00554 assert(sig.size() == numArgs());
00555 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00556 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00557 assert((sig[2])->type() == STANDARD_TYPE_BOOL);
00558 return new BoolNotEqual(
00559 static_cast<RegisterRef<bool>*> (sig[0]),
00560 static_cast<RegisterRef<bool>*> (sig[1]),
00561 static_cast<RegisterRef<bool>*> (sig[2]));
00562 }
00563 };
00564
00565 class FENNEL_CALCULATOR_EXPORT BoolGreater
00566 : public BoolInstruction
00567 {
00568 public:
00569 explicit
00570 BoolGreater(
00571 RegisterRef<bool>* result,
00572 RegisterRef<bool>* op1,
00573 RegisterRef<bool>* op2)
00574 : BoolInstruction(result, op1, op2)
00575 {}
00576
00577 ~BoolGreater() {}
00578
00579 static const char* longName();
00580 static const char* shortName();
00581 static int numArgs();
00582 void describe(string& out, bool values) const;
00583
00584 virtual void exec(TProgramCounter& pc) const {
00585
00586 pc++;
00587 if (mOp1->isNull() || mOp2->isNull()) {
00588 mResult->toNull();
00589 } else {
00590 if ((mOp1->value() == true) && (mOp2->value() == false)) {
00591 mResult->value(true);
00592 } else {
00593 mResult->value(false);
00594 }
00595 }
00596 }
00597
00598 static InstructionSignature
00599 signature(StandardTypeDescriptorOrdinal type) {
00600 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00601 return InstructionSignature(shortName(), v);
00602 }
00603
00604 static Instruction*
00605 create(InstructionSignature const & sig)
00606 {
00607 assert(sig.size() == numArgs());
00608 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00609 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00610 assert((sig[2])->type() == STANDARD_TYPE_BOOL);
00611 return new BoolGreater(
00612 static_cast<RegisterRef<bool>*> (sig[0]),
00613 static_cast<RegisterRef<bool>*> (sig[1]),
00614 static_cast<RegisterRef<bool>*> (sig[2]));
00615 }
00616 };
00617
00618 class FENNEL_CALCULATOR_EXPORT BoolGreaterEqual
00619 : public BoolInstruction
00620 {
00621 public:
00622 explicit
00623 BoolGreaterEqual(
00624 RegisterRef<bool>* result,
00625 RegisterRef<bool>* op1,
00626 RegisterRef<bool>* op2)
00627 : BoolInstruction(result, op1, op2)
00628 {}
00629
00630 ~BoolGreaterEqual() {}
00631
00632 static const char* longName();
00633 static const char* shortName();
00634 static int numArgs();
00635 void describe(string& out, bool values) const;
00636
00637 virtual void exec(TProgramCounter& pc) const {
00638
00639 pc++;
00640 if (mOp1->isNull() || mOp2->isNull()) {
00641 mResult->toNull();
00642 } else {
00643 bool op1 = mOp1->value();
00644 bool op2 = mOp2->value();
00645 if ((op1 == true && op2 == false) ||
00646 op1 == op2) {
00647 mResult->value(true);
00648 } else {
00649 mResult->value(false);
00650 }
00651 }
00652 }
00653
00654 static InstructionSignature
00655 signature(StandardTypeDescriptorOrdinal type) {
00656 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00657 return InstructionSignature(shortName(), v);
00658 }
00659
00660 static Instruction*
00661 create(InstructionSignature const & sig)
00662 {
00663 assert(sig.size() == numArgs());
00664 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00665 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00666 assert((sig[2])->type() == STANDARD_TYPE_BOOL);
00667 return new BoolGreaterEqual(
00668 static_cast<RegisterRef<bool>*> (sig[0]),
00669 static_cast<RegisterRef<bool>*> (sig[1]),
00670 static_cast<RegisterRef<bool>*> (sig[2]));
00671 }
00672 };
00673
00674 class FENNEL_CALCULATOR_EXPORT BoolLess
00675 : public BoolInstruction
00676 {
00677 public:
00678 explicit
00679 BoolLess(
00680 RegisterRef<bool>* result,
00681 RegisterRef<bool>* op1,
00682 RegisterRef<bool>* op2)
00683 : BoolInstruction(result, op1, op2)
00684 {}
00685
00686 ~BoolLess() {}
00687
00688 static const char* longName();
00689 static const char* shortName();
00690 static int numArgs();
00691 void describe(string& out, bool values) const;
00692
00693 virtual void exec(TProgramCounter& pc) const {
00694
00695 pc++;
00696 if (mOp1->isNull() || mOp2->isNull()) {
00697 mResult->toNull();
00698 } else {
00699 if (mOp1->value() == false && mOp2->value() == true) {
00700 mResult->value(true);
00701 } else {
00702 mResult->value(false);
00703 }
00704 }
00705 }
00706
00707 static InstructionSignature
00708 signature(StandardTypeDescriptorOrdinal type) {
00709 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00710 return InstructionSignature(shortName(), v);
00711 }
00712
00713 static Instruction*
00714 create(InstructionSignature const & sig)
00715 {
00716 assert(sig.size() == numArgs());
00717 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00718 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00719 assert((sig[2])->type() == STANDARD_TYPE_BOOL);
00720 return new BoolLess(
00721 static_cast<RegisterRef<bool>*> (sig[0]),
00722 static_cast<RegisterRef<bool>*> (sig[1]),
00723 static_cast<RegisterRef<bool>*> (sig[2]));
00724 }
00725 };
00726
00727 class FENNEL_CALCULATOR_EXPORT BoolLessEqual
00728 : public BoolInstruction
00729 {
00730 public:
00731 explicit
00732 BoolLessEqual(
00733 RegisterRef<bool>* result,
00734 RegisterRef<bool>* op1,
00735 RegisterRef<bool>* op2)
00736 : BoolInstruction(result, op1, op2)
00737 {}
00738
00739 ~BoolLessEqual() {}
00740
00741 static const char* longName();
00742 static const char* shortName();
00743 static int numArgs();
00744 void describe(string& out, bool values) const;
00745
00746 virtual void exec(TProgramCounter& pc) const {
00747
00748 pc++;
00749 if (mOp1->isNull() || mOp2->isNull()) {
00750 mResult->toNull();
00751 } else {
00752 bool op1 = mOp1->value();
00753 bool op2 = mOp2->value();
00754 if ((op1 == false && op2 == true) ||
00755 op1 == op2) {
00756 mResult->value(true);
00757 } else {
00758 mResult->value(false);
00759 }
00760 }
00761 }
00762
00763 static InstructionSignature
00764 signature(StandardTypeDescriptorOrdinal type) {
00765 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00766 return InstructionSignature(shortName(), v);
00767 }
00768
00769 static Instruction*
00770 create(InstructionSignature const & sig)
00771 {
00772 assert(sig.size() == numArgs());
00773 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00774 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00775 assert((sig[2])->type() == STANDARD_TYPE_BOOL);
00776 return new BoolLessEqual(
00777 static_cast<RegisterRef<bool>*> (sig[0]),
00778 static_cast<RegisterRef<bool>*> (sig[1]),
00779 static_cast<RegisterRef<bool>*> (sig[2]));
00780 }
00781 };
00782
00783 class FENNEL_CALCULATOR_EXPORT BoolIsNull
00784 : public BoolInstruction
00785 {
00786 public:
00787 explicit
00788 BoolIsNull(
00789 RegisterRef<bool>* result,
00790 RegisterRef<bool>* op1)
00791 : BoolInstruction(result, op1)
00792 {}
00793
00794 ~BoolIsNull() {}
00795
00796 static const char* longName();
00797 static const char* shortName();
00798 static int numArgs();
00799 void describe(string& out, bool values) const;
00800
00801 virtual void exec(TProgramCounter& pc) const {
00802 pc++;
00803 if (mOp1->isNull()) {
00804 mResult->value(true);
00805 } else {
00806 mResult->value(false);
00807 }
00808 }
00809
00810 static InstructionSignature
00811 signature(StandardTypeDescriptorOrdinal type) {
00812 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00813 return InstructionSignature(shortName(), v);
00814 }
00815
00816 static Instruction*
00817 create(InstructionSignature const & sig)
00818 {
00819 assert(sig.size() == numArgs());
00820 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00821 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00822 return new BoolIsNull(
00823 static_cast<RegisterRef<bool>*> (sig[0]),
00824 static_cast<RegisterRef<bool>*> (sig[1]));
00825 }
00826 };
00827
00828 class FENNEL_CALCULATOR_EXPORT BoolIsNotNull
00829 : public BoolInstruction
00830 {
00831 public:
00832 explicit
00833 BoolIsNotNull(
00834 RegisterRef<bool>* result,
00835 RegisterRef<bool>* op1)
00836 : BoolInstruction(result, op1)
00837 {}
00838
00839 ~BoolIsNotNull() {}
00840
00841 static const char* longName();
00842 static const char* shortName();
00843 static int numArgs();
00844 void describe(string& out, bool values) const;
00845
00846 virtual void exec(TProgramCounter& pc) const {
00847
00848 pc++;
00849 if (mOp1->isNull()) {
00850 mResult->value(false);
00851 } else {
00852 mResult->value(true);
00853 }
00854 }
00855
00856 static InstructionSignature
00857 signature(StandardTypeDescriptorOrdinal type) {
00858 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00859 return InstructionSignature(shortName(), v);
00860 }
00861
00862 static Instruction*
00863 create(InstructionSignature const & sig)
00864 {
00865 assert(sig.size() == numArgs());
00866 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00867 assert((sig[1])->type() == STANDARD_TYPE_BOOL);
00868 return new BoolIsNotNull(
00869 static_cast<RegisterRef<bool>*> (sig[0]),
00870 static_cast<RegisterRef<bool>*> (sig[1]));
00871 }
00872 };
00873
00874 class FENNEL_CALCULATOR_EXPORT BoolToNull
00875 : public BoolInstruction
00876 {
00877 public:
00878 explicit
00879 BoolToNull(RegisterRef<bool>* result)
00880 : BoolInstruction(result)
00881 {}
00882
00883 ~BoolToNull() {}
00884
00885 static const char* longName();
00886 static const char* shortName();
00887 static int numArgs();
00888 void describe(string& out, bool values) const;
00889
00890 virtual void exec(TProgramCounter& pc) const {
00891
00892 pc++;
00893 mResult->toNull();
00894 }
00895
00896 static InstructionSignature
00897 signature(StandardTypeDescriptorOrdinal type) {
00898 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00899 return InstructionSignature(shortName(), v);
00900 }
00901
00902 static Instruction*
00903 create(InstructionSignature const & sig)
00904 {
00905 assert(sig.size() == numArgs());
00906 assert((sig[0])->type() == STANDARD_TYPE_BOOL);
00907 return new BoolToNull(static_cast<RegisterRef<bool>*> (sig[0]));
00908 }
00909 };
00910
00911 class FENNEL_CALCULATOR_EXPORT BoolInstructionRegister
00912 : InstructionRegister {
00913
00914
00915 template < class INSTCLASS2 >
00916 static void
00917 registerTypes(vector<StandardTypeDescriptorOrdinal> const & t)
00918 {
00919 for (uint i = 0; i < t.size(); i++) {
00920 StandardTypeDescriptorOrdinal type = t[i];
00921 InstructionSignature sig = INSTCLASS2::signature(type);
00922 switch (type) {
00923 #define Fennel_InstructionRegisterSwitch_Bool 1
00924 #include "fennel/calculator/InstructionRegisterSwitch.h"
00925 default:
00926 throw std::logic_error("Default InstructionRegister");
00927 }
00928 }
00929 }
00930
00931 public:
00932 static void
00933 registerInstructions()
00934 {
00935 vector<StandardTypeDescriptorOrdinal> t;
00936 t.push_back(STANDARD_TYPE_BOOL);
00937
00938
00939
00940
00941
00942
00943 registerTypes<fennel::BoolOr>(t);
00944 registerTypes<fennel::BoolAnd>(t);
00945 registerTypes<fennel::BoolNot>(t);
00946 registerTypes<fennel::BoolMove>(t);
00947 registerTypes<fennel::BoolRef>(t);
00948 registerTypes<fennel::BoolIs>(t);
00949 registerTypes<fennel::BoolIsNot>(t);
00950 registerTypes<fennel::BoolEqual>(t);
00951 registerTypes<fennel::BoolNotEqual>(t);
00952 registerTypes<fennel::BoolGreater>(t);
00953 registerTypes<fennel::BoolGreaterEqual>(t);
00954 registerTypes<fennel::BoolLess>(t);
00955 registerTypes<fennel::BoolLessEqual>(t);
00956 registerTypes<fennel::BoolIsNull>(t);
00957 registerTypes<fennel::BoolIsNotNull>(t);
00958 registerTypes<fennel::BoolToNull>(t);
00959 }
00960 };
00961
00962
00963 FENNEL_END_NAMESPACE
00964
00965 #endif
00966
00967
00968