Code::Blocks  SVN r11506
sqobject.cpp
Go to the documentation of this file.
1 /*
2  see copyright notice in squirrel.h
3 */
4 #include "sqpcheader.h"
5 #include "sqvm.h"
6 #include "sqstring.h"
7 #include "sqarray.h"
8 #include "sqtable.h"
9 #include "squserdata.h"
10 #include "sqfuncproto.h"
11 #include "sqclass.h"
12 #include "sqclosure.h"
13 
14 
15 const SQChar *IdType2Name(SQObjectType type)
16 {
17  switch(_RAW_TYPE(type))
18  {
19  case _RT_NULL:return _SC("null");
20  case _RT_INTEGER:return _SC("integer");
21  case _RT_FLOAT:return _SC("float");
22  case _RT_BOOL:return _SC("bool");
23  case _RT_STRING:return _SC("string");
24  case _RT_TABLE:return _SC("table");
25  case _RT_ARRAY:return _SC("array");
26  case _RT_GENERATOR:return _SC("generator");
27  case _RT_CLOSURE:
28  case _RT_NATIVECLOSURE:
29  return _SC("function");
30  case _RT_USERDATA:
31  case _RT_USERPOINTER:
32  return _SC("userdata");
33  case _RT_THREAD: return _SC("thread");
34  case _RT_FUNCPROTO: return _SC("function");
35  case _RT_CLASS: return _SC("class");
36  case _RT_INSTANCE: return _SC("instance");
37  case _RT_WEAKREF: return _SC("weakref");
38  default:
39  return NULL;
40  }
41 }
42 
43 const SQChar *GetTypeName(const SQObjectPtr &obj1)
44 {
45  return IdType2Name(type(obj1));
46 }
47 
48 SQString *SQString::Create(SQSharedState *ss,const SQChar *s,SQInteger len)
49 {
50  SQString *str=ADD_STRING(ss,s,len);
51  str->_sharedstate=ss;
52  return str;
53 }
54 
55 void SQString::Release()
56 {
57  REMOVE_STRING(_sharedstate,this);
58 }
59 
60 SQInteger SQString::Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval)
61 {
62  SQInteger idx = (SQInteger)TranslateIndex(refpos);
63  while(idx < _len){
64  outkey = (SQInteger)idx;
65  outval = SQInteger(_val[idx]);
66  //return idx for the next iteration
67  return ++idx;
68  }
69  //nothing to iterate anymore
70  return -1;
71 }
72 
73 SQUnsignedInteger TranslateIndex(const SQObjectPtr &idx)
74 {
75  switch(type(idx)){
76  case OT_NULL:
77  return 0;
78  case OT_INTEGER:
79  return (SQUnsignedInteger)_integer(idx);
80  default: assert(0); break;
81  }
82  return 0;
83 }
84 
85 SQWeakRef *SQRefCounted::GetWeakRef(SQObjectType type)
86 {
87  if(!_weakref) {
88  sq_new(_weakref,SQWeakRef);
89  _weakref->_obj._type = type;
90  _weakref->_obj._unVal.pRefCounted = this;
91  }
92  return _weakref;
93 }
94 
95 SQRefCounted::~SQRefCounted()
96 {
97  if(_weakref) {
98  _weakref->_obj._type = OT_NULL;
99  _weakref->_obj._unVal.pRefCounted = NULL;
100  }
101 }
102 
103 void SQWeakRef::Release() {
104  if(ISREFCOUNTED(_obj._type)) {
105  _obj._unVal.pRefCounted->_weakref = NULL;
106  }
107  sq_delete(this,SQWeakRef);
108 }
109 
110 bool SQDelegable::GetMetaMethod(SQVM *v,SQMetaMethod mm,SQObjectPtr &res) {
111  if(_delegate) {
112  return _delegate->Get((*_ss(v)->_metamethods)[mm],res);
113  }
114  return false;
115 }
116 
117 bool SQDelegable::SetDelegate(SQTable *mt)
118 {
119  SQTable *temp = mt;
120  if(temp == this) return false;
121  while (temp) {
122  if (temp->_delegate == this) return false; //cycle detected
123  temp = temp->_delegate;
124  }
125  if (mt) __ObjAddRef(mt);
126  __ObjRelease(_delegate);
127  _delegate = mt;
128  return true;
129 }
130 
131 bool SQGenerator::Yield(SQVM *v)
132 {
133  if(_state==eSuspended) { v->Raise_Error(_SC("internal vm error, yielding dead generator")); return false;}
134  if(_state==eDead) { v->Raise_Error(_SC("internal vm error, yielding a dead generator")); return false; }
135  SQInteger size = v->_top-v->_stackbase;
136  _ci=*v->ci;
137  _stack.resize(size);
138  for(SQInteger n =0; n<size; n++) {
139  _stack._vals[n] = v->_stack[v->_stackbase+n];
140  v->_stack[v->_stackbase+n] = _null_;
141  }
142  SQInteger nvargs = v->ci->_vargs.size;
143  SQInteger vargsbase = v->ci->_vargs.base;
144  for(SQInteger j = nvargs - 1; j >= 0; j--) {
145  _vargsstack.push_back(v->_vargsstack[vargsbase+j]);
146  }
147  _ci._generator=NULL;
148  for(SQInteger i=0;i<_ci._etraps;i++) {
149  _etraps.push_back(v->_etraps.top());
150  v->_etraps.pop_back();
151  }
152  _state=eSuspended;
153  return true;
154 }
155 
156 bool SQGenerator::Resume(SQVM *v,SQInteger target)
157 {
158  SQInteger size=_stack.size();
159  if(_state==eDead){ v->Raise_Error(_SC("resuming dead generator")); return false; }
160  if(_state==eRunning){ v->Raise_Error(_SC("resuming active generator")); return false; }
161  SQInteger prevtop=v->_top-v->_stackbase;
162  PUSH_CALLINFO(v,_ci);
163  SQInteger oldstackbase=v->_stackbase;
164  v->_stackbase = v->_top;
165  v->ci->_target = (SQInt32)target;
166  v->ci->_generator = this;
167  v->ci->_vargs.size = (unsigned short)_vargsstack.size();
168 
169  for(SQInteger i=0;i<_ci._etraps;i++) {
170  v->_etraps.push_back(_etraps.top());
171  _etraps.pop_back();
172  }
173  for(SQInteger n =0; n<size; n++) {
174  v->_stack[v->_stackbase+n] = _stack._vals[n];
175  _stack._vals[0] = _null_;
176  }
177  while(_vargsstack.size()) {
178  v->_vargsstack.push_back(_vargsstack.back());
179  _vargsstack.pop_back();
180  }
181  v->ci->_vargs.base = (unsigned short)(v->_vargsstack.size() - v->ci->_vargs.size);
182  v->_top=v->_stackbase+size;
183  v->ci->_prevtop = (SQInt32)prevtop;
184  v->ci->_prevstkbase = (SQInt32)(v->_stackbase - oldstackbase);
185  _state=eRunning;
186  if (type(v->_debughook) != OT_NULL && _rawval(v->_debughook) != _rawval(v->ci->_closure))
187  v->CallDebugHook(_SC('c'));
188 
189  return true;
190 }
191 
192 void SQArray::Extend(const SQArray *a){
193  SQInteger xlen;
194  if((xlen=a->Size()))
195  for(SQInteger i=0;i<xlen;i++)
196  Append(a->_values[i]);
197 }
198 
199 const SQChar* SQFunctionProto::GetLocal(SQVM *vm,SQUnsignedInteger stackbase,SQUnsignedInteger nseq,SQUnsignedInteger nop)
200 {
201  SQUnsignedInteger nvars=_nlocalvarinfos;
202  const SQChar *res=NULL;
203  if(nvars>=nseq){
204  for(SQUnsignedInteger i=0;i<nvars;i++){
205  if(_localvarinfos[i]._start_op<=nop && _localvarinfos[i]._end_op>=nop)
206  {
207  if(nseq==0){
208  vm->Push(vm->_stack[stackbase+_localvarinfos[i]._pos]);
209  res=_stringval(_localvarinfos[i]._name);
210  break;
211  }
212  nseq--;
213  }
214  }
215  }
216  return res;
217 }
218 
219 SQInteger SQFunctionProto::GetLine(SQInstruction *curr)
220 {
221  SQInteger op = (SQInteger)(curr-_instructions);
222  SQInteger line=_lineinfos[0]._line;
223  for(SQInteger i=1;i<_nlineinfos;i++){
224  if(_lineinfos[i]._op>=op)
225  return line;
226  line=_lineinfos[i]._line;
227  }
228  return line;
229 }
230 
231 #define _CHECK_IO(exp) { if(!exp)return false; }
232 bool SafeWrite(HSQUIRRELVM v,SQWRITEFUNC write,SQUserPointer up,SQUserPointer dest,SQInteger size)
233 {
234  if(write(up,dest,size) != size) {
235  v->Raise_Error(_SC("io error (write function failure)"));
236  return false;
237  }
238  return true;
239 }
240 
241 bool SafeRead(HSQUIRRELVM v,SQWRITEFUNC read,SQUserPointer up,SQUserPointer dest,SQInteger size)
242 {
243  if(size && read(up,dest,size) != size) {
244  v->Raise_Error(_SC("io error, read function failure, the origin stream could be corrupted/trucated"));
245  return false;
246  }
247  return true;
248 }
249 
250 bool WriteTag(HSQUIRRELVM v,SQWRITEFUNC write,SQUserPointer up,SQInteger tag)
251 {
252  return SafeWrite(v,write,up,&tag,sizeof(tag));
253 }
254 
255 bool CheckTag(HSQUIRRELVM v,SQWRITEFUNC read,SQUserPointer up,SQInteger tag)
256 {
257  SQInteger t;
258  _CHECK_IO(SafeRead(v,read,up,&t,sizeof(t)));
259  if(t != tag){
260  v->Raise_Error(_SC("invalid or corrupted closure stream"));
261  return false;
262  }
263  return true;
264 }
265 
266 bool WriteObject(HSQUIRRELVM v,SQUserPointer up,SQWRITEFUNC write,SQObjectPtr &o)
267 {
268  _CHECK_IO(SafeWrite(v,write,up,&type(o),sizeof(SQObjectType)));
269  switch(type(o)){
270  case OT_STRING:
271  _CHECK_IO(SafeWrite(v,write,up,&_string(o)->_len,sizeof(SQInteger)));
272  _CHECK_IO(SafeWrite(v,write,up,_stringval(o),rsl(_string(o)->_len)));
273  break;
274  case OT_INTEGER:
275  _CHECK_IO(SafeWrite(v,write,up,&_integer(o),sizeof(SQInteger)));break;
276  case OT_FLOAT:
277  _CHECK_IO(SafeWrite(v,write,up,&_float(o),sizeof(SQFloat)));break;
278  case OT_NULL:
279  break;
280  default:
281  v->Raise_Error(_SC("cannot serialize a %s"),GetTypeName(o));
282  return false;
283  }
284  return true;
285 }
286 
287 bool ReadObject(HSQUIRRELVM v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &o)
288 {
289  SQObjectType t;
290  _CHECK_IO(SafeRead(v,read,up,&t,sizeof(SQObjectType)));
291  switch(t){
292  case OT_STRING:{
293  SQInteger len;
294  _CHECK_IO(SafeRead(v,read,up,&len,sizeof(SQInteger)));
295  _CHECK_IO(SafeRead(v,read,up,_ss(v)->GetScratchPad(rsl(len)),rsl(len)));
296  o=SQString::Create(_ss(v),_ss(v)->GetScratchPad(-1),len);
297  }
298  break;
299  case OT_INTEGER:{
300  SQInteger i;
301  _CHECK_IO(SafeRead(v,read,up,&i,sizeof(SQInteger))); o = i; break;
302  }
303  case OT_FLOAT:{
304  SQFloat f;
305  _CHECK_IO(SafeRead(v,read,up,&f,sizeof(SQFloat))); o = f; break;
306  }
307  case OT_NULL:
308  o=_null_;
309  break;
310  default:
311  v->Raise_Error(_SC("cannot serialize a %s"),IdType2Name(t));
312  return false;
313  }
314  return true;
315 }
316 
317 bool SQClosure::Save(SQVM *v,SQUserPointer up,SQWRITEFUNC write)
318 {
319  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_HEAD));
320  _CHECK_IO(WriteTag(v,write,up,sizeof(SQChar)));
321  _CHECK_IO(_funcproto(_function)->Save(v,up,write));
322  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_TAIL));
323  return true;
324 }
325 
326 bool SQClosure::Load(SQVM *v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &ret)
327 {
328  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_HEAD));
329  _CHECK_IO(CheckTag(v,read,up,sizeof(SQChar)));
330  SQObjectPtr func;
331  _CHECK_IO(SQFunctionProto::Load(v,up,read,func));
332  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_TAIL));
333  ret = SQClosure::Create(_ss(v),_funcproto(func));
334  return true;
335 }
336 
337 bool SQFunctionProto::Save(SQVM *v,SQUserPointer up,SQWRITEFUNC write)
338 {
339  SQInteger i,nliterals = _nliterals,nparameters = _nparameters;
340  SQInteger noutervalues = _noutervalues,nlocalvarinfos = _nlocalvarinfos;
341  SQInteger nlineinfos=_nlineinfos,ninstructions = _ninstructions,nfunctions=_nfunctions;
342  SQInteger ndefaultparams = _ndefaultparams;
343  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
344  _CHECK_IO(WriteObject(v,up,write,_sourcename));
345  _CHECK_IO(WriteObject(v,up,write,_name));
346  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
347  _CHECK_IO(SafeWrite(v,write,up,&nliterals,sizeof(nliterals)));
348  _CHECK_IO(SafeWrite(v,write,up,&nparameters,sizeof(nparameters)));
349  _CHECK_IO(SafeWrite(v,write,up,&noutervalues,sizeof(noutervalues)));
350  _CHECK_IO(SafeWrite(v,write,up,&nlocalvarinfos,sizeof(nlocalvarinfos)));
351  _CHECK_IO(SafeWrite(v,write,up,&nlineinfos,sizeof(nlineinfos)));
352  _CHECK_IO(SafeWrite(v,write,up,&ndefaultparams,sizeof(ndefaultparams)));
353  _CHECK_IO(SafeWrite(v,write,up,&ninstructions,sizeof(ninstructions)));
354  _CHECK_IO(SafeWrite(v,write,up,&nfunctions,sizeof(nfunctions)));
355  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
356  for(i=0;i<nliterals;i++){
357  _CHECK_IO(WriteObject(v,up,write,_literals[i]));
358  }
359 
360  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
361  for(i=0;i<nparameters;i++){
362  _CHECK_IO(WriteObject(v,up,write,_parameters[i]));
363  }
364 
365  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
366  for(i=0;i<noutervalues;i++){
367  _CHECK_IO(SafeWrite(v,write,up,&_outervalues[i]._type,sizeof(SQUnsignedInteger)));
368  _CHECK_IO(WriteObject(v,up,write,_outervalues[i]._src));
369  _CHECK_IO(WriteObject(v,up,write,_outervalues[i]._name));
370  }
371 
372  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
373  for(i=0;i<nlocalvarinfos;i++){
374  SQLocalVarInfo &lvi=_localvarinfos[i];
375  _CHECK_IO(WriteObject(v,up,write,lvi._name));
376  _CHECK_IO(SafeWrite(v,write,up,&lvi._pos,sizeof(SQUnsignedInteger)));
377  _CHECK_IO(SafeWrite(v,write,up,&lvi._start_op,sizeof(SQUnsignedInteger)));
378  _CHECK_IO(SafeWrite(v,write,up,&lvi._end_op,sizeof(SQUnsignedInteger)));
379  }
380 
381  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
382  _CHECK_IO(SafeWrite(v,write,up,_lineinfos,sizeof(SQLineInfo)*nlineinfos));
383 
384  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
385  _CHECK_IO(SafeWrite(v,write,up,_defaultparams,sizeof(SQInteger)*ndefaultparams));
386 
387  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
388  _CHECK_IO(SafeWrite(v,write,up,_instructions,sizeof(SQInstruction)*ninstructions));
389 
390  _CHECK_IO(WriteTag(v,write,up,SQ_CLOSURESTREAM_PART));
391  for(i=0;i<nfunctions;i++){
392  _CHECK_IO(_funcproto(_functions[i])->Save(v,up,write));
393  }
394  _CHECK_IO(SafeWrite(v,write,up,&_stacksize,sizeof(_stacksize)));
395  _CHECK_IO(SafeWrite(v,write,up,&_bgenerator,sizeof(_bgenerator)));
396  _CHECK_IO(SafeWrite(v,write,up,&_varparams,sizeof(_varparams)));
397  return true;
398 }
399 
400 bool SQFunctionProto::Load(SQVM *v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &ret)
401 {
402  SQInteger i, nliterals,nparameters;
403  SQInteger noutervalues ,nlocalvarinfos ;
404  SQInteger nlineinfos,ninstructions ,nfunctions,ndefaultparams ;
405  SQObjectPtr sourcename, name;
406  SQObjectPtr o;
407  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
408  _CHECK_IO(ReadObject(v, up, read, sourcename));
409  _CHECK_IO(ReadObject(v, up, read, name));
410 
411  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
412  _CHECK_IO(SafeRead(v,read,up, &nliterals, sizeof(nliterals)));
413  _CHECK_IO(SafeRead(v,read,up, &nparameters, sizeof(nparameters)));
414  _CHECK_IO(SafeRead(v,read,up, &noutervalues, sizeof(noutervalues)));
415  _CHECK_IO(SafeRead(v,read,up, &nlocalvarinfos, sizeof(nlocalvarinfos)));
416  _CHECK_IO(SafeRead(v,read,up, &nlineinfos, sizeof(nlineinfos)));
417  _CHECK_IO(SafeRead(v,read,up, &ndefaultparams, sizeof(ndefaultparams)));
418  _CHECK_IO(SafeRead(v,read,up, &ninstructions, sizeof(ninstructions)));
419  _CHECK_IO(SafeRead(v,read,up, &nfunctions, sizeof(nfunctions)));
420 
421 
422  SQFunctionProto *f = SQFunctionProto::Create(ninstructions,nliterals,nparameters,
423  nfunctions,noutervalues,nlineinfos,nlocalvarinfos,ndefaultparams);
424  SQObjectPtr proto = f; //gets a ref in case of failure
425  f->_sourcename = sourcename;
426  f->_name = name;
427 
428  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
429 
430  for(i = 0;i < nliterals; i++){
431  _CHECK_IO(ReadObject(v, up, read, o));
432  f->_literals[i] = o;
433  }
434  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
435 
436  for(i = 0; i < nparameters; i++){
437  _CHECK_IO(ReadObject(v, up, read, o));
438  f->_parameters[i] = o;
439  }
440  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
441 
442  for(i = 0; i < noutervalues; i++){
443  SQUnsignedInteger type;
444  // C::B patch: Avoid compiler warnings about shadowing params
445  SQObjectPtr name_;
446  _CHECK_IO(SafeRead(v,read,up, &type, sizeof(SQUnsignedInteger)));
447  _CHECK_IO(ReadObject(v, up, read, o));
448  _CHECK_IO(ReadObject(v, up, read, name_));
449  f->_outervalues[i] = SQOuterVar(name_,o, (SQOuterType)type);
450  }
451  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
452 
453  for(i = 0; i < nlocalvarinfos; i++){
454  SQLocalVarInfo lvi;
455  _CHECK_IO(ReadObject(v, up, read, lvi._name));
456  _CHECK_IO(SafeRead(v,read,up, &lvi._pos, sizeof(SQUnsignedInteger)));
457  _CHECK_IO(SafeRead(v,read,up, &lvi._start_op, sizeof(SQUnsignedInteger)));
458  _CHECK_IO(SafeRead(v,read,up, &lvi._end_op, sizeof(SQUnsignedInteger)));
459  f->_localvarinfos[i] = lvi;
460  }
461  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
462  _CHECK_IO(SafeRead(v,read,up, f->_lineinfos, sizeof(SQLineInfo)*nlineinfos));
463 
464  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
465  _CHECK_IO(SafeRead(v,read,up, f->_defaultparams, sizeof(SQInteger)*ndefaultparams));
466 
467  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
468  _CHECK_IO(SafeRead(v,read,up, f->_instructions, sizeof(SQInstruction)*ninstructions));
469 
470  _CHECK_IO(CheckTag(v,read,up,SQ_CLOSURESTREAM_PART));
471  for(i = 0; i < nfunctions; i++){
472  _CHECK_IO(_funcproto(o)->Load(v, up, read, o));
473  f->_functions[i] = o;
474  }
475  _CHECK_IO(SafeRead(v,read,up, &f->_stacksize, sizeof(f->_stacksize)));
476  _CHECK_IO(SafeRead(v,read,up, &f->_bgenerator, sizeof(f->_bgenerator)));
477  _CHECK_IO(SafeRead(v,read,up, &f->_varparams, sizeof(f->_varparams)));
478 
479  ret = f;
480  return true;
481 }
482 
483 #ifndef NO_GARBAGE_COLLECTOR
484 
485 #define START_MARK() if(!(_uiRef&MARK_FLAG)){ \
486  _uiRef|=MARK_FLAG;
487 
488 #define END_MARK() RemoveFromChain(&_sharedstate->_gc_chain, this); \
489  AddToChain(chain, this); }
490 
491 void SQVM::Mark(SQCollectable **chain)
492 {
493  START_MARK()
494  SQSharedState::MarkObject(_lasterror,chain);
495  SQSharedState::MarkObject(_errorhandler,chain);
496  SQSharedState::MarkObject(_debughook,chain);
497  SQSharedState::MarkObject(_roottable, chain);
498  SQSharedState::MarkObject(temp_reg, chain);
499  for(SQUnsignedInteger i = 0; i < _stack.size(); i++) SQSharedState::MarkObject(_stack[i], chain);
500  for(SQUnsignedInteger j = 0; j < _vargsstack.size(); j++) SQSharedState::MarkObject(_vargsstack[j], chain);
501  for(SQInteger k = 0; k < _callsstacksize; k++) SQSharedState::MarkObject(_callsstack[k]._closure, chain);
502  END_MARK()
503 }
504 
505 void SQArray::Mark(SQCollectable **chain)
506 {
507  START_MARK()
508  SQInteger len = _values.size();
509  for(SQInteger i = 0;i < len; i++) SQSharedState::MarkObject(_values[i], chain);
510  END_MARK()
511 }
512 void SQTable::Mark(SQCollectable **chain)
513 {
514  START_MARK()
515  if(_delegate) _delegate->Mark(chain);
516  SQInteger len = _numofnodes;
517  for(SQInteger i = 0; i < len; i++){
518  SQSharedState::MarkObject(_nodes[i].key, chain);
519  SQSharedState::MarkObject(_nodes[i].val, chain);
520  }
521  END_MARK()
522 }
523 
524 void SQClass::Mark(SQCollectable **chain)
525 {
526  START_MARK()
527  _members->Mark(chain);
528  if(_base) _base->Mark(chain);
529  SQSharedState::MarkObject(_attributes, chain);
530  for(SQUnsignedInteger i =0; i< _defaultvalues.size(); i++) {
531  SQSharedState::MarkObject(_defaultvalues[i].val, chain);
532  SQSharedState::MarkObject(_defaultvalues[i].attrs, chain);
533  }
534  for(SQUnsignedInteger j =0; j< _methods.size(); j++) {
535  SQSharedState::MarkObject(_methods[j].val, chain);
536  SQSharedState::MarkObject(_methods[j].attrs, chain);
537  }
538  for(SQUnsignedInteger k =0; k< _metamethods.size(); k++) {
539  SQSharedState::MarkObject(_metamethods[k], chain);
540  }
541  END_MARK()
542 }
543 
544 void SQInstance::Mark(SQCollectable **chain)
545 {
546  START_MARK()
547  _class->Mark(chain);
548  SQUnsignedInteger nvalues = _class->_defaultvalues.size();
549  for(SQUnsignedInteger i =0; i< nvalues; i++) {
550  SQSharedState::MarkObject(_values[i], chain);
551  }
552  END_MARK()
553 }
554 
555 void SQGenerator::Mark(SQCollectable **chain)
556 {
557  START_MARK()
558  for(SQUnsignedInteger i = 0; i < _stack.size(); i++) SQSharedState::MarkObject(_stack[i], chain);
559  for(SQUnsignedInteger j = 0; j < _vargsstack.size(); j++) SQSharedState::MarkObject(_vargsstack[j], chain);
560  SQSharedState::MarkObject(_closure, chain);
561  END_MARK()
562 }
563 
564 void SQClosure::Mark(SQCollectable **chain)
565 {
566  START_MARK()
567  for(SQUnsignedInteger i = 0; i < _outervalues.size(); i++) SQSharedState::MarkObject(_outervalues[i], chain);
568  for(SQUnsignedInteger i = 0; i < _defaultparams.size(); i++) SQSharedState::MarkObject(_defaultparams[i], chain);
569  END_MARK()
570 }
571 
572 void SQNativeClosure::Mark(SQCollectable **chain)
573 {
574  START_MARK()
575  for(SQUnsignedInteger i = 0; i < _outervalues.size(); i++) SQSharedState::MarkObject(_outervalues[i], chain);
576  END_MARK()
577 }
578 
579 void SQUserData::Mark(SQCollectable **chain){
580  START_MARK()
581  if(_delegate) _delegate->Mark(chain);
582  END_MARK()
583 }
584 
585 void SQCollectable::UnMark() { _uiRef&=~MARK_FLAG; }
586 
587 #endif
588 
bool SafeRead(HSQUIRRELVM v, SQWRITEFUNC read, SQUserPointer up, SQUserPointer dest, SQInteger size)
Definition: sqobject.cpp:241
#define _CHECK_IO(exp)
Definition: sqobject.cpp:231
SQObjectPtr _null_
Definition: sqstate.cpp:15
bool CheckTag(HSQUIRRELVM v, SQWRITEFUNC read, SQUserPointer up, SQInteger tag)
Definition: sqobject.cpp:255
SQUnsignedInteger TranslateIndex(const SQObjectPtr &idx)
Definition: sqobject.cpp:73
bool WriteObject(HSQUIRRELVM v, SQUserPointer up, SQWRITEFUNC write, SQObjectPtr &o)
Definition: sqobject.cpp:266
const SQChar * GetTypeName(const SQObjectPtr &obj1)
Definition: sqobject.cpp:43
bool WriteTag(HSQUIRRELVM v, SQWRITEFUNC write, SQUserPointer up, SQInteger tag)
Definition: sqobject.cpp:250
bool SafeWrite(HSQUIRRELVM v, SQWRITEFUNC write, SQUserPointer up, SQUserPointer dest, SQInteger size)
Definition: sqobject.cpp:232
bool ReadObject(HSQUIRRELVM v, SQUserPointer up, SQREADFUNC read, SQObjectPtr &o)
Definition: sqobject.cpp:287
const SQChar * IdType2Name(SQObjectType type)
Definition: sqobject.cpp:15
char SQChar
#define END_MARK()
Definition: sqobject.cpp:488
#define START_MARK()
Definition: sqobject.cpp:485
#define NULL
Definition: prefix.cpp:59