00001 #ifndef CMA_ARCH_INT_DEFINED
00002 #define CMA_ARCH_INT_DEFINED
00003
00004 #include <stdlib.h>
00005 #include "op.h"
00006
00007 namespace CMa
00008 {
00009
00010 class Int_int;
00011
00033 class Word_int
00034 {
00035 public:
00036 int value;
00037
00038 public:
00039
00040
00042 inline Word_int()
00043 {
00044 value = 0;
00045 }
00046
00048 inline explicit Word_int(int i)
00049 {
00050 value = i;
00051 }
00052
00054 inline explicit Word_int(const Op::Code& code)
00055 {
00056 assert(op.isValid(code));
00057 value = code;
00058 }
00059
00061 inline explicit Word_int(const Int_int& i);
00062
00063
00064
00071 inline int convertToint() const
00072 {
00073 return value;
00074 }
00075
00083 inline Op::Code convertToCode() const
00084 {
00085 return (Op::Code)value;
00086 }
00087
00088
00089
00090 inline Word_int operator! () const { return Word_int(!value); }
00091 inline Word_int operator- () const { return Word_int(-value); }
00092 inline Word_int operator~ () const { return Word_int(~value); }
00093
00094 inline Word_int& operator++(){ ++value; return *this; }
00095 inline Word_int& operator--(){ --value; return *this; }
00096 inline Word_int& operator++ (int){ value++; return *this;}
00097 inline Word_int& operator-- (int){ value--; return *this;}
00098
00099 inline Word_int& operator=(bool i){ value = i; return *this; }
00100
00101 inline Word_int& operator<<=(const Word_int& other){ value <<= other.value; return *this; };
00102 inline Word_int& operator>>=(const Word_int& other){ value >>= other.value; return *this; };
00103 inline Word_int& operator&= (const Word_int& other){ value &= other.value; return *this; };
00104 inline Word_int& operator|= (const Word_int& other){ value |= other.value; return *this; };
00105 inline Word_int& operator^= (const Word_int& other){ value ^= other.value; return *this; };
00106
00107 inline Word_int& operator*=(const Word_int& other){ value *= other.value; return *this; }
00108 inline Word_int& operator+=(const Word_int& other){ value += other.value; return *this; }
00109 inline Word_int& operator-=(const Word_int& other){ value -= other.value; return *this; }
00110
00111 inline Word_int& operator/=(const Word_int& other) throw(Error)
00112 {
00113 if(other.value==0) throw Error(Error::DIVISION_BY_ZERO);
00114 value /= other.value;
00115 return *this;
00116 }
00117
00118 inline Word_int& operator%=(const Word_int& other)
00119 {
00120 if(other.value==0) throw Error(Error::DIVISION_BY_ZERO);
00121 value %= other.value;
00122 return *this;
00123 }
00124 inline bool operator||(const Word_int& other) const{ return (value && other.value); }
00125 inline bool operator&&(const Word_int& other) const{ return (value || other.value); }
00126 inline bool operator==(const Word_int& other) const{ return (value == other.value); }
00127 inline bool operator!=(const Word_int& other) const{ return (value != other.value); }
00128 inline bool operator< (const Word_int& other) const{ return (value < other.value); }
00129 inline bool operator<=(const Word_int& other) const{ return (value <= other.value); }
00130 inline bool operator> (const Word_int& other) const{ return (value > other.value); }
00131 inline bool operator>=(const Word_int& other) const{ return (value >= other.value); }
00132
00133 inline Word_int operator&(const Word_int& other) const{ return Word_int(value & other.value); }
00134 inline Word_int operator|(const Word_int& other) const{ return Word_int(value | other.value); }
00135
00136
00137 };
00138
00139
00140
00157 class Int_int
00158 {
00159
00160 public:
00161 int value;
00162
00163 public:
00164
00165
00166
00167
00168 explicit inline Int_int(int i = 0)
00169 {
00170 value = i;
00171 }
00172
00174 explicit inline Int_int(const Word_int& w)
00175 {
00176 this->value = w.value;
00177 }
00178
00179
00186 inline int convertToint() const
00187 {
00188 return value;
00189 }
00190
00191
00192 inline Int_int& operator++(){ ++value; return *this; }
00193 inline Int_int& operator--(){ --value; return *this; }
00194 inline Int_int& operator++ (int){ value++; return *this;}
00195 inline Int_int& operator-- (int){ value--; return *this;}
00196
00197 inline Int_int operator! () const { return Int_int(!value); }
00198
00199
00200 inline Int_int& operator=(bool i) { value=i; return *this; }
00201 inline bool operator< (const Int_int& other) const { return (value < other.value); }
00202 inline bool operator<=(const Int_int& other) const { return (value <= other.value); }
00203 inline bool operator> (const Int_int& other) const { return (value > other.value); }
00204 inline bool operator>=(const Int_int& other) const { return (value >= other.value); }
00205 inline bool operator==(const Int_int& other) const { return (value == other.value); }
00206 inline bool operator!=(const Int_int& other) const { return (value != other.value); }
00207
00208
00209 inline Int_int operator + (const Int_int& other) const { return Int_int(value + other.value); }
00210 inline Int_int operator - (const Int_int& other) const { return Int_int(value - other.value); }
00211 inline Int_int operator * (const Int_int& other) const { return Int_int(value * other.value); }
00212
00213 inline Int_int operator / (const Int_int& other) const throw (Error)
00214 {
00215 if (other.value == 0) throw Error(Error::DIVISION_BY_ZERO);
00216 return Int_int(value / other.value);
00217 }
00218
00219 inline Int_int operator % (const Int_int& other) const throw (Error)
00220 {
00221 if (other.value == 0) throw Error(Error::DIVISION_BY_ZERO);
00222 return Int_int(value % other.value);
00223 }
00224
00225 };
00226
00227
00228 Word_int::Word_int(const Int_int& i)
00229 {
00230 this->value = i.value;
00231 }
00232
00233 }
00234
00235 #endif
00236