コード例 #1
0
ファイル: StringStream.cs プロジェクト: fantasydr/krkr-cs
 private void GenerateLineVector()
 {
     mLineVector = new IntVector();
     mLineLengthVector = new IntVector();
     int count = mText.Length;
     int lastCR = 0;
     int i;
     for (i = 0; i < count; i++)
     {
         int c = mText[i];
         if (c == CARRIAGE_RETURN || c == LINE_FEED)
         {
             mLineVector.Add(lastCR);
             mLineLengthVector.Add(i - lastCR);
             lastCR = i + 1;
             if ((i + 1) < count)
             {
                 c = mText[i + 1];
                 if (c == CARRIAGE_RETURN || c == LINE_FEED)
                 {
                     i++;
                     lastCR = i + 1;
                 }
             }
         }
     }
     if (i != lastCR)
     {
         mLineVector.Add(lastCR);
         mLineLengthVector.Add(i - lastCR);
     }
 }
コード例 #2
0
ファイル: ArrayObject.cs プロジェクト: fantasydr/krkr-cs
 public virtual int Remove(ArrayNI ni, Variant @ref, bool removeall)
 {
     int count = 0;
     IntVector todelete = new IntVector();
     int arrayCount = ni.mItems.Count;
     for (int i = 0; i < arrayCount; i++)
     {
         Variant v = ni.mItems[i];
         if (@ref.DiscernCompareInternal(v))
         {
             count++;
             todelete.Add(i);
             if (!removeall)
             {
                 break;
             }
         }
     }
     // list objects up
     int delCount = todelete.Size();
     for (int i_1 = 0; i_1 < delCount; i_1++)
     {
         int pos = todelete.Get(i_1);
         Variant v = ni.mItems[pos];
         v.Clear();
     }
     // remove items found
     for (int i_2 = delCount - 1; i_2 >= 0; i_2--)
     {
         ni.mItems.Remove(todelete.Get(i_2));
     }
     todelete = null;
     return count;
 }
コード例 #3
0
 public NestData()
 {
     // tNestType
     // union {
     // boolean IsFirstCase; 上と同じとみなす
     //};
     ContinuePatchVector = new IntVector();
     ExitPatchVector = new IntVector();
 }
コード例 #4
0
 // has expanding node
 //void addJumpList() { mJumpList.add( mCodeAreaPos ); }
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 public virtual void Commit()
 {
     // some context-related processing at final, and commits it
     if (mContextType == ContextType.CLASS)
     {
         // clean up super class proxy
         if (mSuperClassGetter != null)
         {
             mSuperClassGetter.Commit();
         }
     }
     if (mContextType != ContextType.PROPERTY && mContextType != ContextType.SUPER_CLASS_GETTER)
     {
         int lexpos = GetLexPos();
         //putCode( VM_SRV, lexpos );
         //putCode( 0 );
         if ((mCodeAreaPos + 2) >= mCodeArea.Length)
         {
             ExpandCodeArea();
         }
         if (CompileState.mEnableDebugCode)
         {
             PutSrcPos(lexpos);
         }
         mCodeArea[mCodeAreaPos] = (short)(VM_SRV);
         mCodeAreaPos++;
         mCodeArea[mCodeAreaPos] = (short)(0);
         mCodeAreaPos++;
         //putCode( VM_RET, -1 );
         mCodeArea[mCodeAreaPos] = (short)(VM_RET);
         mCodeAreaPos++;
     }
     RegisterFunction();
     if (mContextType != ContextType.PROPERTY && mContextType != ContextType.SUPER_CLASS_GETTER)
     {
         FixCode();
     }
     mDataArray = new Variant[mDataArea.Count];
     mDataArray = Sharpen.Collections.ToArray(mDataArea, mDataArray);
     mDataArea.Clear();
     mDataArea = null;
     if (mContextType == ContextType.SUPER_CLASS_GETTER)
     {
         mMaxVariableCount = 2;
     }
     else
     {
         // always 2
         mMaxVariableCount = mNamespace.GetMaxCount();
     }
     mSuperClassExpr = null;
     ClearNodesToDelete();
     mCode = new short[mCodeAreaPos];
     System.Array.Copy(mCodeArea, 0, mCode, 0, mCodeAreaPos);
     // set object type info for debugging
     // we do thus nasty thing because the std::vector does not free its storage
     // even we call 'clear' method...
     //mNodeToDeleteVector = null; mNodeToDeleteVector = new VectorWrap<ExprNode>(); 直前でクリアされているはず
     mCurrentNodeVector.Clear();
     // mCurrentNodeVector = null; mCurrentNodeVector = new VectorWrap<ExprNode>();
     mFuncArgStack = null;
     mFuncArgStack = new Stack<InterCodeGenerator.FuncArg>();
     mArrayArgStack = null;
     mArrayArgStack = new Stack<InterCodeGenerator.ArrayArg>();
     mNestVector = null;
     mNestVector = new VectorWrap<InterCodeGenerator.NestData>();
     mJumpList = null;
     mJumpList = new IntVector();
     mFixList = null;
     mFixList = new AList<InterCodeGenerator.FixData>();
     mNonLocalFunctionDeclVector = null;
     mNonLocalFunctionDeclVector = new VectorWrap<InterCodeGenerator.NonLocalFunctionDecl
         >();
 }
コード例 #5
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;
            }
        }
コード例 #6
0
        /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
        public virtual IntVector CheckJumpCode(int start, int end)
        {
            IntVector ret = new IntVector();
            short[] ca = mCode;
            if (end <= 0)
            {
                end = ca.Length;
            }
            if (end > ca.Length)
            {
                end = ca.Length;
            }
            int size = 0;
            for (int i = start; i < end; )
            {
                switch (ca[i])
                {
                    case VM_NOP:
                    {
                        size = 1;
                        break;
                    }

                    case VM_NF:
                    {
                        size = 1;
                        break;
                    }

                    case VM_CONST:
                    {
                        size = 3;
                        break;
                    }

                    case VM_CP:
                    {
                        size = 3;
                        break;
                    }

                    case VM_CEQ:
                    {
                        size = 3;
                        break;
                    }

                    case VM_CDEQ:
                    {
                        size = 3;
                        break;
                    }

                    case VM_CLT:
                    {
                        size = 3;
                        break;
                    }

                    case VM_CGT:
                    {
                        size = 3;
                        break;
                    }

                    case VM_CHKINS:
                    {
                        size = 3;
                        break;
                    }

                    case VM_LOR:
                    {
                        size = 3;
                        break;
                    }

                    case VM_LOR + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_LOR + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_LOR + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_LAND:
                    {
                        size = 3;
                        break;
                    }

                    case VM_LAND + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_LAND + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_LAND + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_BOR:
                    {
                        size = 3;
                        break;
                    }

                    case VM_BOR + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_BOR + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_BOR + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_BXOR:
                    {
                        size = 3;
                        break;
                    }

                    case VM_BXOR + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_BXOR + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_BXOR + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_BAND:
                    {
                        size = 3;
                        break;
                    }

                    case VM_BAND + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_BAND + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_BAND + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_SAR:
                    {
                        size = 3;
                        break;
                    }

                    case VM_SAR + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_SAR + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_SAR + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_SAL:
                    {
                        size = 3;
                        break;
                    }

                    case VM_SAL + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_SAL + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_SAL + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_SR:
                    {
                        size = 3;
                        break;
                    }

                    case VM_SR + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_SR + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_SR + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_ADD:
                    {
                        size = 3;
                        break;
                    }

                    case VM_ADD + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_ADD + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_ADD + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_SUB:
                    {
                        size = 3;
                        break;
                    }

                    case VM_SUB + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_SUB + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_SUB + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_MOD:
                    {
                        size = 3;
                        break;
                    }

                    case VM_MOD + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_MOD + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_MOD + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_DIV:
                    {
                        size = 3;
                        break;
                    }

                    case VM_DIV + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_DIV + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_DIV + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_IDIV:
                    {
                        size = 3;
                        break;
                    }

                    case VM_IDIV + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_IDIV + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_IDIV + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_MUL:
                    {
                        size = 3;
                        break;
                    }

                    case VM_MUL + 1:
                    {
                        size = 5;
                        break;
                    }

                    case VM_MUL + 2:
                    {
                        size = 5;
                        break;
                    }

                    case VM_MUL + 3:
                    {
                        size = 4;
                        break;
                    }

                    case VM_TT:
                    {
                        size = 2;
                        break;
                    }

                    case VM_TF:
                    {
                        size = 2;
                        break;
                    }

                    case VM_SETF:
                    {
                        size = 2;
                        break;
                    }

                    case VM_SETNF:
                    {
                        size = 2;
                        break;
                    }

                    case VM_LNOT:
                    {
                        size = 2;
                        break;
                    }

                    case VM_BNOT:
                    {
                        size = 2;
                        break;
                    }

                    case VM_ASC:
                    {
                        size = 2;
                        break;
                    }

                    case VM_CHR:
                    {
                        size = 2;
                        break;
                    }

                    case VM_NUM:
                    {
                        size = 2;
                        break;
                    }

                    case VM_CHS:
                    {
                        size = 2;
                        break;
                    }

                    case VM_CL:
                    {
                        size = 2;
                        break;
                    }

                    case VM_INV:
                    {
                        size = 2;
                        break;
                    }

                    case VM_CHKINV:
                    {
                        size = 2;
                        break;
                    }

                    case VM_TYPEOF:
                    {
                        size = 2;
                        break;
                    }

                    case VM_EVAL:
                    {
                        size = 2;
                        break;
                    }

                    case VM_EEXP:
                    {
                        size = 2;
                        break;
                    }

                    case VM_INT:
                    {
                        size = 2;
                        break;
                    }

                    case VM_REAL:
                    {
                        size = 2;
                        break;
                    }

                    case VM_STR:
                    {
                        size = 2;
                        break;
                    }

                    case VM_OCTET:
                    {
                        size = 2;
                        break;
                    }

                    case VM_CCL:
                    {
                        size = 3;
                        break;
                    }

                    case VM_INC:
                    {
                        size = 2;
                        break;
                    }

                    case VM_INC + 1:
                    {
                        size = 4;
                        break;
                    }

                    case VM_INC + 2:
                    {
                        size = 4;
                        break;
                    }

                    case VM_INC + 3:
                    {
                        size = 3;
                        break;
                    }

                    case VM_DEC:
                    {
                        size = 2;
                        break;
                    }

                    case VM_DEC + 1:
                    {
                        size = 4;
                        break;
                    }

                    case VM_DEC + 2:
                    {
                        size = 4;
                        break;
                    }

                    case VM_DEC + 3:
                    {
                        size = 3;
                        break;
                    }

                    case VM_JF:
                    {
                        ret.Add(ca[i + 1] + i);
                        size = 2;
                        break;
                    }

                    case VM_JNF:
                    {
                        ret.Add(ca[i + 1] + i);
                        size = 2;
                        break;
                    }

                    case VM_JMP:
                    {
                        ret.Add(ca[i + 1] + i);
                        size = 2;
                        break;
                    }

                    case VM_CALL:
                    case VM_CALLD:
                    case VM_CALLI:
                    case VM_NEW:
                    {
                        int st;
                        // start of arguments
                        if (ca[i] == VM_CALLD || ca[i] == VM_CALLI)
                        {
                            st = 5;
                        }
                        else
                        {
                            st = 4;
                        }
                        int num = ca[i + st - 1];
                        // st-1 = argument count
                        if (num == -1)
                        {
                            // omit arg
                            size = st;
                        }
                        else
                        {
                            if (num == -2)
                            {
                                // expand arg
                                st++;
                                num = ca[i + st - 1];
                                size = st + num * 2;
                            }
                            else
                            {
                                // normal operation
                                size = st + num;
                            }
                        }
                        break;
                    }

                    case VM_GPD:
                    case VM_GPDS:
                    {
                        size = 4;
                        break;
                    }

                    case VM_SPD:
                    case VM_SPDE:
                    case VM_SPDEH:
                    case VM_SPDS:
                    {
                        size = 4;
                        break;
                    }

                    case VM_GPI:
                    case VM_GPIS:
                    {
                        size = 4;
                        break;
                    }

                    case VM_SPI:
                    case VM_SPIE:
                    case VM_SPIS:
                    {
                        size = 4;
                        break;
                    }

                    case VM_SETP:
                    {
                        size = 3;
                        break;
                    }

                    case VM_GETP:
                    {
                        size = 3;
                        break;
                    }

                    case VM_DELD:
                    case VM_TYPEOFD:
                    {
                        size = 4;
                        break;
                    }

                    case VM_DELI:
                    case VM_TYPEOFI:
                    {
                        size = 4;
                        break;
                    }

                    case VM_SRV:
                    {
                        size = 2;
                        break;
                    }

                    case VM_RET:
                    {
                        size = 1;
                        break;
                    }

                    case VM_ENTRY:
                    {
                        ret.Add(ca[i + 1] + i);
                        // catch アドレス
                        size = 3;
                        break;
                    }

                    case VM_EXTRY:
                    {
                        size = 1;
                        break;
                    }

                    case VM_THROW:
                    {
                        size = 2;
                        break;
                    }

                    case VM_CHGTHIS:
                    {
                        size = 3;
                        break;
                    }

                    case VM_GLOBAL:
                    {
                        size = 2;
                        break;
                    }

                    case VM_ADDCI:
                    {
                        size = 3;
                        break;
                    }

                    case VM_REGMEMBER:
                    {
                        size = 1;
                        break;
                    }

                    case VM_DEBUGGER:
                    {
                        size = 1;
                        break;
                    }

                    default:
                    {
                        size = 1;
                        break;
                        break;
                    }
                }
                i += size;
            }
            return ret;
        }