sqfuncstate.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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, SQInteger scope, SQInteger type=_VAR_ANY);
  31. void AddParameter(const SQObject &name, SQInteger scope, SQInteger type=_VAR_ANY);
  32. //void AddOuterValue(const SQObject &name);
  33. SQInteger GetLocalVariable(const SQObject &name);
  34. void MarkLocalAsOuter(SQInteger pos);
  35. SQInteger FindOuterVariable(const SQObject &name);
  36. SQInteger GetOuterVariable(const SQObject &name);
  37. SQInteger GenerateCode();
  38. SQInteger GetStackSize();
  39. SQInteger CalcStackFrameSize();
  40. void AddLineInfos(SQInteger line,bool lineop,bool force=false);
  41. SQFunctionProto *BuildProto();
  42. SQInteger AllocStackPos();
  43. SQInteger PushTarget(SQInteger n=-1);
  44. SQInteger PopTarget();
  45. SQInteger TopTarget();
  46. SQInteger GetUpTarget(SQInteger n);
  47. void DiscardTarget();
  48. bool IsLocal(SQUnsignedInteger stkpos);
  49. SQObject CreateString(const SQChar *s,SQInteger len = -1);
  50. SQObject CreateTable();
  51. bool IsConstant(const SQObject &name,SQObject &e);
  52. SQInteger _returnexp;
  53. SQLocalVarInfoVec _vlocals;
  54. SQIntVec _targetstack;
  55. SQInteger _stacksize;
  56. bool _varparams;
  57. bool _bgenerator;
  58. SQIntVec _unresolvedbreaks;
  59. SQIntVec _unresolvedcontinues;
  60. SQObjectPtrVec _functions;
  61. SQObjectPtrVec _parameters;
  62. SQOuterVarVec _outervalues;
  63. SQInstructionVec _instructions;
  64. SQLocalVarInfoVec _localvarinfos;
  65. SQObjectPtr _literals;
  66. SQObjectPtr _strings;
  67. SQObjectPtr _name;
  68. SQObjectPtr _sourcename;
  69. SQInteger _nliterals;
  70. SQLineInfoVec _lineinfos;
  71. SQFuncState *_parent;
  72. SQIntVec _scope_blocks;
  73. SQIntVec _breaktargets;
  74. SQIntVec _continuetargets;
  75. SQIntVec _defaultparams;
  76. SQInteger _lastline;
  77. SQInteger _traps; //contains number of nested exception traps
  78. SQInteger _outers;
  79. bool _optimization;
  80. SQSharedState *_sharedstate;
  81. sqvector<SQFuncState*> _childstates;
  82. SQInteger GetConstant(const SQObject &cons);
  83. private:
  84. CompilerErrorFunc _errfunc;
  85. void *_errtarget;
  86. SQSharedState *_ss;
  87. };
  88. #endif //_SQFUNCSTATE_H_