sqfuncstate.h 3.3 KB

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