Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
sqfuncproto.h
00001 /* see copyright notice in squirrel.h */ 00002 #ifndef _SQFUNCTION_H_ 00003 #define _SQFUNCTION_H_ 00004 00005 #include "sqopcodes.h" 00006 00007 enum SQOuterType { 00008 otLOCAL = 0, 00009 otOUTER = 1 00010 }; 00011 00012 struct SQOuterVar 00013 { 00014 00015 SQOuterVar(){} 00016 SQOuterVar(const SQObjectPtr &name,const SQObjectPtr &src,SQOuterType t) 00017 { 00018 _name = name; 00019 _src=src; 00020 _type=t; 00021 } 00022 SQOuterVar(const SQOuterVar &ov) 00023 { 00024 _type=ov._type; 00025 _src=ov._src; 00026 _name=ov._name; 00027 } 00028 SQOuterType _type; 00029 SQObjectPtr _name; 00030 SQObjectPtr _src; 00031 }; 00032 00033 struct SQLocalVarInfo 00034 { 00035 SQLocalVarInfo():_start_op(0),_end_op(0),_pos(0){} 00036 SQLocalVarInfo(const SQLocalVarInfo &lvi) 00037 { 00038 _name=lvi._name; 00039 _start_op=lvi._start_op; 00040 _end_op=lvi._end_op; 00041 _pos=lvi._pos; 00042 } 00043 SQObjectPtr _name; 00044 SQUnsignedInteger _start_op; 00045 SQUnsignedInteger _end_op; 00046 SQUnsignedInteger _pos; 00047 }; 00048 00049 struct SQLineInfo { SQInteger _line;SQInteger _op; }; 00050 00051 typedef sqvector<SQOuterVar> SQOuterVarVec; 00052 typedef sqvector<SQLocalVarInfo> SQLocalVarInfoVec; 00053 typedef sqvector<SQLineInfo> SQLineInfoVec; 00054 00055 #define _FUNC_SIZE(ni,nl,nparams,nfuncs,nouters,nlineinf,localinf,defparams) (sizeof(SQFunctionProto) \ 00056 +((ni-1)*sizeof(SQInstruction))+(nl*sizeof(SQObjectPtr)) \ 00057 +(nparams*sizeof(SQObjectPtr))+(nfuncs*sizeof(SQObjectPtr)) \ 00058 +(nouters*sizeof(SQOuterVar))+(nlineinf*sizeof(SQLineInfo)) \ 00059 +(localinf*sizeof(SQLocalVarInfo))+(defparams*sizeof(SQInteger))) 00060 00061 00062 struct SQFunctionProto : public CHAINABLE_OBJ 00063 { 00064 private: 00065 SQFunctionProto(SQSharedState *ss); 00066 ~SQFunctionProto(); 00067 00068 public: 00069 static SQFunctionProto *Create(SQSharedState *ss,SQInteger ninstructions, 00070 SQInteger nliterals,SQInteger nparameters, 00071 SQInteger nfunctions,SQInteger noutervalues, 00072 SQInteger nlineinfos,SQInteger nlocalvarinfos,SQInteger ndefaultparams) 00073 { 00074 SQFunctionProto *f; 00075 //I compact the whole class and members in a single memory allocation 00076 f = (SQFunctionProto *)sq_vm_malloc(_FUNC_SIZE(ninstructions,nliterals,nparameters,nfunctions,noutervalues,nlineinfos,nlocalvarinfos,ndefaultparams)); 00077 new (f) SQFunctionProto(ss); 00078 f->_ninstructions = ninstructions; 00079 f->_literals = (SQObjectPtr*)&f->_instructions[ninstructions]; 00080 f->_nliterals = nliterals; 00081 f->_parameters = (SQObjectPtr*)&f->_literals[nliterals]; 00082 f->_nparameters = nparameters; 00083 f->_functions = (SQObjectPtr*)&f->_parameters[nparameters]; 00084 f->_nfunctions = nfunctions; 00085 f->_outervalues = (SQOuterVar*)&f->_functions[nfunctions]; 00086 f->_noutervalues = noutervalues; 00087 f->_lineinfos = (SQLineInfo *)&f->_outervalues[noutervalues]; 00088 f->_nlineinfos = nlineinfos; 00089 f->_localvarinfos = (SQLocalVarInfo *)&f->_lineinfos[nlineinfos]; 00090 f->_nlocalvarinfos = nlocalvarinfos; 00091 f->_defaultparams = (SQInteger *)&f->_localvarinfos[nlocalvarinfos]; 00092 f->_ndefaultparams = ndefaultparams; 00093 00094 _CONSTRUCT_VECTOR(SQObjectPtr,f->_nliterals,f->_literals); 00095 _CONSTRUCT_VECTOR(SQObjectPtr,f->_nparameters,f->_parameters); 00096 _CONSTRUCT_VECTOR(SQObjectPtr,f->_nfunctions,f->_functions); 00097 _CONSTRUCT_VECTOR(SQOuterVar,f->_noutervalues,f->_outervalues); 00098 //_CONSTRUCT_VECTOR(SQLineInfo,f->_nlineinfos,f->_lineinfos); //not required are 2 integers 00099 _CONSTRUCT_VECTOR(SQLocalVarInfo,f->_nlocalvarinfos,f->_localvarinfos); 00100 return f; 00101 } 00102 void Release(){ 00103 _DESTRUCT_VECTOR(SQObjectPtr,_nliterals,_literals); 00104 _DESTRUCT_VECTOR(SQObjectPtr,_nparameters,_parameters); 00105 _DESTRUCT_VECTOR(SQObjectPtr,_nfunctions,_functions); 00106 _DESTRUCT_VECTOR(SQOuterVar,_noutervalues,_outervalues); 00107 //_DESTRUCT_VECTOR(SQLineInfo,_nlineinfos,_lineinfos); //not required are 2 integers 00108 _DESTRUCT_VECTOR(SQLocalVarInfo,_nlocalvarinfos,_localvarinfos); 00109 SQInteger size = _FUNC_SIZE(_ninstructions,_nliterals,_nparameters,_nfunctions,_noutervalues,_nlineinfos,_nlocalvarinfos,_ndefaultparams); 00110 this->~SQFunctionProto(); 00111 sq_vm_free(this,size); 00112 } 00113 00114 const SQChar* GetLocal(SQVM *v,SQUnsignedInteger stackbase,SQUnsignedInteger nseq,SQUnsignedInteger nop); 00115 SQInteger GetLine(SQInstruction *curr); 00116 bool Save(SQVM *v,SQUserPointer up,SQWRITEFUNC write); 00117 static bool Load(SQVM *v,SQUserPointer up,SQREADFUNC read,SQObjectPtr &ret); 00118 #ifndef NO_GARBAGE_COLLECTOR 00119 void Mark(SQCollectable **chain); 00120 void Finalize(){ _NULL_SQOBJECT_VECTOR(_literals,_nliterals); } 00121 SQObjectType GetType() {return OT_FUNCPROTO;} 00122 #endif 00123 SQObjectPtr _sourcename; 00124 SQObjectPtr _name; 00125 SQInteger _stacksize; 00126 bool _bgenerator; 00127 SQInteger _varparams; 00128 00129 SQInteger _nlocalvarinfos; 00130 SQLocalVarInfo *_localvarinfos; 00131 00132 SQInteger _nlineinfos; 00133 SQLineInfo *_lineinfos; 00134 00135 SQInteger _nliterals; 00136 SQObjectPtr *_literals; 00137 00138 SQInteger _nparameters; 00139 SQObjectPtr *_parameters; 00140 00141 SQInteger _nfunctions; 00142 SQObjectPtr *_functions; 00143 00144 SQInteger _noutervalues; 00145 SQOuterVar *_outervalues; 00146 00147 SQInteger _ndefaultparams; 00148 SQInteger *_defaultparams; 00149 00150 SQInteger _ninstructions; 00151 SQInstruction _instructions[1]; 00152 }; 00153 00154 #endif //_SQFUNCTION_H_
Generated on Tue Jul 12 2022 21:35:49 by
