sqfuncstate.h 3.7 KB

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