6 #define _CALC_CLOSURE_SIZE(func) (sizeof(SQClosure) + (func->_noutervalues*sizeof(SQObjectPtr)) + (func->_ndefaultparams*sizeof(SQObjectPtr))) 13 SQClosure(
SQSharedState *ss,
SQFunctionProto *func){_function = func; __ObjAddRef(_function); _base = NULL; INIT_CHAIN();ADD_TO_CHAIN(&_ss(
this)->_gc_chain,
this); _env = NULL; _root=NULL;}
16 SQInteger size = _CALC_CLOSURE_SIZE(func);
20 nc->_defaultparams = &nc->_outervalues[func->_noutervalues];
22 __ObjAddRef(nc->_root);
23 _CONSTRUCT_VECTOR(
SQObjectPtr,func->_noutervalues,nc->_outervalues);
24 _CONSTRUCT_VECTOR(
SQObjectPtr,func->_ndefaultparams,nc->_defaultparams);
29 SQInteger size = _CALC_CLOSURE_SIZE(f);
30 _DESTRUCT_VECTOR(
SQObjectPtr,f->_noutervalues,_outervalues);
31 _DESTRUCT_VECTOR(
SQObjectPtr,f->_ndefaultparams,_defaultparams);
32 __ObjRelease(_function);
34 sq_vm_free(
this,size);
45 SQClosure * ret = SQClosure::Create(_opt_ss(
this),f,_root);
47 if(ret->_env) __ObjAddRef(ret->_env);
48 _COPY_VECTOR(ret->_outervalues,_outervalues,f->_noutervalues);
49 _COPY_VECTOR(ret->_defaultparams,_defaultparams,f->_ndefaultparams);
54 bool Save(
SQVM *v,SQUserPointer up,SQWRITEFUNC write);
55 static bool Load(
SQVM *v,SQUserPointer up,SQREADFUNC read,
SQObjectPtr &ret);
56 #ifndef NO_GARBAGE_COLLECTOR 60 _NULL_SQOBJECT_VECTOR(_outervalues,f->_noutervalues);
61 _NULL_SQOBJECT_VECTOR(_defaultparams,f->_ndefaultparams);
63 SQObjectType GetType() {
return OT_CLOSURE;}
87 ~
SQOuter() { REMOVE_FROM_CHAIN(&_ss(
this)->_gc_chain,
this); }
92 sq_vm_free(
this,
sizeof(
SQOuter));
95 #ifndef NO_GARBAGE_COLLECTOR 97 void Finalize() { _value.Null(); }
98 SQObjectType GetType() {
return OT_OUTER;}
110 enum SQGeneratorState{eRunning,eSuspended,eDead};
121 REMOVE_FROM_CHAIN(&_ss(
this)->_gc_chain,
this);
131 bool Yield(
SQVM *v,SQInteger target);
133 #ifndef NO_GARBAGE_COLLECTOR 135 void Finalize(){_stack.resize(0);_closure.Null();}
136 SQObjectType GetType() {
return OT_GENERATOR;}
142 SQGeneratorState _state;
145 #define _CALC_NATVIVECLOSURE_SIZE(noutervalues) (sizeof(SQNativeClosure) + (noutervalues*sizeof(SQObjectPtr))) 154 SQInteger size = _CALC_NATVIVECLOSURE_SIZE(nouters);
158 nc->_noutervalues = nouters;
159 _CONSTRUCT_VECTOR(
SQObjectPtr,nc->_noutervalues,nc->_outervalues);
164 SQNativeClosure * ret = SQNativeClosure::Create(_opt_ss(
this),_function,_noutervalues);
166 if(ret->_env) __ObjAddRef(ret->_env);
168 _COPY_VECTOR(ret->_outervalues,_outervalues,_noutervalues);
169 ret->_typecheck.copy(_typecheck);
170 ret->_nparamscheck = _nparamscheck;
176 REMOVE_FROM_CHAIN(&_ss(
this)->_gc_chain,
this);
179 SQInteger size = _CALC_NATVIVECLOSURE_SIZE(_noutervalues);
180 _DESTRUCT_VECTOR(
SQObjectPtr,_noutervalues,_outervalues);
185 #ifndef NO_GARBAGE_COLLECTOR 187 void Finalize() { _NULL_SQOBJECT_VECTOR(_outervalues,_noutervalues); }
188 SQObjectType GetType() {
return OT_NATIVECLOSURE;}
190 SQInteger _nparamscheck = 0;
193 SQUnsignedInteger _noutervalues = 0;
195 SQFUNCTION _function;
201 #endif //_SQCLOSURE_H_
Definition: sqclosure.h:10
Definition: sqclosure.h:74
Definition: sqclosure.h:108
Definition: sqobject.h:98
Definition: sqobject.h:205
Definition: sqclosure.h:147
Definition: sqfuncproto.h:49
Definition: sqobject.h:313