The Squirrel interpreter. See http://www.squirrel-lang.org/

Dependents:   Squirrel

Committer:
jhnwkmn
Date:
Tue Dec 16 10:20:34 2014 +0000
Revision:
0:97a4f8cc534c
Initial import of Squirrel.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhnwkmn 0:97a4f8cc534c 1 /* see copyright notice in squirrel.h */
jhnwkmn 0:97a4f8cc534c 2 #ifndef _SQOBJECT_H_
jhnwkmn 0:97a4f8cc534c 3 #define _SQOBJECT_H_
jhnwkmn 0:97a4f8cc534c 4
jhnwkmn 0:97a4f8cc534c 5 #include "squtils.h"
jhnwkmn 0:97a4f8cc534c 6
jhnwkmn 0:97a4f8cc534c 7 #ifdef _SQ64
jhnwkmn 0:97a4f8cc534c 8 #define UINT_MINUS_ONE (0xFFFFFFFFFFFFFFFF)
jhnwkmn 0:97a4f8cc534c 9 #else
jhnwkmn 0:97a4f8cc534c 10 #define UINT_MINUS_ONE (0xFFFFFFFF)
jhnwkmn 0:97a4f8cc534c 11 #endif
jhnwkmn 0:97a4f8cc534c 12
jhnwkmn 0:97a4f8cc534c 13 #define SQ_CLOSURESTREAM_HEAD (('S'<<24)|('Q'<<16)|('I'<<8)|('R'))
jhnwkmn 0:97a4f8cc534c 14 #define SQ_CLOSURESTREAM_PART (('P'<<24)|('A'<<16)|('R'<<8)|('T'))
jhnwkmn 0:97a4f8cc534c 15 #define SQ_CLOSURESTREAM_TAIL (('T'<<24)|('A'<<16)|('I'<<8)|('L'))
jhnwkmn 0:97a4f8cc534c 16
jhnwkmn 0:97a4f8cc534c 17 struct SQSharedState;
jhnwkmn 0:97a4f8cc534c 18
jhnwkmn 0:97a4f8cc534c 19 enum SQMetaMethod{
jhnwkmn 0:97a4f8cc534c 20 MT_ADD=0,
jhnwkmn 0:97a4f8cc534c 21 MT_SUB=1,
jhnwkmn 0:97a4f8cc534c 22 MT_MUL=2,
jhnwkmn 0:97a4f8cc534c 23 MT_DIV=3,
jhnwkmn 0:97a4f8cc534c 24 MT_UNM=4,
jhnwkmn 0:97a4f8cc534c 25 MT_MODULO=5,
jhnwkmn 0:97a4f8cc534c 26 MT_SET=6,
jhnwkmn 0:97a4f8cc534c 27 MT_GET=7,
jhnwkmn 0:97a4f8cc534c 28 MT_TYPEOF=8,
jhnwkmn 0:97a4f8cc534c 29 MT_NEXTI=9,
jhnwkmn 0:97a4f8cc534c 30 MT_CMP=10,
jhnwkmn 0:97a4f8cc534c 31 MT_CALL=11,
jhnwkmn 0:97a4f8cc534c 32 MT_CLONED=12,
jhnwkmn 0:97a4f8cc534c 33 MT_NEWSLOT=13,
jhnwkmn 0:97a4f8cc534c 34 MT_DELSLOT=14,
jhnwkmn 0:97a4f8cc534c 35 MT_TOSTRING=15,
jhnwkmn 0:97a4f8cc534c 36 MT_NEWMEMBER=16,
jhnwkmn 0:97a4f8cc534c 37 MT_INHERITED=17,
jhnwkmn 0:97a4f8cc534c 38 MT_LAST = 18
jhnwkmn 0:97a4f8cc534c 39 };
jhnwkmn 0:97a4f8cc534c 40
jhnwkmn 0:97a4f8cc534c 41 #define MM_ADD _SC("_add")
jhnwkmn 0:97a4f8cc534c 42 #define MM_SUB _SC("_sub")
jhnwkmn 0:97a4f8cc534c 43 #define MM_MUL _SC("_mul")
jhnwkmn 0:97a4f8cc534c 44 #define MM_DIV _SC("_div")
jhnwkmn 0:97a4f8cc534c 45 #define MM_UNM _SC("_unm")
jhnwkmn 0:97a4f8cc534c 46 #define MM_MODULO _SC("_modulo")
jhnwkmn 0:97a4f8cc534c 47 #define MM_SET _SC("_set")
jhnwkmn 0:97a4f8cc534c 48 #define MM_GET _SC("_get")
jhnwkmn 0:97a4f8cc534c 49 #define MM_TYPEOF _SC("_typeof")
jhnwkmn 0:97a4f8cc534c 50 #define MM_NEXTI _SC("_nexti")
jhnwkmn 0:97a4f8cc534c 51 #define MM_CMP _SC("_cmp")
jhnwkmn 0:97a4f8cc534c 52 #define MM_CALL _SC("_call")
jhnwkmn 0:97a4f8cc534c 53 #define MM_CLONED _SC("_cloned")
jhnwkmn 0:97a4f8cc534c 54 #define MM_NEWSLOT _SC("_newslot")
jhnwkmn 0:97a4f8cc534c 55 #define MM_DELSLOT _SC("_delslot")
jhnwkmn 0:97a4f8cc534c 56 #define MM_TOSTRING _SC("_tostring")
jhnwkmn 0:97a4f8cc534c 57 #define MM_NEWMEMBER _SC("_newmember")
jhnwkmn 0:97a4f8cc534c 58 #define MM_INHERITED _SC("_inherited")
jhnwkmn 0:97a4f8cc534c 59
jhnwkmn 0:97a4f8cc534c 60
jhnwkmn 0:97a4f8cc534c 61 #define _CONSTRUCT_VECTOR(type,size,ptr) { \
jhnwkmn 0:97a4f8cc534c 62 for(SQInteger n = 0; n < ((SQInteger)size); n++) { \
jhnwkmn 0:97a4f8cc534c 63 new (&ptr[n]) type(); \
jhnwkmn 0:97a4f8cc534c 64 } \
jhnwkmn 0:97a4f8cc534c 65 }
jhnwkmn 0:97a4f8cc534c 66
jhnwkmn 0:97a4f8cc534c 67 #define _DESTRUCT_VECTOR(type,size,ptr) { \
jhnwkmn 0:97a4f8cc534c 68 for(SQInteger nl = 0; nl < ((SQInteger)size); nl++) { \
jhnwkmn 0:97a4f8cc534c 69 ptr[nl].~type(); \
jhnwkmn 0:97a4f8cc534c 70 } \
jhnwkmn 0:97a4f8cc534c 71 }
jhnwkmn 0:97a4f8cc534c 72
jhnwkmn 0:97a4f8cc534c 73 #define _COPY_VECTOR(dest,src,size) { \
jhnwkmn 0:97a4f8cc534c 74 for(SQInteger _n_ = 0; _n_ < ((SQInteger)size); _n_++) { \
jhnwkmn 0:97a4f8cc534c 75 dest[_n_] = src[_n_]; \
jhnwkmn 0:97a4f8cc534c 76 } \
jhnwkmn 0:97a4f8cc534c 77 }
jhnwkmn 0:97a4f8cc534c 78
jhnwkmn 0:97a4f8cc534c 79 #define _NULL_SQOBJECT_VECTOR(vec,size) { \
jhnwkmn 0:97a4f8cc534c 80 for(SQInteger _n_ = 0; _n_ < ((SQInteger)size); _n_++) { \
jhnwkmn 0:97a4f8cc534c 81 vec[_n_].Null(); \
jhnwkmn 0:97a4f8cc534c 82 } \
jhnwkmn 0:97a4f8cc534c 83 }
jhnwkmn 0:97a4f8cc534c 84
jhnwkmn 0:97a4f8cc534c 85 #define MINPOWER2 4
jhnwkmn 0:97a4f8cc534c 86
jhnwkmn 0:97a4f8cc534c 87 struct SQRefCounted
jhnwkmn 0:97a4f8cc534c 88 {
jhnwkmn 0:97a4f8cc534c 89 SQUnsignedInteger _uiRef;
jhnwkmn 0:97a4f8cc534c 90 struct SQWeakRef *_weakref;
jhnwkmn 0:97a4f8cc534c 91 SQRefCounted() { _uiRef = 0; _weakref = NULL; }
jhnwkmn 0:97a4f8cc534c 92 virtual ~SQRefCounted();
jhnwkmn 0:97a4f8cc534c 93 SQWeakRef *GetWeakRef(SQObjectType type);
jhnwkmn 0:97a4f8cc534c 94 virtual void Release()=0;
jhnwkmn 0:97a4f8cc534c 95
jhnwkmn 0:97a4f8cc534c 96 };
jhnwkmn 0:97a4f8cc534c 97
jhnwkmn 0:97a4f8cc534c 98 struct SQWeakRef : SQRefCounted
jhnwkmn 0:97a4f8cc534c 99 {
jhnwkmn 0:97a4f8cc534c 100 void Release();
jhnwkmn 0:97a4f8cc534c 101 SQObject _obj;
jhnwkmn 0:97a4f8cc534c 102 };
jhnwkmn 0:97a4f8cc534c 103
jhnwkmn 0:97a4f8cc534c 104 #define _realval(o) (type((o)) != OT_WEAKREF?(SQObject)o:_weakref(o)->_obj)
jhnwkmn 0:97a4f8cc534c 105
jhnwkmn 0:97a4f8cc534c 106 struct SQObjectPtr;
jhnwkmn 0:97a4f8cc534c 107
jhnwkmn 0:97a4f8cc534c 108 #define __AddRef(type,unval) if(ISREFCOUNTED(type)) \
jhnwkmn 0:97a4f8cc534c 109 { \
jhnwkmn 0:97a4f8cc534c 110 unval.pRefCounted->_uiRef++; \
jhnwkmn 0:97a4f8cc534c 111 }
jhnwkmn 0:97a4f8cc534c 112
jhnwkmn 0:97a4f8cc534c 113 #define __Release(type,unval) if(ISREFCOUNTED(type) && ((--unval.pRefCounted->_uiRef)==0)) \
jhnwkmn 0:97a4f8cc534c 114 { \
jhnwkmn 0:97a4f8cc534c 115 unval.pRefCounted->Release(); \
jhnwkmn 0:97a4f8cc534c 116 }
jhnwkmn 0:97a4f8cc534c 117
jhnwkmn 0:97a4f8cc534c 118 #define __ObjRelease(obj) { \
jhnwkmn 0:97a4f8cc534c 119 if((obj)) { \
jhnwkmn 0:97a4f8cc534c 120 (obj)->_uiRef--; \
jhnwkmn 0:97a4f8cc534c 121 if((obj)->_uiRef == 0) \
jhnwkmn 0:97a4f8cc534c 122 (obj)->Release(); \
jhnwkmn 0:97a4f8cc534c 123 (obj) = NULL; \
jhnwkmn 0:97a4f8cc534c 124 } \
jhnwkmn 0:97a4f8cc534c 125 }
jhnwkmn 0:97a4f8cc534c 126
jhnwkmn 0:97a4f8cc534c 127 #define __ObjAddRef(obj) { \
jhnwkmn 0:97a4f8cc534c 128 (obj)->_uiRef++; \
jhnwkmn 0:97a4f8cc534c 129 }
jhnwkmn 0:97a4f8cc534c 130
jhnwkmn 0:97a4f8cc534c 131 #define type(obj) ((obj)._type)
jhnwkmn 0:97a4f8cc534c 132 #define is_delegable(t) (type(t)&SQOBJECT_DELEGABLE)
jhnwkmn 0:97a4f8cc534c 133 #define raw_type(obj) _RAW_TYPE((obj)._type)
jhnwkmn 0:97a4f8cc534c 134
jhnwkmn 0:97a4f8cc534c 135 #define _integer(obj) ((obj)._unVal.nInteger)
jhnwkmn 0:97a4f8cc534c 136 #define _float(obj) ((obj)._unVal.fFloat)
jhnwkmn 0:97a4f8cc534c 137 #define _string(obj) ((obj)._unVal.pString)
jhnwkmn 0:97a4f8cc534c 138 #define _table(obj) ((obj)._unVal.pTable)
jhnwkmn 0:97a4f8cc534c 139 #define _array(obj) ((obj)._unVal.pArray)
jhnwkmn 0:97a4f8cc534c 140 #define _closure(obj) ((obj)._unVal.pClosure)
jhnwkmn 0:97a4f8cc534c 141 #define _generator(obj) ((obj)._unVal.pGenerator)
jhnwkmn 0:97a4f8cc534c 142 #define _nativeclosure(obj) ((obj)._unVal.pNativeClosure)
jhnwkmn 0:97a4f8cc534c 143 #define _userdata(obj) ((obj)._unVal.pUserData)
jhnwkmn 0:97a4f8cc534c 144 #define _userpointer(obj) ((obj)._unVal.pUserPointer)
jhnwkmn 0:97a4f8cc534c 145 #define _thread(obj) ((obj)._unVal.pThread)
jhnwkmn 0:97a4f8cc534c 146 #define _funcproto(obj) ((obj)._unVal.pFunctionProto)
jhnwkmn 0:97a4f8cc534c 147 #define _class(obj) ((obj)._unVal.pClass)
jhnwkmn 0:97a4f8cc534c 148 #define _instance(obj) ((obj)._unVal.pInstance)
jhnwkmn 0:97a4f8cc534c 149 #define _delegable(obj) ((SQDelegable *)(obj)._unVal.pDelegable)
jhnwkmn 0:97a4f8cc534c 150 #define _weakref(obj) ((obj)._unVal.pWeakRef)
jhnwkmn 0:97a4f8cc534c 151 #define _outer(obj) ((obj)._unVal.pOuter)
jhnwkmn 0:97a4f8cc534c 152 #define _refcounted(obj) ((obj)._unVal.pRefCounted)
jhnwkmn 0:97a4f8cc534c 153 #define _rawval(obj) ((obj)._unVal.raw)
jhnwkmn 0:97a4f8cc534c 154
jhnwkmn 0:97a4f8cc534c 155 #define _stringval(obj) (obj)._unVal.pString->_val
jhnwkmn 0:97a4f8cc534c 156 #define _userdataval(obj) ((SQUserPointer)sq_aligning((obj)._unVal.pUserData + 1))
jhnwkmn 0:97a4f8cc534c 157
jhnwkmn 0:97a4f8cc534c 158 #define tofloat(num) ((type(num)==OT_INTEGER)?(SQFloat)_integer(num):_float(num))
jhnwkmn 0:97a4f8cc534c 159 #define tointeger(num) ((type(num)==OT_FLOAT)?(SQInteger)_float(num):_integer(num))
jhnwkmn 0:97a4f8cc534c 160 /////////////////////////////////////////////////////////////////////////////////////
jhnwkmn 0:97a4f8cc534c 161 /////////////////////////////////////////////////////////////////////////////////////
jhnwkmn 0:97a4f8cc534c 162 #if defined(SQUSEDOUBLE) && !defined(_SQ64) || !defined(SQUSEDOUBLE) && defined(_SQ64)
jhnwkmn 0:97a4f8cc534c 163 #define SQ_REFOBJECT_INIT() SQ_OBJECT_RAWINIT()
jhnwkmn 0:97a4f8cc534c 164 #else
jhnwkmn 0:97a4f8cc534c 165 #define SQ_REFOBJECT_INIT()
jhnwkmn 0:97a4f8cc534c 166 #endif
jhnwkmn 0:97a4f8cc534c 167
jhnwkmn 0:97a4f8cc534c 168 #define _REF_TYPE_DECL(type,_class,sym) \
jhnwkmn 0:97a4f8cc534c 169 SQObjectPtr(_class * x) \
jhnwkmn 0:97a4f8cc534c 170 { \
jhnwkmn 0:97a4f8cc534c 171 SQ_OBJECT_RAWINIT() \
jhnwkmn 0:97a4f8cc534c 172 _type=type; \
jhnwkmn 0:97a4f8cc534c 173 _unVal.sym = x; \
jhnwkmn 0:97a4f8cc534c 174 assert(_unVal.pTable); \
jhnwkmn 0:97a4f8cc534c 175 _unVal.pRefCounted->_uiRef++; \
jhnwkmn 0:97a4f8cc534c 176 } \
jhnwkmn 0:97a4f8cc534c 177 inline SQObjectPtr& operator=(_class *x) \
jhnwkmn 0:97a4f8cc534c 178 { \
jhnwkmn 0:97a4f8cc534c 179 SQObjectType tOldType; \
jhnwkmn 0:97a4f8cc534c 180 SQObjectValue unOldVal; \
jhnwkmn 0:97a4f8cc534c 181 tOldType=_type; \
jhnwkmn 0:97a4f8cc534c 182 unOldVal=_unVal; \
jhnwkmn 0:97a4f8cc534c 183 _type = type; \
jhnwkmn 0:97a4f8cc534c 184 SQ_REFOBJECT_INIT() \
jhnwkmn 0:97a4f8cc534c 185 _unVal.sym = x; \
jhnwkmn 0:97a4f8cc534c 186 _unVal.pRefCounted->_uiRef++; \
jhnwkmn 0:97a4f8cc534c 187 __Release(tOldType,unOldVal); \
jhnwkmn 0:97a4f8cc534c 188 return *this; \
jhnwkmn 0:97a4f8cc534c 189 }
jhnwkmn 0:97a4f8cc534c 190
jhnwkmn 0:97a4f8cc534c 191 #define _SCALAR_TYPE_DECL(type,_class,sym) \
jhnwkmn 0:97a4f8cc534c 192 SQObjectPtr(_class x) \
jhnwkmn 0:97a4f8cc534c 193 { \
jhnwkmn 0:97a4f8cc534c 194 SQ_OBJECT_RAWINIT() \
jhnwkmn 0:97a4f8cc534c 195 _type=type; \
jhnwkmn 0:97a4f8cc534c 196 _unVal.sym = x; \
jhnwkmn 0:97a4f8cc534c 197 } \
jhnwkmn 0:97a4f8cc534c 198 inline SQObjectPtr& operator=(_class x) \
jhnwkmn 0:97a4f8cc534c 199 { \
jhnwkmn 0:97a4f8cc534c 200 __Release(_type,_unVal); \
jhnwkmn 0:97a4f8cc534c 201 _type = type; \
jhnwkmn 0:97a4f8cc534c 202 SQ_OBJECT_RAWINIT() \
jhnwkmn 0:97a4f8cc534c 203 _unVal.sym = x; \
jhnwkmn 0:97a4f8cc534c 204 return *this; \
jhnwkmn 0:97a4f8cc534c 205 }
jhnwkmn 0:97a4f8cc534c 206 struct SQObjectPtr : public SQObject
jhnwkmn 0:97a4f8cc534c 207 {
jhnwkmn 0:97a4f8cc534c 208 SQObjectPtr()
jhnwkmn 0:97a4f8cc534c 209 {
jhnwkmn 0:97a4f8cc534c 210 SQ_OBJECT_RAWINIT()
jhnwkmn 0:97a4f8cc534c 211 _type=OT_NULL;
jhnwkmn 0:97a4f8cc534c 212 _unVal.pUserPointer=NULL;
jhnwkmn 0:97a4f8cc534c 213 }
jhnwkmn 0:97a4f8cc534c 214 SQObjectPtr(const SQObjectPtr &o)
jhnwkmn 0:97a4f8cc534c 215 {
jhnwkmn 0:97a4f8cc534c 216 _type = o._type;
jhnwkmn 0:97a4f8cc534c 217 _unVal = o._unVal;
jhnwkmn 0:97a4f8cc534c 218 __AddRef(_type,_unVal);
jhnwkmn 0:97a4f8cc534c 219 }
jhnwkmn 0:97a4f8cc534c 220 SQObjectPtr(const SQObject &o)
jhnwkmn 0:97a4f8cc534c 221 {
jhnwkmn 0:97a4f8cc534c 222 _type = o._type;
jhnwkmn 0:97a4f8cc534c 223 _unVal = o._unVal;
jhnwkmn 0:97a4f8cc534c 224 __AddRef(_type,_unVal);
jhnwkmn 0:97a4f8cc534c 225 }
jhnwkmn 0:97a4f8cc534c 226 _REF_TYPE_DECL(OT_TABLE,SQTable,pTable)
jhnwkmn 0:97a4f8cc534c 227 _REF_TYPE_DECL(OT_CLASS,SQClass,pClass)
jhnwkmn 0:97a4f8cc534c 228 _REF_TYPE_DECL(OT_INSTANCE,SQInstance,pInstance)
jhnwkmn 0:97a4f8cc534c 229 _REF_TYPE_DECL(OT_ARRAY,SQArray,pArray)
jhnwkmn 0:97a4f8cc534c 230 _REF_TYPE_DECL(OT_CLOSURE,SQClosure,pClosure)
jhnwkmn 0:97a4f8cc534c 231 _REF_TYPE_DECL(OT_NATIVECLOSURE,SQNativeClosure,pNativeClosure)
jhnwkmn 0:97a4f8cc534c 232 _REF_TYPE_DECL(OT_OUTER,SQOuter,pOuter)
jhnwkmn 0:97a4f8cc534c 233 _REF_TYPE_DECL(OT_GENERATOR,SQGenerator,pGenerator)
jhnwkmn 0:97a4f8cc534c 234 _REF_TYPE_DECL(OT_STRING,SQString,pString)
jhnwkmn 0:97a4f8cc534c 235 _REF_TYPE_DECL(OT_USERDATA,SQUserData,pUserData)
jhnwkmn 0:97a4f8cc534c 236 _REF_TYPE_DECL(OT_WEAKREF,SQWeakRef,pWeakRef)
jhnwkmn 0:97a4f8cc534c 237 _REF_TYPE_DECL(OT_THREAD,SQVM,pThread)
jhnwkmn 0:97a4f8cc534c 238 _REF_TYPE_DECL(OT_FUNCPROTO,SQFunctionProto,pFunctionProto)
jhnwkmn 0:97a4f8cc534c 239
jhnwkmn 0:97a4f8cc534c 240 _SCALAR_TYPE_DECL(OT_INTEGER,SQInteger,nInteger)
jhnwkmn 0:97a4f8cc534c 241 _SCALAR_TYPE_DECL(OT_FLOAT,SQFloat,fFloat)
jhnwkmn 0:97a4f8cc534c 242 _SCALAR_TYPE_DECL(OT_USERPOINTER,SQUserPointer,pUserPointer)
jhnwkmn 0:97a4f8cc534c 243
jhnwkmn 0:97a4f8cc534c 244 SQObjectPtr(bool bBool)
jhnwkmn 0:97a4f8cc534c 245 {
jhnwkmn 0:97a4f8cc534c 246 SQ_OBJECT_RAWINIT()
jhnwkmn 0:97a4f8cc534c 247 _type = OT_BOOL;
jhnwkmn 0:97a4f8cc534c 248 _unVal.nInteger = bBool?1:0;
jhnwkmn 0:97a4f8cc534c 249 }
jhnwkmn 0:97a4f8cc534c 250 inline SQObjectPtr& operator=(bool b)
jhnwkmn 0:97a4f8cc534c 251 {
jhnwkmn 0:97a4f8cc534c 252 __Release(_type,_unVal);
jhnwkmn 0:97a4f8cc534c 253 SQ_OBJECT_RAWINIT()
jhnwkmn 0:97a4f8cc534c 254 _type = OT_BOOL;
jhnwkmn 0:97a4f8cc534c 255 _unVal.nInteger = b?1:0;
jhnwkmn 0:97a4f8cc534c 256 return *this;
jhnwkmn 0:97a4f8cc534c 257 }
jhnwkmn 0:97a4f8cc534c 258
jhnwkmn 0:97a4f8cc534c 259 ~SQObjectPtr()
jhnwkmn 0:97a4f8cc534c 260 {
jhnwkmn 0:97a4f8cc534c 261 __Release(_type,_unVal);
jhnwkmn 0:97a4f8cc534c 262 }
jhnwkmn 0:97a4f8cc534c 263
jhnwkmn 0:97a4f8cc534c 264 inline SQObjectPtr& operator=(const SQObjectPtr& obj)
jhnwkmn 0:97a4f8cc534c 265 {
jhnwkmn 0:97a4f8cc534c 266 SQObjectType tOldType;
jhnwkmn 0:97a4f8cc534c 267 SQObjectValue unOldVal;
jhnwkmn 0:97a4f8cc534c 268 tOldType=_type;
jhnwkmn 0:97a4f8cc534c 269 unOldVal=_unVal;
jhnwkmn 0:97a4f8cc534c 270 _unVal = obj._unVal;
jhnwkmn 0:97a4f8cc534c 271 _type = obj._type;
jhnwkmn 0:97a4f8cc534c 272 __AddRef(_type,_unVal);
jhnwkmn 0:97a4f8cc534c 273 __Release(tOldType,unOldVal);
jhnwkmn 0:97a4f8cc534c 274 return *this;
jhnwkmn 0:97a4f8cc534c 275 }
jhnwkmn 0:97a4f8cc534c 276 inline SQObjectPtr& operator=(const SQObject& obj)
jhnwkmn 0:97a4f8cc534c 277 {
jhnwkmn 0:97a4f8cc534c 278 SQObjectType tOldType;
jhnwkmn 0:97a4f8cc534c 279 SQObjectValue unOldVal;
jhnwkmn 0:97a4f8cc534c 280 tOldType=_type;
jhnwkmn 0:97a4f8cc534c 281 unOldVal=_unVal;
jhnwkmn 0:97a4f8cc534c 282 _unVal = obj._unVal;
jhnwkmn 0:97a4f8cc534c 283 _type = obj._type;
jhnwkmn 0:97a4f8cc534c 284 __AddRef(_type,_unVal);
jhnwkmn 0:97a4f8cc534c 285 __Release(tOldType,unOldVal);
jhnwkmn 0:97a4f8cc534c 286 return *this;
jhnwkmn 0:97a4f8cc534c 287 }
jhnwkmn 0:97a4f8cc534c 288 inline void Null()
jhnwkmn 0:97a4f8cc534c 289 {
jhnwkmn 0:97a4f8cc534c 290 SQObjectType tOldType = _type;
jhnwkmn 0:97a4f8cc534c 291 SQObjectValue unOldVal = _unVal;
jhnwkmn 0:97a4f8cc534c 292 _type = OT_NULL;
jhnwkmn 0:97a4f8cc534c 293 _unVal.raw = (SQRawObjectVal)NULL;
jhnwkmn 0:97a4f8cc534c 294 __Release(tOldType ,unOldVal);
jhnwkmn 0:97a4f8cc534c 295 }
jhnwkmn 0:97a4f8cc534c 296 private:
jhnwkmn 0:97a4f8cc534c 297 SQObjectPtr(const SQChar *){} //safety
jhnwkmn 0:97a4f8cc534c 298 };
jhnwkmn 0:97a4f8cc534c 299
jhnwkmn 0:97a4f8cc534c 300
jhnwkmn 0:97a4f8cc534c 301 inline void _Swap(SQObject &a,SQObject &b)
jhnwkmn 0:97a4f8cc534c 302 {
jhnwkmn 0:97a4f8cc534c 303 SQObjectType tOldType = a._type;
jhnwkmn 0:97a4f8cc534c 304 SQObjectValue unOldVal = a._unVal;
jhnwkmn 0:97a4f8cc534c 305 a._type = b._type;
jhnwkmn 0:97a4f8cc534c 306 a._unVal = b._unVal;
jhnwkmn 0:97a4f8cc534c 307 b._type = tOldType;
jhnwkmn 0:97a4f8cc534c 308 b._unVal = unOldVal;
jhnwkmn 0:97a4f8cc534c 309 }
jhnwkmn 0:97a4f8cc534c 310
jhnwkmn 0:97a4f8cc534c 311 /////////////////////////////////////////////////////////////////////////////////////
jhnwkmn 0:97a4f8cc534c 312 #ifndef NO_GARBAGE_COLLECTOR
jhnwkmn 0:97a4f8cc534c 313 #define MARK_FLAG 0x80000000
jhnwkmn 0:97a4f8cc534c 314 struct SQCollectable : public SQRefCounted {
jhnwkmn 0:97a4f8cc534c 315 SQCollectable *_next;
jhnwkmn 0:97a4f8cc534c 316 SQCollectable *_prev;
jhnwkmn 0:97a4f8cc534c 317 SQSharedState *_sharedstate;
jhnwkmn 0:97a4f8cc534c 318 virtual SQObjectType GetType()=0;
jhnwkmn 0:97a4f8cc534c 319 virtual void Release()=0;
jhnwkmn 0:97a4f8cc534c 320 virtual void Mark(SQCollectable **chain)=0;
jhnwkmn 0:97a4f8cc534c 321 void UnMark();
jhnwkmn 0:97a4f8cc534c 322 virtual void Finalize()=0;
jhnwkmn 0:97a4f8cc534c 323 static void AddToChain(SQCollectable **chain,SQCollectable *c);
jhnwkmn 0:97a4f8cc534c 324 static void RemoveFromChain(SQCollectable **chain,SQCollectable *c);
jhnwkmn 0:97a4f8cc534c 325 };
jhnwkmn 0:97a4f8cc534c 326
jhnwkmn 0:97a4f8cc534c 327
jhnwkmn 0:97a4f8cc534c 328 #define ADD_TO_CHAIN(chain,obj) AddToChain(chain,obj)
jhnwkmn 0:97a4f8cc534c 329 #define REMOVE_FROM_CHAIN(chain,obj) {if(!(_uiRef&MARK_FLAG))RemoveFromChain(chain,obj);}
jhnwkmn 0:97a4f8cc534c 330 #define CHAINABLE_OBJ SQCollectable
jhnwkmn 0:97a4f8cc534c 331 #define INIT_CHAIN() {_next=NULL;_prev=NULL;_sharedstate=ss;}
jhnwkmn 0:97a4f8cc534c 332 #else
jhnwkmn 0:97a4f8cc534c 333
jhnwkmn 0:97a4f8cc534c 334 #define ADD_TO_CHAIN(chain,obj) ((void)0)
jhnwkmn 0:97a4f8cc534c 335 #define REMOVE_FROM_CHAIN(chain,obj) ((void)0)
jhnwkmn 0:97a4f8cc534c 336 #define CHAINABLE_OBJ SQRefCounted
jhnwkmn 0:97a4f8cc534c 337 #define INIT_CHAIN() ((void)0)
jhnwkmn 0:97a4f8cc534c 338 #endif
jhnwkmn 0:97a4f8cc534c 339
jhnwkmn 0:97a4f8cc534c 340 struct SQDelegable : public CHAINABLE_OBJ {
jhnwkmn 0:97a4f8cc534c 341 bool SetDelegate(SQTable *m);
jhnwkmn 0:97a4f8cc534c 342 virtual bool GetMetaMethod(SQVM *v,SQMetaMethod mm,SQObjectPtr &res);
jhnwkmn 0:97a4f8cc534c 343 SQTable *_delegate;
jhnwkmn 0:97a4f8cc534c 344 };
jhnwkmn 0:97a4f8cc534c 345
jhnwkmn 0:97a4f8cc534c 346 SQUnsignedInteger TranslateIndex(const SQObjectPtr &idx);
jhnwkmn 0:97a4f8cc534c 347 typedef sqvector<SQObjectPtr> SQObjectPtrVec;
jhnwkmn 0:97a4f8cc534c 348 typedef sqvector<SQInteger> SQIntVec;
jhnwkmn 0:97a4f8cc534c 349 const SQChar *GetTypeName(const SQObjectPtr &obj1);
jhnwkmn 0:97a4f8cc534c 350 const SQChar *IdType2Name(SQObjectType type);
jhnwkmn 0:97a4f8cc534c 351
jhnwkmn 0:97a4f8cc534c 352
jhnwkmn 0:97a4f8cc534c 353
jhnwkmn 0:97a4f8cc534c 354 #endif //_SQOBJECT_H_