Back to home page

Enduro/X

 
 

    


0001 /*  see copyright notice in pscript.h */
0002 #ifndef _PSFUNCSTATE_H_
0003 #define _PSFUNCSTATE_H_
0004 ///////////////////////////////////

0005 #include "psutils.h"
0006 
0007 struct PSFuncState
0008 {
0009     PSFuncState(PSSharedState *ss,PSFuncState *parent,CompilerErrorFunc efunc,void *ed);
0010     ~PSFuncState();
0011 #ifdef _DEBUG_DUMP
0012     void Dump(PSFunctionProto *func);
0013 #endif
0014     void Error(const PSChar *err);
0015     PSFuncState *PushChildState(PSSharedState *ss);
0016     void PopChildState();
0017     void AddInstruction(PSOpcode _op,PSInteger arg0=0,PSInteger arg1=0,PSInteger arg2=0,PSInteger arg3=0){PSInstruction i(_op,arg0,arg1,arg2,arg3);AddInstruction(i);}
0018     void AddInstruction(PSInstruction &i);
0019     void SetIntructionParams(PSInteger pos,PSInteger arg0,PSInteger arg1,PSInteger arg2=0,PSInteger arg3=0);
0020     void SetIntructionParam(PSInteger pos,PSInteger arg,PSInteger val);
0021     PSInstruction &GetInstruction(PSInteger pos){return _instructions[pos];}
0022     void PopInstructions(PSInteger size){for(PSInteger i=0;i<size;i++)_instructions.pop_back();}
0023     void SetStackSize(PSInteger n);
0024     PSInteger CountOuters(PSInteger stacksize);
0025     void SnoozeOpt(){_optimization=false;}
0026     void AddDefaultParam(PSInteger trg) { _defaultparams.push_back(trg); }
0027     PSInteger GetDefaultParamCount() { return _defaultparams.size(); }
0028     PSInteger GetCurrentPos(){return _instructions.size()-1;}
0029     PSInteger GetNumericConstant(const PSInteger cons);
0030     PSInteger GetNumericConstant(const PSFloat cons);
0031     PSInteger PushLocalVariable(const PSObject &name);
0032     void AddParameter(const PSObject &name);
0033     //void AddOuterValue(const PSObject &name);

0034     PSInteger GetLocalVariable(const PSObject &name);
0035     void MarkLocalAsOuter(PSInteger pos);
0036     PSInteger GetOuterVariable(const PSObject &name);
0037     PSInteger GenerateCode();
0038     PSInteger GetStackSize();
0039     PSInteger CalcStackFrameSize();
0040     void AddLineInfos(PSInteger line,bool lineop,bool force=false);
0041     PSFunctionProto *BuildProto();
0042     PSInteger AllocStackPos();
0043     PSInteger PushTarget(PSInteger n=-1);
0044     PSInteger PopTarget();
0045     PSInteger TopTarget();
0046     PSInteger GetUpTarget(PSInteger n);
0047     void DiscardTarget();
0048     bool IsLocal(PSUnsignedInteger stkpos);
0049     PSObject CreateString(const PSChar *s,PSInteger len = -1);
0050     PSObject CreateTable();
0051     bool IsConstant(const PSObject &name,PSObject &e);
0052     PSInteger _returnexp;
0053     PSLocalVarInfoVec _vlocals;
0054     PSIntVec _targetstack;
0055     PSInteger _stacksize;
0056     bool _varparams;
0057     bool _bgenerator;
0058     PSIntVec _unresolvedbreaks;
0059     PSIntVec _unresolvedcontinues;
0060     PSObjectPtrVec _functions;
0061     PSObjectPtrVec _parameters;
0062     PSOuterVarVec _outervalues;
0063     PSInstructionVec _instructions;
0064     PSLocalVarInfoVec _localvarinfos;
0065     PSObjectPtr _literals;
0066     PSObjectPtr _strings;
0067     PSObjectPtr _name;
0068     PSObjectPtr _sourcename;
0069     PSInteger _nliterals;
0070     PSLineInfoVec _lineinfos;
0071     PSFuncState *_parent;
0072     PSIntVec _scope_blocks;
0073     PSIntVec _breaktargets;
0074     PSIntVec _continuetargets;
0075     PSIntVec _defaultparams;
0076     PSInteger _lastline;
0077     PSInteger _traps; //contains number of nested exception traps

0078     PSInteger _outers;
0079     bool _optimization;
0080     PSSharedState *_sharedstate;
0081     psvector<PSFuncState*> _childstates;
0082     PSInteger GetConstant(const PSObject &cons);
0083 private:
0084     CompilerErrorFunc _errfunc;
0085     void *_errtarget;
0086     PSSharedState *_ss;
0087 };
0088 
0089 
0090 #endif //_PSFUNCSTATE_H_

0091