Go to the
documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008 #pragma once
00009
00010 #include "..\kernel\value.h"
00011 #include "mxstime.h"
00012
00013
00014
00015 class Float;
00016 class Double;
00017 class Integer;
00018 class Integer64;
00019 class IntegerPtr;
00020
00021 #define FLOAT_CACHE_SIZE 1024 // must be power of 2
00022 #define DOUBLE_CACHE_SIZE 512 // " " "
00023 #define INT_CACHE_SIZE 512 // " " "
00024 #define INT64_CACHE_SIZE 128 // " " "
00025 #define LOW_INT_RANGE 100
00026
00027 extern Float* float_cache[];
00028 extern Double* double_cache[];
00029 extern Integer* int_cache[];
00030 extern Integer64* int64_cache[];
00031
00032 visible_class_debug_ok (Number)
00033
00034 class Number : public Value
00035 {
00036 public:
00037 # define is_integer_number(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(Integer) || (v)->tag == class_tag(Integer64) || (v)->tag == class_tag(IntegerPtr))
00038 # define is_float_number(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(Float) || (v)->tag == class_tag(Double))
00039 # define is_number(o) (is_integer_number(o) || is_float_number(o))
00040 classof_methods (Number, Value);
00041
00042 static Value* read(MCHAR* str, bool heapAlloc = false);
00043 static void setup();
00044
00045 #include "..\macros\define_implementations.h"
00046 def_generic( coerce, "coerce");
00047 def_generic( copy, "copy");
00048 };
00049
00050 applyable_class_debug_ok (Float)
00051 applyable_class_debug_ok (Double)
00052 applyable_class_debug_ok (Integer)
00053 applyable_class_debug_ok (Integer64)
00054 applyable_class_debug_ok (IntegerPtr)
00055 #define is_double(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(Double))
00056 #define is_integer(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(Integer))
00057 #define is_integer64(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(Integer64))
00058 #define is_integerptr(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(IntegerPtr))
00059
00060 class Float : public Number
00061 {
00062 public:
00063 float value;
00064
00065 ENABLE_STACK_ALLOCATE(Float);
00066
00067 Float() { }
00068 ScripterExport Float(float init_val);
00069
00070 static ScripterExport Value* intern(float init_val) { return new Float (init_val); }
00071 static ScripterExport Value* heap_intern(float init_val);
00072
00073 classof_methods (Float, Number);
00074 # define is_float(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(Float))
00075 void collect() { delete this; }
00076 ScripterExport void sprin1(CharStream* s);
00077
00078
00079
00080 #include "..\macros\define_implementations.h"
00081 # include "..\protocols\math.inl"
00082
00083 float to_float() { return value; }
00084 double to_double() { return static_cast<double>(value); }
00085 int to_int();
00086 INT64 to_int64() { return static_cast<INT64>(value); }
00087 INT_PTR to_intptr()
00088 {
00089 #ifndef _WIN64
00090 return to_int();
00091 #else
00092 return to_int64();
00093 #endif
00094 }
00095 TimeValue to_timevalue() { return (TimeValue)(value * GetTicksPerFrame()); }
00096 void to_fpvalue(FPValue& v) { v.f = to_float(); v.type = (ParamType2)TYPE_FLOAT; }
00097
00098 Value* widen_to(Value* arg, Value** arg_list);
00099 BOOL comparable(Value* arg) { return (is_number(arg) || is_time(arg)); }
00100
00101
00102 IOResult Save(ISave* isave);
00103 static Value* Load(ILoad* iload, USHORT chunkID, ValueLoader* vload);
00104 };
00105
00106 class Double : public Number
00107 {
00108 public:
00109 double value;
00110
00111 ENABLE_STACK_ALLOCATE(Double);
00112
00113 Double() { }
00114 ScripterExport Double(double init_val);
00115
00116 static ScripterExport Value* intern(double init_val) { return new Double (init_val); }
00117 static ScripterExport Value* heap_intern(double init_val);
00118
00119 classof_methods (Double, Number);
00120 # define is_double(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(Double))
00121 void collect() { delete this; }
00122 ScripterExport void sprin1(CharStream* s);
00123
00124
00125
00126 #include "..\macros\define_implementations.h"
00127 # include "..\protocols\math.inl"
00128
00129 float to_float() { return static_cast<float>(value); }
00130 double to_double() { return value; }
00131 int to_int();
00132 INT64 to_int64() { return static_cast<INT64>(value); }
00133 INT_PTR to_intptr()
00134 {
00135 #ifndef _WIN64
00136 return to_int();
00137 #else
00138 return to_int64();
00139 #endif
00140 }
00141 TimeValue to_timevalue() { return (TimeValue)(value * GetTicksPerFrame()); }
00142 void to_fpvalue(FPValue& v) { v.dbl = to_double(); v.type = (ParamType2)TYPE_DOUBLE; }
00143
00144 Value* widen_to(Value* arg, Value** arg_list);
00145 BOOL comparable(Value* arg) { return (is_number(arg) || is_time(arg)); }
00146
00147
00148 IOResult Save(ISave* isave);
00149 static Value* Load(ILoad* iload, USHORT chunkID, ValueLoader* vload);
00150 };
00151
00152
00153 class Integer : public Number
00154 {
00155 public:
00156 int value;
00157
00158 ENABLE_STACK_ALLOCATE(Integer);
00159
00160 Integer() { };
00161 ScripterExport Integer(int init_val);
00162
00163 static ScripterExport Value* intern(int init_val) { return new Integer (init_val); }
00164 static ScripterExport Value* heap_intern(int init_val);
00165
00166 classof_methods (Integer, Number);
00167 # define is_int(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(Integer))
00168 void collect() { delete this; }
00169 ScripterExport void sprin1(CharStream* s);
00170
00171
00172
00173 #include "..\macros\define_implementations.h"
00174 # include "..\protocols\math.inl"
00175
00176 float to_float() { return static_cast<float>(value); }
00177 double to_double() { return static_cast<double>(value); }
00178 int to_int() { return value; }
00179 INT_PTR to_intptr() { return static_cast<INT_PTR>(value); }
00180 INT64 to_int64() { return static_cast<INT64>(value); }
00181 TimeValue to_timevalue() { return (TimeValue)(value * GetTicksPerFrame()); }
00182 void to_fpvalue(FPValue& v) { v.i = to_int(); v.type = (ParamType2)TYPE_INT; }
00183
00184 Value* widen_to(Value* arg, Value** arg_list);
00185 BOOL comparable(Value* arg) { return (is_number(arg) || is_time(arg)); }
00186
00187
00188 IOResult Save(ISave* isave);
00189 static Value* Load(ILoad* iload, USHORT chunkID, ValueLoader* vload);
00190 };
00191
00192 class Integer64 : public Number
00193 {
00194 public:
00195 INT64 value;
00196
00197 ENABLE_STACK_ALLOCATE(Integer64);
00198
00199 Integer64() { };
00200 ScripterExport Integer64(INT64 init_val);
00201
00202 static ScripterExport Value* intern(INT64 init_val) { return new Integer64(init_val); }
00203 static ScripterExport Value* heap_intern(INT64 init_val);
00204
00205 classof_methods (Integer64, Number);
00206 # define is_int64(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(Integer64))
00207 void collect() { delete this; }
00208 ScripterExport void sprin1(CharStream* s);
00209
00210
00211
00212 #include "..\macros\define_implementations.h"
00213 # include "..\protocols\math.inl"
00214
00215 float to_float() { return static_cast<float>(value); }
00216 double to_double() { return static_cast<double>(value); }
00217 int to_int() { return static_cast<int>(value); }
00218 INT_PTR to_intptr() { return static_cast<INT_PTR>(value); }
00219 INT64 to_int64() { return value; }
00220 TimeValue to_timevalue() { return (TimeValue)(value * GetTicksPerFrame()); }
00221 void to_fpvalue(FPValue& v) { v.i64 = to_int64(); v.type = (ParamType2)TYPE_INT64; }
00222
00223 Value* widen_to(Value* arg, Value** arg_list);
00224 BOOL comparable(Value* arg) { return (is_number(arg) || is_time(arg)); }
00225
00226
00227 IOResult Save(ISave* isave);
00228 static Value* Load(ILoad* iload, USHORT chunkID, ValueLoader* vload);
00229 };
00230
00231
00232
00233
00234
00235
00236 class IntegerPtr : public Number
00237 {
00238 public:
00239 INT_PTR value;
00240
00241 ENABLE_STACK_ALLOCATE(IntegerPtr);
00242
00243 IntegerPtr() { };
00244 ScripterExport IntegerPtr(INT_PTR init_val);
00245
00246 static ScripterExport Value* intern(INT_PTR init_val) { return new IntegerPtr(init_val); }
00247 static ScripterExport Value* heap_intern(INT_PTR init_val);
00248
00249 classof_methods (IntegerPtr, Number);
00250 # define is_intptr(v) ((DbgVerify(!is_sourcepositionwrapper(v)), (v))->tag == class_tag(IntegerPtr))
00251 void collect() { delete this; }
00252 ScripterExport void sprin1(CharStream* s);
00253
00254
00255
00256 #include "..\macros\define_implementations.h"
00257 # include"..\protocols\math.inl"
00258
00259 float to_float() { return static_cast<float>(value); }
00260 double to_double() { return static_cast<double>(value); }
00261 int to_int() { return static_cast<int>(value); }
00262 INT_PTR to_intptr() { return value; }
00263 INT64 to_int64() { return static_cast<INT64>(value); }
00264 TimeValue to_timevalue() { return (TimeValue)(value * GetTicksPerFrame()); }
00265 void to_fpvalue(FPValue& v) { v.intptr = to_intptr(); v.type = (ParamType2)TYPE_INTPTR; }
00266
00267 Value* widen_to(Value* arg, Value** arg_list);
00268 BOOL comparable(Value* arg) { return (is_number(arg) || is_time(arg)); }
00269
00270
00271 IOResult Save(ISave* isave);
00272 static Value* Load(ILoad* iload, USHORT chunkID, ValueLoader* vload);
00273 };
00274