00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef Fennel_BoolPointerInstruction_Included
00023 #define Fennel_BoolPointerInstruction_Included
00024
00025 #include "fennel/calculator/PointerInstruction.h"
00026
00027 FENNEL_BEGIN_NAMESPACE
00028
00034 template<typename PTR_TYPE>
00035 class BoolPointerInstruction : public PointerInstruction
00036 {
00037 public:
00038 explicit
00039 BoolPointerInstruction(
00040 RegisterRef<bool>* result,
00041 RegisterRef<PTR_TYPE>* op1,
00042 StandardTypeDescriptorOrdinal pointerType)
00043 : mResult(result),
00044 mOp1(op1),
00045 mOp2(),
00046 mPointerType(pointerType)
00047 {}
00048 explicit
00049 BoolPointerInstruction(
00050 RegisterRef<bool>* result,
00051 RegisterRef<PTR_TYPE>* op1,
00052 RegisterRef<PTR_TYPE>* op2,
00053 StandardTypeDescriptorOrdinal pointerType)
00054 : mResult(result),
00055 mOp1(op1),
00056 mOp2(op2),
00057 mPointerType(pointerType)
00058 {}
00059 ~BoolPointerInstruction() {
00060 #ifndef __MSVC__
00061
00062 if (0) {
00063 PointerInstruction_NotAPointerType<PTR_TYPE>();
00064 }
00065 #endif
00066 }
00067
00068 protected:
00069 RegisterRef<bool>* mResult;
00070 RegisterRef<PTR_TYPE>* mOp1;
00071 RegisterRef<PTR_TYPE>* mOp2;
00072 StandardTypeDescriptorOrdinal mPointerType;
00073
00074 };
00075
00076 template <typename PTR_TYPE>
00077 class BoolPointerEqual : public BoolPointerInstruction<PTR_TYPE>
00078 {
00079 public:
00080 explicit
00081 BoolPointerEqual(
00082 RegisterRef<bool>* result,
00083 RegisterRef<PTR_TYPE>* op1,
00084 RegisterRef<PTR_TYPE>* op2,
00085 StandardTypeDescriptorOrdinal pointerType)
00086 : BoolPointerInstruction<PTR_TYPE>(result, op1, op2, pointerType)
00087 {}
00088 virtual
00089 ~BoolPointerEqual() {}
00090
00091 virtual void exec(TProgramCounter& pc) const {
00092 pc++;
00093
00094 if (BoolPointerInstruction<PTR_TYPE>::mOp1->isNull() ||
00095 BoolPointerInstruction<PTR_TYPE>::mOp2->isNull()) {
00096 BoolPointerInstruction<PTR_TYPE>::mResult->toNull();
00097 } else if (BoolPointerInstruction<PTR_TYPE>::mOp1->pointer() ==
00098 BoolPointerInstruction<PTR_TYPE>::mOp2->pointer()) {
00099 BoolPointerInstruction<PTR_TYPE>::mResult->value(true);
00100 } else {
00101 BoolPointerInstruction<PTR_TYPE>::mResult->value(false);
00102 }
00103 }
00104
00105 static const char * longName()
00106 {
00107 return "BoolPointerEqual";
00108 }
00109
00110 static const char * shortName()
00111 {
00112 return "EQ";
00113 }
00114
00115 static int numArgs()
00116 {
00117 return 3;
00118 }
00119
00120 void describe(string& out, bool values) const {
00121 describeHelper(
00122 out, values, longName(), shortName(),
00123 BoolPointerInstruction<PTR_TYPE>::mResult,
00124 BoolPointerInstruction<PTR_TYPE>::mOp1,
00125 BoolPointerInstruction<PTR_TYPE>::mOp2);
00126 }
00127
00128 static InstructionSignature
00129 signature(StandardTypeDescriptorOrdinal type) {
00130 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00131 v[0] = STANDARD_TYPE_BOOL;
00132 return InstructionSignature(shortName(), v);
00133 }
00134
00135 static Instruction*
00136 create(InstructionSignature const & sig)
00137 {
00138 assert(sig.size() == numArgs());
00139 return new
00140 BoolPointerEqual(
00141 static_cast<RegisterRef<bool>*> (sig[0]),
00142 static_cast<RegisterRef<PTR_TYPE>*> (sig[1]),
00143 static_cast<RegisterRef<PTR_TYPE>*> (sig[2]),
00144 (sig[1])->type());
00145 }
00146 };
00147
00148 template <typename PTR_TYPE>
00149 class BoolPointerNotEqual : public BoolPointerInstruction<PTR_TYPE>
00150 {
00151 public:
00152 explicit
00153 BoolPointerNotEqual(
00154 RegisterRef<bool>* result,
00155 RegisterRef<PTR_TYPE>* op1,
00156 RegisterRef<PTR_TYPE>* op2,
00157 StandardTypeDescriptorOrdinal pointerType)
00158 : BoolPointerInstruction<PTR_TYPE>(result, op1, op2, pointerType)
00159 {}
00160 virtual
00161 ~BoolPointerNotEqual() {}
00162
00163 virtual void exec(TProgramCounter& pc) const {
00164 pc++;
00165 if (BoolPointerInstruction<PTR_TYPE>::mOp1->isNull() ||
00166 BoolPointerInstruction<PTR_TYPE>::mOp2->isNull()) {
00167 BoolPointerInstruction<PTR_TYPE>::mResult->toNull();
00168 } else if (BoolPointerInstruction<PTR_TYPE>::mOp1->pointer() ==
00169 BoolPointerInstruction<PTR_TYPE>::mOp2->pointer()) {
00170 BoolPointerInstruction<PTR_TYPE>::mResult->value(false);
00171 } else {
00172 BoolPointerInstruction<PTR_TYPE>::mResult->value(true);
00173 }
00174 }
00175
00176 static const char * longName()
00177 {
00178 return "BoolPointerNotEqual";
00179 }
00180
00181 static const char * shortName()
00182 {
00183 return "NE";
00184 }
00185
00186 static int numArgs()
00187 {
00188 return 3;
00189 }
00190
00191 void describe(string& out, bool values) const {
00192 describeHelper(
00193 out, values, longName(), shortName(),
00194 BoolPointerInstruction<PTR_TYPE>::mResult,
00195 BoolPointerInstruction<PTR_TYPE>::mOp1,
00196 BoolPointerInstruction<PTR_TYPE>::mOp2);
00197 }
00198
00199 static InstructionSignature
00200 signature(StandardTypeDescriptorOrdinal type) {
00201 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00202 v[0] = STANDARD_TYPE_BOOL;
00203 return InstructionSignature(shortName(), v);
00204 }
00205
00206 static Instruction*
00207 create(InstructionSignature const & sig)
00208 {
00209 assert(sig.size() == numArgs());
00210 return new
00211 BoolPointerNotEqual(
00212 static_cast<RegisterRef<bool>*> (sig[0]),
00213 static_cast<RegisterRef<PTR_TYPE>*> (sig[1]),
00214 static_cast<RegisterRef<PTR_TYPE>*> (sig[2]),
00215 (sig[1])->type());
00216 }
00217 };
00218
00219 template <typename PTR_TYPE>
00220 class BoolPointerGreater : public BoolPointerInstruction<PTR_TYPE>
00221 {
00222 public:
00223 explicit
00224 BoolPointerGreater(
00225 RegisterRef<bool>* result,
00226 RegisterRef<PTR_TYPE>* op1,
00227 RegisterRef<PTR_TYPE>* op2,
00228 StandardTypeDescriptorOrdinal pointerType)
00229 : BoolPointerInstruction<PTR_TYPE>(result, op1, op2, pointerType)
00230 {}
00231 virtual
00232 ~BoolPointerGreater() {}
00233
00234 virtual void exec(TProgramCounter& pc) const {
00235 pc++;
00236 if (BoolPointerInstruction<PTR_TYPE>::mOp1->isNull() ||
00237 BoolPointerInstruction<PTR_TYPE>::mOp2->isNull()) {
00238 BoolPointerInstruction<PTR_TYPE>::mResult->toNull();
00239 } else if (BoolPointerInstruction<PTR_TYPE>::mOp1->pointer() >
00240 BoolPointerInstruction<PTR_TYPE>::mOp2->pointer()) {
00241 BoolPointerInstruction<PTR_TYPE>::mResult->value(true);
00242 } else {
00243 BoolPointerInstruction<PTR_TYPE>::mResult->value(false);
00244 }
00245 }
00246
00247 static const char * longName()
00248 {
00249 return "BoolPointerGreater";
00250 }
00251
00252 static const char * shortName()
00253 {
00254 return "GT";
00255 }
00256
00257 static int numArgs()
00258 {
00259 return 3;
00260 }
00261
00262 void describe(string& out, bool values) const {
00263 describeHelper(
00264 out, values, longName(), shortName(),
00265 BoolPointerInstruction<PTR_TYPE>::mResult,
00266 BoolPointerInstruction<PTR_TYPE>::mOp1,
00267 BoolPointerInstruction<PTR_TYPE>::mOp2);
00268 }
00269
00270 static InstructionSignature
00271 signature(StandardTypeDescriptorOrdinal type) {
00272 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00273 v[0] = STANDARD_TYPE_BOOL;
00274 return InstructionSignature(shortName(), v);
00275 }
00276
00277 static Instruction*
00278 create(InstructionSignature const & sig)
00279 {
00280 assert(sig.size() == numArgs());
00281 return new
00282 BoolPointerGreater(
00283 static_cast<RegisterRef<bool>*> (sig[0]),
00284 static_cast<RegisterRef<PTR_TYPE>*> (sig[1]),
00285 static_cast<RegisterRef<PTR_TYPE>*> (sig[2]),
00286 (sig[1])->type());
00287 }
00288 };
00289
00290 template <typename PTR_TYPE>
00291 class BoolPointerGreaterEqual : public BoolPointerInstruction<PTR_TYPE>
00292 {
00293 public:
00294 explicit
00295 BoolPointerGreaterEqual(
00296 RegisterRef<bool>* result,
00297 RegisterRef<PTR_TYPE>* op1,
00298 RegisterRef<PTR_TYPE>* op2,
00299 StandardTypeDescriptorOrdinal pointerType)
00300 : BoolPointerInstruction<PTR_TYPE>(result, op1, op2, pointerType)
00301 {}
00302 virtual
00303 ~BoolPointerGreaterEqual() {}
00304
00305 virtual void exec(TProgramCounter& pc) const {
00306 pc++;
00307 if (BoolPointerInstruction<PTR_TYPE>::mOp1->isNull() ||
00308 BoolPointerInstruction<PTR_TYPE>::mOp2->isNull()) {
00309 BoolPointerInstruction<PTR_TYPE>::mResult->toNull();
00310 } else if (BoolPointerInstruction<PTR_TYPE>::mOp1->pointer() >=
00311 BoolPointerInstruction<PTR_TYPE>::mOp2->pointer()) {
00312 BoolPointerInstruction<PTR_TYPE>::mResult->value(true);
00313 } else {
00314 BoolPointerInstruction<PTR_TYPE>::mResult->value(false);
00315 }
00316 }
00317
00318 static const char * longName()
00319 {
00320 return "BoolPointerGreaterEqual";
00321 }
00322
00323 static const char * shortName()
00324 {
00325 return "GE";
00326 }
00327
00328 static int numArgs()
00329 {
00330 return 3;
00331 }
00332
00333 void describe(string& out, bool values) const {
00334 describeHelper(
00335 out, values, longName(), shortName(),
00336 BoolPointerInstruction<PTR_TYPE>::mResult,
00337 BoolPointerInstruction<PTR_TYPE>::mOp1,
00338 BoolPointerInstruction<PTR_TYPE>::mOp2);
00339 }
00340
00341 static InstructionSignature
00342 signature(StandardTypeDescriptorOrdinal type) {
00343 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00344 v[0] = STANDARD_TYPE_BOOL;
00345 return InstructionSignature(shortName(), v);
00346 }
00347
00348 static Instruction*
00349 create(InstructionSignature const & sig)
00350 {
00351 assert(sig.size() == numArgs());
00352 return new
00353 BoolPointerGreaterEqual(
00354 static_cast<RegisterRef<bool>*> (sig[0]),
00355 static_cast<RegisterRef<PTR_TYPE>*> (sig[1]),
00356 static_cast<RegisterRef<PTR_TYPE>*> (sig[2]),
00357 (sig[1])->type());
00358 }
00359 };
00360
00361 template <typename PTR_TYPE>
00362 class BoolPointerLess : public BoolPointerInstruction<PTR_TYPE>
00363 {
00364 public:
00365 explicit
00366 BoolPointerLess(
00367 RegisterRef<bool>* result,
00368 RegisterRef<PTR_TYPE>* op1,
00369 RegisterRef<PTR_TYPE>* op2,
00370 StandardTypeDescriptorOrdinal pointerType)
00371 : BoolPointerInstruction<PTR_TYPE>(result, op1, op2, pointerType)
00372 {}
00373 virtual
00374 ~BoolPointerLess() {}
00375
00376 virtual void exec(TProgramCounter& pc) const {
00377 pc++;
00378 if (BoolPointerInstruction<PTR_TYPE>::mOp1->isNull() ||
00379 BoolPointerInstruction<PTR_TYPE>::mOp2->isNull()) {
00380 BoolPointerInstruction<PTR_TYPE>::mResult->toNull();
00381 } else if (BoolPointerInstruction<PTR_TYPE>::mOp1->pointer() <
00382 BoolPointerInstruction<PTR_TYPE>::mOp2->pointer()) {
00383 BoolPointerInstruction<PTR_TYPE>::mResult->value(true);
00384 } else {
00385 BoolPointerInstruction<PTR_TYPE>::mResult->value(false);
00386 }
00387 }
00388
00389 static const char * longName()
00390 {
00391 return "BoolPointerLess";
00392 }
00393
00394 static const char * shortName()
00395 {
00396 return "LT";
00397 }
00398
00399 static int numArgs()
00400 {
00401 return 3;
00402 }
00403
00404 void describe(string& out, bool values) const {
00405 describeHelper(
00406 out, values, longName(), shortName(),
00407 BoolPointerInstruction<PTR_TYPE>::mResult,
00408 BoolPointerInstruction<PTR_TYPE>::mOp1,
00409 BoolPointerInstruction<PTR_TYPE>::mOp2);
00410 }
00411
00412 static InstructionSignature
00413 signature(StandardTypeDescriptorOrdinal type) {
00414 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00415 v[0] = STANDARD_TYPE_BOOL;
00416 return InstructionSignature(shortName(), v);
00417 }
00418
00419 static Instruction*
00420 create(InstructionSignature const & sig)
00421 {
00422 assert(sig.size() == numArgs());
00423 return new
00424 BoolPointerLess(
00425 static_cast<RegisterRef<bool>*> (sig[0]),
00426 static_cast<RegisterRef<PTR_TYPE>*> (sig[1]),
00427 static_cast<RegisterRef<PTR_TYPE>*> (sig[2]),
00428 (sig[1])->type());
00429 }
00430 };
00431
00432 template <typename PTR_TYPE>
00433 class BoolPointerLessEqual : public BoolPointerInstruction<PTR_TYPE>
00434 {
00435 public:
00436 explicit
00437 BoolPointerLessEqual(
00438 RegisterRef<bool>* result,
00439 RegisterRef<PTR_TYPE>* op1,
00440 RegisterRef<PTR_TYPE>* op2,
00441 StandardTypeDescriptorOrdinal pointerType)
00442 : BoolPointerInstruction<PTR_TYPE>(result, op1, op2, pointerType)
00443 {}
00444 virtual
00445 ~BoolPointerLessEqual() {}
00446
00447 virtual void exec(TProgramCounter& pc) const {
00448 pc++;
00449 if (BoolPointerInstruction<PTR_TYPE>::mOp1->isNull() ||
00450 BoolPointerInstruction<PTR_TYPE>::mOp2->isNull()) {
00451 BoolPointerInstruction<PTR_TYPE>::mResult->toNull();
00452 } else if (BoolPointerInstruction<PTR_TYPE>::mOp1->pointer() <=
00453 BoolPointerInstruction<PTR_TYPE>::mOp2->pointer()) {
00454 BoolPointerInstruction<PTR_TYPE>::mResult->value(true);
00455 } else {
00456 BoolPointerInstruction<PTR_TYPE>::mResult->value(false);
00457 }
00458 }
00459
00460 static const char * longName()
00461 {
00462 return "BoolPointerLessEqual";
00463 }
00464
00465 static const char * shortName()
00466 {
00467 return "LE";
00468 }
00469
00470 static int numArgs()
00471 {
00472 return 3;
00473 }
00474
00475 void describe(string& out, bool values) const {
00476 describeHelper(
00477 out, values, longName(), shortName(),
00478 BoolPointerInstruction<PTR_TYPE>::mResult,
00479 BoolPointerInstruction<PTR_TYPE>::mOp1,
00480 BoolPointerInstruction<PTR_TYPE>::mOp2);
00481 }
00482
00483 static InstructionSignature
00484 signature(StandardTypeDescriptorOrdinal type) {
00485 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00486 v[0] = STANDARD_TYPE_BOOL;
00487 return InstructionSignature(shortName(), v);
00488 }
00489
00490 static Instruction*
00491 create(InstructionSignature const & sig)
00492 {
00493 assert(sig.size() == numArgs());
00494 return new
00495 BoolPointerLessEqual(
00496 static_cast<RegisterRef<bool>*> (sig[0]),
00497 static_cast<RegisterRef<PTR_TYPE>*> (sig[1]),
00498 static_cast<RegisterRef<PTR_TYPE>*> (sig[2]),
00499 (sig[1])->type());
00500 }
00501 };
00502
00503 template <typename PTR_TYPE>
00504 class BoolPointerIsNull : public BoolPointerInstruction<PTR_TYPE>
00505 {
00506 public:
00507 explicit
00508 BoolPointerIsNull(
00509 RegisterRef<bool>* result,
00510 RegisterRef<PTR_TYPE>* op1,
00511 StandardTypeDescriptorOrdinal pointerType)
00512 : BoolPointerInstruction<PTR_TYPE>(result, op1, pointerType)
00513 {}
00514 virtual
00515 ~BoolPointerIsNull() {}
00516
00517 virtual void exec(TProgramCounter& pc) const {
00518 pc++;
00519 if (BoolPointerInstruction<PTR_TYPE>::mOp1->isNull()) {
00520 BoolPointerInstruction<PTR_TYPE>::mResult->value(true);
00521 } else {
00522 BoolPointerInstruction<PTR_TYPE>::mResult->value(false);
00523 }
00524 }
00525
00526 static const char * longName()
00527 {
00528 return "BoolPointerIsNull";
00529 }
00530
00531 static const char * shortName()
00532 {
00533 return "ISNULL";
00534 }
00535
00536 static int numArgs()
00537 {
00538 return 2;
00539 }
00540
00541 void describe(string& out, bool values) const {
00542 describeHelper(
00543 out, values, longName(), shortName(),
00544 BoolPointerInstruction<PTR_TYPE>::mResult,
00545 BoolPointerInstruction<PTR_TYPE>::mOp1,
00546 BoolPointerInstruction<PTR_TYPE>::mOp2);
00547 }
00548
00549 static InstructionSignature
00550 signature(StandardTypeDescriptorOrdinal type) {
00551 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00552 v[0] = STANDARD_TYPE_BOOL;
00553 return InstructionSignature(shortName(), v);
00554 }
00555
00556 static Instruction*
00557 create(InstructionSignature const & sig)
00558 {
00559 assert(sig.size() == numArgs());
00560 return new
00561 BoolPointerIsNull(
00562 static_cast<RegisterRef<bool>*> (sig[0]),
00563 static_cast<RegisterRef<PTR_TYPE>*> (sig[1]),
00564 (sig[1])->type());
00565 }
00566 };
00567
00568 template <typename PTR_TYPE>
00569 class BoolPointerIsNotNull : public BoolPointerInstruction<PTR_TYPE>
00570 {
00571 public:
00572 explicit
00573 BoolPointerIsNotNull(
00574 RegisterRef<bool>* result,
00575 RegisterRef<PTR_TYPE>* op1,
00576 StandardTypeDescriptorOrdinal pointerType)
00577 : BoolPointerInstruction<PTR_TYPE>(result, op1, pointerType)
00578 {}
00579 virtual
00580 ~BoolPointerIsNotNull() {}
00581
00582 virtual void exec(TProgramCounter& pc) const {
00583 pc++;
00584 if (BoolPointerInstruction<PTR_TYPE>::mOp1->isNull()) {
00585 BoolPointerInstruction<PTR_TYPE>::mResult->value(false);
00586 } else {
00587 BoolPointerInstruction<PTR_TYPE>::mResult->value(true);
00588 }
00589 }
00590
00591 static const char * longName()
00592 {
00593 return "BoolPointerIsNotNull";
00594 }
00595
00596 static const char * shortName()
00597 {
00598 return "ISNOTNULL";
00599 }
00600
00601 static int numArgs()
00602 {
00603 return 2;
00604 }
00605
00606 void describe(string& out, bool values) const {
00607 describeHelper(
00608 out, values, longName(), shortName(),
00609 BoolPointerInstruction<PTR_TYPE>::mResult,
00610 BoolPointerInstruction<PTR_TYPE>::mOp1,
00611 BoolPointerInstruction<PTR_TYPE>::mOp2);
00612 }
00613
00614 static InstructionSignature
00615 signature(StandardTypeDescriptorOrdinal type) {
00616 vector<StandardTypeDescriptorOrdinal> v(numArgs(), type);
00617 v[0] = STANDARD_TYPE_BOOL;
00618 return InstructionSignature(shortName(), v);
00619 }
00620
00621 static Instruction*
00622 create(InstructionSignature const & sig)
00623 {
00624 assert(sig.size() == numArgs());
00625 return new
00626 BoolPointerIsNotNull(
00627 static_cast<RegisterRef<bool>*> (sig[0]),
00628 static_cast<RegisterRef<PTR_TYPE>*> (sig[1]),
00629 (sig[1])->type());
00630 }
00631 };
00632
00633 class FENNEL_CALCULATOR_EXPORT BoolPointerInstructionRegister
00634 : InstructionRegister
00635 {
00636
00637 template < template <typename> class INSTCLASS2 >
00638 static void
00639 registerTypes(vector<StandardTypeDescriptorOrdinal> const &t) {
00640
00641 for (uint i = 0; i < t.size(); i++) {
00642 StandardTypeDescriptorOrdinal type = t[i];
00643
00644 InstructionSignature sig = INSTCLASS2<char>::signature(type);
00645 switch (type) {
00646
00647
00648
00649
00650 #define Fennel_InstructionRegisterSwitch_Array 1
00651 #include "fennel/calculator/InstructionRegisterSwitch.h"
00652 default:
00653 throw std::logic_error("Default InstructionRegister");
00654 }
00655 }
00656 }
00657
00658 public:
00659 static void
00660 registerInstructions() {
00661 vector<StandardTypeDescriptorOrdinal> t;
00662
00663
00664
00665 t = InstructionSignature::typeVector(StandardTypeDescriptor::isArray);
00666
00667
00668
00669
00670
00671
00672 registerTypes<fennel::BoolPointerEqual>(t);
00673 registerTypes<fennel::BoolPointerNotEqual>(t);
00674 registerTypes<fennel::BoolPointerGreater>(t);
00675 registerTypes<fennel::BoolPointerGreaterEqual>(t);
00676 registerTypes<fennel::BoolPointerLess>(t);
00677 registerTypes<fennel::BoolPointerLessEqual>(t);
00678 registerTypes<fennel::BoolPointerIsNull>(t);
00679 registerTypes<fennel::BoolPointerIsNotNull>(t);
00680 }
00681 };
00682
00683 FENNEL_END_NAMESPACE
00684
00685 #endif
00686
00687
00688