TJS2 バイトコードを持ったオブジェクト
Inheritance: CustomObject, SourceCodeAccessor
Exemple #1
0
 public virtual bool AddTrace(InterCodeObject context, int codepos)
 {
     int len = mTrace.Length;
     if (len >= MAX_TRACE_TEXT_LEN)
     {
         return false;
     }
     if (len != 0)
     {
         mTrace += " <-- ";
     }
     mTrace += context.GetPositionDescriptionString(codepos);
     return true;
 }
Exemple #2
0
 // create a member if not exists
 // ignore property invoking
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 private ScriptBlock GenerateInterCodeObjects()
 {
     // dumpClassStructure();
     ScriptBlock block = new ScriptBlock(mOwner, mName, mLineOffset, mScript, mLineData
         );
     mInterCodeObjectList.Clear();
     // 1st. pass, まずはInterCodeObjectを作る
     int count = mInterCodeGeneratorList.Count;
     for (int i = 0; i < count; i++)
     {
         InterCodeGenerator gen = mInterCodeGeneratorList[i];
         mInterCodeObjectList.AddItem(gen.CreteCodeObject(block));
     }
     Variant val = new Variant();
     // 2nd. pass, 次にInterCodeObject内のリンクを解决する
     for (int i_1 = 0; i_1 < count; i_1++)
     {
         InterCodeGenerator gen = mInterCodeGeneratorList[i_1];
         InterCodeObject obj = mInterCodeObjectList[i_1];
         gen.CreateSecond(obj);
         gen.DateReplace(this);
         // DaraArray の中の InterCodeGenerator を InterCodeObject に差し替える
         //obj.dateReplace( this ); // DaraArray の中の InterCodeGenerator を InterCodeObject に差し替える
         AList<InterCodeGenerator.Property> p = gen.GetProp();
         if (p != null)
         {
             int pcount = p.Count;
             for (int j = 0; j < pcount; j++)
             {
                 InterCodeGenerator.Property prop = p[j];
                 val.Set(GetCodeObject(GetCodeIndex(prop.Value)));
                 obj.mParent.PropSet(MEMBERENSURE | IGNOREPROP, prop.Name, val, obj.mParent);
             }
             p.Clear();
         }
     }
     mTopLevelObject = GetCodeObject(GetCodeIndex(mTopLevelGenerator));
     block.SetObjects(mTopLevelObject, mInterCodeObjectList);
     // 解放してしまう
     mInterCodeGenerator = null;
     mTopLevelGenerator = null;
     mGeneratorStack = null;
     mInterCodeGeneratorList.Clear();
     mInterCodeGeneratorList = null;
     mInterCodeObjectList.Clear();
     mInterCodeObjectList = null;
     return block;
 }
Exemple #3
0
 public virtual int GetObjectIndex(InterCodeObject gen)
 {
     return mInterCodeObjectList.IndexOf(gen);
 }
 public virtual void CreateSecond(InterCodeObject obj)
 {
     obj.SetCodeObject(mParent != null ? mBlock.GetCodeObject(mBlock.GetCodeIndex(mParent
         )) : null, mPropSetter != null ? mBlock.GetCodeObject(mBlock.GetCodeIndex(mPropSetter
         )) : null, mPropGetter != null ? mBlock.GetCodeObject(mBlock.GetCodeIndex(mPropGetter
         )) : null, mSuperClassGetter != null ? mBlock.GetCodeObject(mBlock.GetCodeIndex(
         mSuperClassGetter)) : null);
 }
Exemple #5
0
        /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
        private void ReadObjects(ScriptBlock block, byte[] buff, int offset, int size)
        {
            string[] strarray = mStringArray;
            ByteBuffer[] bbarray = mByteBufferArray;
            double[] dblarray = mDoubleArray;
            byte[] barray = mByteArray;
            short[] sarray = mShortArray;
            int[] iarray = mIntArray;
            long[] larray = mLongArray;
            int toplevel = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                (int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                 + 3] & unchecked((int)(0xff))) << 24;
            offset += 4;
            int objcount = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                (int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                 + 3] & unchecked((int)(0xff))) << 24;
            offset += 4;
            //Log.v("test","count:"+objcount);
            mObjectsCache.Create(objcount);
            InterCodeObject[] objs = mObjectsCache.mObjs;
            AList<ByteCodeLoader.VariantRepalace> work = mObjectsCache.mWork;
            int[] parent = mObjectsCache.mParent;
            int[] propSetter = mObjectsCache.mPropSetter;
            int[] propGetter = mObjectsCache.mPropGetter;
            int[] superClassGetter = mObjectsCache.mSuperClassGetter;
            int[][] properties = mObjectsCache.mProperties;
            for (int o = 0; o < objcount; o++)
            {
                int tag = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                    (int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                     + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                if (tag != FILE_TAG_LE)
                {
                    throw new TJSException(Error.ByteCodeBroken);
                }
                //int objsize = (buff[offset]&0xff) | (buff[offset+1]&0xff) << 8 | (buff[offset+2]&0xff) << 16 | (buff[offset+3]&0xff) << 24;
                offset += 4;
                parent[o] = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                    (int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                     + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                int name = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                    (int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                     + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                int contextType = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                    (int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                     + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                int maxVariableCount = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1
                    ] & unchecked((int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) <<
                     16 | (buff[offset + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                int variableReserveCount = (buff[offset] & unchecked((int)(0xff))) | (buff[offset
                     + 1] & unchecked((int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff)
                    )) << 16 | (buff[offset + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                int maxFrameCount = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] &
                     unchecked((int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16
                     | (buff[offset + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                int funcDeclArgCount = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1
                    ] & unchecked((int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) <<
                     16 | (buff[offset + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                int funcDeclUnnamedArgArrayBase = (buff[offset] & unchecked((int)(0xff))) | (buff
                    [offset + 1] & unchecked((int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int
                    )(0xff))) << 16 | (buff[offset + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                int funcDeclCollapseBase = (buff[offset] & unchecked((int)(0xff))) | (buff[offset
                     + 1] & unchecked((int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff)
                    )) << 16 | (buff[offset + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                propSetter[o] = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                    (int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                     + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                propGetter[o] = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                    (int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                     + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                superClassGetter[o] = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1]
                     & unchecked((int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) <<
                     16 | (buff[offset + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                int count = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                    (int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                     + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                LongBuffer srcpos;
                // codePos/srcPos は今のところ使ってない、ソート济みなので、longにする必要はないが……
                offset += count << 3;
                srcpos = null;
                count = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked((
                    int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                     + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                short[] code = new short[count];
                for (int i = 0; i < count; i++)
                {
                    code[i] = (short)((buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                        (int)(0xff))) << 8);
                    offset += 2;
                }
                offset += (count & 1) << 1;
                count = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked((
                    int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                     + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                int vcount = count << 1;
                if (mVariantTypeData == null || mVariantTypeData.Length < vcount)
                {
                    mVariantTypeData = new short[vcount];
                }
                short[] data = mVariantTypeData;
                for (int i_1 = 0; i_1 < vcount; i_1++)
                {
                    data[i_1] = (short)((buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] &
                         unchecked((int)(0xff))) << 8);
                    offset += 2;
                }
                Variant[] vdata = new Variant[count];
                int datacount = count;
                Variant tmp;
                for (int i_2 = 0; i_2 < datacount; i_2++)
                {
                    int pos = i_2 << 1;
                    int type = data[pos];
                    int index = data[pos + 1];
                    switch (type)
                    {
                        case TYPE_VOID:
                        {
                            vdata[i_2] = new Variant();
                            // null
                            break;
                        }

                        case TYPE_OBJECT:
                        {
                            vdata[i_2] = new Variant(null, null);
                            // null Array Dictionary はまだサポートしていない TODO
                            break;
                        }

                        case TYPE_INTER_OBJECT:
                        {
                            tmp = new Variant();
                            work.AddItem(new ByteCodeLoader.VariantRepalace(tmp, index));
                            vdata[i_2] = tmp;
                            break;
                        }

                        case TYPE_INTER_GENERATOR:
                        {
                            tmp = new Variant();
                            work.AddItem(new ByteCodeLoader.VariantRepalace(tmp, index));
                            vdata[i_2] = tmp;
                            break;
                        }

                        case TYPE_STRING:
                        {
                            vdata[i_2] = new Variant(strarray[index]);
                            break;
                        }

                        case TYPE_OCTET:
                        {
                            vdata[i_2] = new Variant(bbarray[index]);
                            break;
                        }

                        case TYPE_REAL:
                        {
                            vdata[i_2] = new Variant(dblarray[index]);
                            break;
                        }

                        case TYPE_BYTE:
                        {
                            vdata[i_2] = new Variant(barray[index]);
                            break;
                        }

                        case TYPE_SHORT:
                        {
                            vdata[i_2] = new Variant(sarray[index]);
                            break;
                        }

                        case TYPE_INTEGER:
                        {
                            vdata[i_2] = new Variant(iarray[index]);
                            break;
                        }

                        case TYPE_LONG:
                        {
                            vdata[i_2] = new Variant(larray[index]);
                            break;
                        }

                        case TYPE_UNKNOWN:
                        default:
                        {
                            vdata[i_2] = new Variant();
                            // null;
                            break;
                            break;
                        }
                    }
                }
                count = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked((
                    int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                     + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                int[] scgetterps = new int[count];
                for (int i_3 = 0; i_3 < count; i_3++)
                {
                    scgetterps[i_3] = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                        (int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                         + 3] & unchecked((int)(0xff))) << 24;
                    offset += 4;
                }
                // properties
                count = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked((
                    int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                     + 3] & unchecked((int)(0xff))) << 24;
                offset += 4;
                if (count > 0)
                {
                    int pcount = count << 1;
                    int[] props = new int[pcount];
                    for (int i_4 = 0; i_4 < pcount; i_4++)
                    {
                        props[i_4] = (buff[offset] & unchecked((int)(0xff))) | (buff[offset + 1] & unchecked(
                            (int)(0xff))) << 8 | (buff[offset + 2] & unchecked((int)(0xff))) << 16 | (buff[offset
                             + 3] & unchecked((int)(0xff))) << 24;
                        offset += 4;
                    }
                    properties[o] = props;
                }
                //IntVector superpointer = IntVector.wrap( scgetterps );
                InterCodeObject obj = new InterCodeObject(block, mStringArray[name], contextType,
                    code, vdata, maxVariableCount, variableReserveCount, maxFrameCount, funcDeclArgCount
                    , funcDeclUnnamedArgArrayBase, funcDeclCollapseBase, true, srcpos, scgetterps);
                //objs.add(obj);
                objs[o] = obj;
            }
            Variant val = new Variant();
            for (int o_1 = 0; o_1 < objcount; o_1++)
            {
                InterCodeObject parentObj = null;
                InterCodeObject propSetterObj = null;
                InterCodeObject propGetterObj = null;
                InterCodeObject superClassGetterObj = null;
                if (parent[o_1] >= 0)
                {
                    parentObj = objs[parent[o_1]];
                }
                if (propSetter[o_1] >= 0)
                {
                    propSetterObj = objs[propSetter[o_1]];
                }
                if (propGetter[o_1] >= 0)
                {
                    propGetterObj = objs[propGetter[o_1]];
                }
                if (superClassGetter[o_1] >= 0)
                {
                    superClassGetterObj = objs[superClassGetter[o_1]];
                }
                objs[o_1].SetCodeObject(parentObj, propSetterObj, propGetterObj, superClassGetterObj
                    );
                if (properties[o_1] != null)
                {
                    InterCodeObject obj = parentObj;
                    // objs.get(o).mParent;
                    int[] prop = properties[o_1];
                    int length = (int)(((uint)prop.Length) >> 1);
                    for (int i = 0; i < length; i++)
                    {
                        int pos = i << 1;
                        int pname = prop[pos];
                        int pobj = prop[pos + 1];
                        val.Set(objs[pobj]);
                        obj.PropSet(Interface.MEMBERENSURE | Interface.IGNOREPROP, mStringArray[pname], val
                            , obj);
                    }
                    properties[o_1] = null;
                }
            }
            int count_1 = work.Count;
            for (int i_5 = 0; i_5 < count_1; i_5++)
            {
                ByteCodeLoader.VariantRepalace w = work[i_5];
                w.Work.Set(objs[w.Index]);
            }
            work.Clear();
            InterCodeObject top = null;
            if (toplevel >= 0)
            {
                top = objs[toplevel];
            }
            block.SetObjects(top, objs, objcount);
        }
Exemple #6
0
 public virtual void Add(InterCodeObject obj)
 {
     mInterCodeObjectList.AddItem(new WeakReference<InterCodeObject>(obj));
 }
Exemple #7
0
 public static void ReportExceptionSource(string msg, InterCodeObject context, int
     codepos)
 {
     if (TJS.EnableDebugMode)
     {
         TJS.OutputExceptionToConsole(msg + " at " + context.GetPositionDescriptionString(
             codepos));
     }
 }
Exemple #8
0
 public virtual void SetObjects(InterCodeObject toplevel, AList<InterCodeObject> objs
     )
 {
     mTopLevelObject = toplevel;
     mInterCodeObjectList = new AList<WeakReference<InterCodeObject>>(objs.Count);
     int count = objs.Count;
     for (int i = 0; i < count; i++)
     {
         mInterCodeObjectList.AddItem(new WeakReference<InterCodeObject>(objs[i]));
     }
 }
Exemple #9
0
 public virtual void SetObjects(InterCodeObject toplevel, InterCodeObject[] objs, 
     int count)
 {
     mTopLevelObject = toplevel;
     mInterCodeObjectList = new AList<WeakReference<InterCodeObject>>(objs.Length);
     for (int i = 0; i < count; i++)
     {
         mInterCodeObjectList.AddItem(new WeakReference<InterCodeObject>(objs[i]));
         objs[i] = null;
     }
 }
Exemple #10
0
 public virtual void Remove(InterCodeObject obj)
 {
     int count = mInterCodeObjectList.Count;
     for (int i = 0; i < count; i++)
     {
         if (mInterCodeObjectList[i].Get() == obj)
         {
             mInterCodeObjectList.Remove(i);
             break;
         }
     }
     CompactInterCodeObjectList();
 }
Exemple #11
0
 public virtual int GetObjectIndex(InterCodeObject obj)
 {
     return mInterCodeObjectList.IndexOf(new WeakReference<InterCodeObject>(obj));
 }
Exemple #12
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 /// <exception cref="Kirikiri.Tjs2.CompileException"></exception>
 public virtual void ExecuteTopLevel(Variant result, Dispatch2 context)
 {
     // compiles text and executes its global level scripts.
     // the script will be compiled as an expression if isexpressn is true.
     // 逆アセンブル
     // execute global level script
     ExecuteTopLevelScript(result, context);
     int context_count = mInterCodeObjectList.Count;
     if (context_count != 1)
     {
         // this is not a single-context script block
         // (may hook itself)
         // release all contexts and global at this time
         InterCodeObject toplevel = mTopLevelObject;
         if (mTopLevelObject != null)
         {
             mTopLevelObject = null;
         }
         Remove(toplevel);
     }
 }
Exemple #13
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 protected internal override void FinalizeObject()
 {
     if (mPropSetter != null)
     {
         mPropSetter = null;
     }
     if (mPropGetter != null)
     {
         mPropGetter = null;
     }
     if (mSuperClassGetter != null)
     {
         mSuperClassGetter = null;
     }
     mBlock.Remove(this);
     if (mContextType != ContextType.TOP_LEVEL && mBlock != null)
     {
         mBlock = null;
     }
     base.FinalizeObject();
 }
Exemple #14
0
 public virtual void SetCodeObject(Kirikiri.Tjs2.InterCodeObject parent, Kirikiri.Tjs2.InterCodeObject
     setter, Kirikiri.Tjs2.InterCodeObject getter, Kirikiri.Tjs2.InterCodeObject superclass
     )
 {
     mParent = parent;
     mPropSetter = setter;
     mPropGetter = getter;
     mSuperClassGetter = superclass;
 }