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
00027 #ifndef Fennel_Instruction_Included
00028 #define Fennel_Instruction_Included
00029
00030 #include <string>
00031 #include "fennel/calculator/InstructionSignature.h"
00032 #include "fennel/calculator/RegisterReference.h"
00033 #include "fennel/tuple/StandardTypeDescriptor.h"
00034 #include "fennel/calculator/InstructionFactory.h"
00035 #include "fennel/calculator/CalcMessage.h"
00036
00037 FENNEL_BEGIN_NAMESPACE
00038
00039 using namespace std;
00040
00041
00042
00043
00044 class FENNEL_CALCULATOR_EXPORT Instruction
00045 {
00046 public:
00047 explicit
00048 Instruction () {}
00049
00050 virtual
00051 ~Instruction() {}
00052
00053 virtual void describe(string& out, bool values) const = 0;
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 protected:
00064 friend class fennel::Calculator;
00065
00066 virtual void exec(long &pc) const = 0;
00067
00068 void describeHelper(
00069 string &out,
00070 bool values,
00071 const char* longName,
00072 const char* shortName,
00073 RegisterReference* result,
00074 RegisterReference* op1,
00075 RegisterReference* op2) const
00076 {
00077 out = longName;
00078 out += ": ";
00079 out += result->toString();
00080 if (values) {
00081 out += " ( ";
00082 if (result->isNull()) {
00083 out += "NULL";
00084 } else {
00085 out += result->valueToString();
00086 }
00087 out += " ) ";
00088 }
00089 out += " = ";
00090
00091 if (!op2 || !op2->isValid()) {
00092 out += " ";
00093 out += shortName;
00094 out += " ";
00095 }
00096 if (op1 && op1->isValid()) {
00097 out += op1->toString();
00098 if (values) {
00099 out += " ( ";
00100 if (op1->isNull()) {
00101 out += "NULL";
00102 } else {
00103 out += op1->valueToString();
00104 }
00105 out += " ) ";
00106 }
00107 }
00108 if (op2 && op2->isValid()) {
00109 out += " ";
00110 out += shortName;
00111 out += " ";
00112 out += op2->toString();
00113 if (values) {
00114 out += " ( ";
00115 if (op2->isNull()) {
00116 out += "NULL";
00117 } else {
00118 out += op2->valueToString();
00119 }
00120 out += " ) ";
00121 }
00122 }
00123 }
00124 };
00125
00126
00132
00133 class FENNEL_CALCULATOR_EXPORT InstructionRegister
00134 {
00135 protected:
00136 template < typename TYPE1,
00137 template <typename> class INSTCLASS >
00138 static void
00139 registerInstance(StandardTypeDescriptorOrdinal type)
00140 {
00141 StringToCreateFn* instMap = InstructionFactory::getInstructionTable();
00142 (*instMap)[INSTCLASS<TYPE1>::signature(type).compute()] =
00143 &INSTCLASS<TYPE1>::create;
00144 }
00145
00146 template < typename TYPE1,
00147 typename TYPE2,
00148 template <typename, typename> class INSTCLASS >
00149 static void
00150 registerInstance2(
00151 StandardTypeDescriptorOrdinal type1,
00152 StandardTypeDescriptorOrdinal type2)
00153 {
00154 StringToCreateFn* instMap = InstructionFactory::getInstructionTable();
00155 (*instMap)[INSTCLASS<TYPE1,TYPE2>::signature(type1, type2).compute()] =
00156 &INSTCLASS<TYPE1,TYPE2>::create;
00157 }
00158
00159 template < typename IGNOREDDATATYPE, class INSTCLASS >
00160 static void
00161 registerInstance(StandardTypeDescriptorOrdinal type)
00162 {
00163 StringToCreateFn* instMap = InstructionFactory::getInstructionTable();
00164 (*instMap)[INSTCLASS::signature(type).compute()] =
00165 &INSTCLASS::create;
00166 }
00167 };
00168
00169
00170 FENNEL_END_NAMESPACE
00171
00172 #endif
00173
00174
00175