Add() public method

public Add ( InterCodeGenerator gen ) : void
gen InterCodeGenerator
return void
Exemplo n.º 1
0
        /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
        public InterCodeGenerator(InterCodeGenerator parent, string name, Compiler block, 
            int type)
        {
            //super(getContextHashSize(type));
            //super.mCallFinalize = false;
            mNodeToDeleteVector = new VectorWrap<ExprNode>();
            mCurrentNodeVector = new VectorWrap<ExprNode>();
            mJumpList = new IntVector();
            mNestVector = new VectorWrap<InterCodeGenerator.NestData>();
            mArrayArgStack = new Stack<InterCodeGenerator.ArrayArg>();
            mFuncArgStack = new Stack<InterCodeGenerator.FuncArg>();
            mNamespace = new LocalNamespace();
            mFixList = new AList<InterCodeGenerator.FixData>();
            mNonLocalFunctionDeclVector = new VectorWrap<InterCodeGenerator.NonLocalFunctionDecl
                >();
            mSuperClassGetterPointer = new IntVector();
            mParent = parent;
            mPropGetter = mPropSetter = mSuperClassGetter = null;
            mCodeArea = new short[INC_ARRAY_COUNT];
            mDataArea = new AList<Variant>();
            mInterCodeDataArea = new AList<Variant>();
            mFrameBase = 1;
            //mSuperClassExpr = null;
            //mMaxFrameCount = 0;
            //mMaxVariableCount = 0;
            //mFuncDeclArgCount = 0;
            //mFuncDeclUnnamedArgArrayBase = 0;
            mFuncDeclCollapseBase = -1;
            //mFunctionRegisterCodePoint = 0;
            mPrevSourcePos = -1;
            //mSourcePosArraySorted = false;
            //mSourcePosArray = null;
            if (name != null && name.Length > 0)
            {
                mName = name;
            }
            //else {
            //	mName = null;
            //}
            //mAsGlobalContextMode = false;
            mContextType = type;
            switch (mContextType)
            {
                case ContextType.TOP_LEVEL:
                {
                    // decide variable reservation count with context type
                    mVariableReserveCount = 2;
                    break;
                }

                case ContextType.FUNCTION:
                {
                    mVariableReserveCount = 2;
                    break;
                }

                case ContextType.EXPR_FUNCTION:
                {
                    mVariableReserveCount = 2;
                    break;
                }

                case ContextType.PROPERTY:
                {
                    mVariableReserveCount = 0;
                    break;
                }

                case ContextType.PROPERTY_SETTER:
                {
                    mVariableReserveCount = 2;
                    break;
                }

                case ContextType.PROPERTY_GETTER:
                {
                    mVariableReserveCount = 2;
                    break;
                }

                case ContextType.CLASS:
                {
                    mVariableReserveCount = 2;
                    break;
                }

                case ContextType.SUPER_CLASS_GETTER:
                {
                    mVariableReserveCount = 2;
                    break;
                }
            }
            mBlock = block;
            mBlock.Add(this);
            if (mContextType == ContextType.CLASS)
            {
                // add class information to the class instance information
                if (mMaxFrameCount < 1)
                {
                    mMaxFrameCount = 1;
                }
                int dp = PutData(new Variant(mName));
                int lexPos = GetLexPos();
                // const %1, name
                // addci %-1, %1
                // cl %1
                if ((mCodeAreaPos + 7) >= mCodeArea.Length)
                {
                    ExpandCodeArea();
                }
                if (CompileState.mEnableDebugCode)
                {
                    PutSrcPos(lexPos);
                }
                mCodeArea[mCodeAreaPos] = (short)VM_CONST;
                mCodeAreaPos++;
                mCodeArea[mCodeAreaPos] = (short)1;
                mCodeAreaPos++;
                mCodeArea[mCodeAreaPos] = (short)dp;
                mCodeAreaPos++;
                mCodeArea[mCodeAreaPos] = (short)VM_ADDCI;
                mCodeAreaPos++;
                mCodeArea[mCodeAreaPos] = (short)-1;
                mCodeAreaPos++;
                mCodeArea[mCodeAreaPos] = (short)1;
                mCodeAreaPos++;
                mCodeArea[mCodeAreaPos] = (short)VM_CL;
                mCodeAreaPos++;
                mCodeArea[mCodeAreaPos] = (short)1;
                mCodeAreaPos++;
                // update FunctionRegisterCodePoint
                mFunctionRegisterCodePoint = mCodeAreaPos;
            }
        }