1 /* see copyright notice in squirrel.h */ 2 #ifndef _SQFUNCSTATE_H_ 3 #define _SQFUNCSTATE_H_ 4 /////////////////////////////////// 5 #include "squtils.h" 6 7 struct SQFuncState 8 { 9 SQFuncState(SQSharedState *ss,SQFuncState *parent,CompilerErrorFunc efunc,void *ed); 10 ~SQFuncState(); 11 #ifdef _DEBUG_DUMP 12 void Dump(SQFunctionProto *func); 13 #endif 14 void Error(const SQChar *err); 15 SQFuncState *PushChildState(SQSharedState *ss); 16 void PopChildState(); 17 void AddInstruction(SQOpcode _op,SQInteger arg0=0,SQInteger arg1=0,SQInteger arg2=0,SQInteger arg3=0){SQInstruction i(_op,arg0,arg1,arg2,arg3);AddInstruction(i);} 18 void AddInstruction(SQInstruction &i); 19 void SetIntructionParams(SQInteger pos,SQInteger arg0,SQInteger arg1,SQInteger arg2=0,SQInteger arg3=0); 20 void SetIntructionParam(SQInteger pos,SQInteger arg,SQInteger val); GetInstructionSQFuncState21 SQInstruction &GetInstruction(SQInteger pos){return _instructions[pos];} PopInstructionsSQFuncState22 void PopInstructions(SQInteger size){for(SQInteger i=0;i<size;i++)_instructions.pop_back();} 23 void SetStackSize(SQInteger n); SnoozeOptSQFuncState24 void SnoozeOpt(){_optimization=false;} GetCurrentPosSQFuncState25 SQInteger GetCurrentPos(){return _instructions.size()-1;} 26 //SQInteger GetStringConstant(const SQChar *cons); 27 SQInteger GetNumericConstant(const SQInteger cons); 28 SQInteger GetNumericConstant(const SQFloat cons); 29 SQInteger PushLocalVariable(const SQObject &name); 30 void AddParameter(const SQObject &name); 31 void AddOuterValue(const SQObject &name); 32 SQInteger GetLocalVariable(const SQObject &name); 33 SQInteger GetOuterVariable(const SQObject &name); 34 SQInteger GenerateCode(); 35 SQInteger GetStackSize(); 36 SQInteger CalcStackFrameSize(); 37 void AddLineInfos(SQInteger line,bool lineop,bool force=false); 38 SQFunctionProto *BuildProto(); 39 SQInteger AllocStackPos(); 40 SQInteger PushTarget(SQInteger n=-1); 41 SQInteger PopTarget(); 42 SQInteger TopTarget(); 43 SQInteger GetUpTarget(SQInteger n); 44 bool IsLocal(SQUnsignedInteger stkpos); 45 SQObject CreateString(const SQChar *s,SQInteger len = -1); 46 SQInteger _returnexp; 47 SQLocalVarInfoVec _vlocals; 48 SQIntVec _targetstack; 49 SQInteger _stacksize; 50 bool _varparams; 51 bool _bgenerator; 52 SQIntVec _unresolvedbreaks; 53 SQIntVec _unresolvedcontinues; 54 SQObjectPtrVec _functions; 55 SQObjectPtrVec _parameters; 56 SQOuterVarVec _outervalues; 57 SQInstructionVec _instructions; 58 SQLocalVarInfoVec _localvarinfos; 59 SQObjectPtr _literals; 60 SQObjectPtr _strings; 61 SQObjectPtr _name; 62 SQObjectPtr _sourcename; 63 SQInteger _nliterals; 64 SQLineInfoVec _lineinfos; 65 SQFuncState *_parent; 66 SQIntVec _breaktargets; //contains number of nested exception traps 67 SQIntVec _continuetargets; 68 SQInteger _lastline; 69 SQInteger _traps; 70 bool _optimization; 71 SQSharedState *_sharedstate; 72 sqvector<SQFuncState*> _childstates; 73 SQInteger GetConstant(const SQObject &cons); 74 private: 75 CompilerErrorFunc _errfunc; 76 void *_errtarget; 77 }; 78 79 80 #endif //_SQFUNCSTATE_H_ 81 82