// VMCodes // SubType // FuncArgType // result needed // condition flag needed // true logic // inverted logic /// <summary>バイトコードを出力する</summary> /// <returns></returns> public virtual ByteBuffer ExportByteCode(Compiler block, ConstArrayData constarray ) { int parent = -1; if (mParent != null) { parent = block.GetCodeIndex(mParent); } int propSetter = -1; if (mPropSetter != null) { propSetter = block.GetCodeIndex(mPropSetter); } int propGetter = -1; if (mPropGetter != null) { propGetter = block.GetCodeIndex(mPropGetter); } int superClassGetter = -1; if (mSuperClassGetter != null) { superClassGetter = block.GetCodeIndex(mSuperClassGetter); } int name = -1; if (mName != null) { name = constarray.PutString(mName); } // 13 * 4 データ部分のサイズ //int srcpossize = mSourcePosArray != null ? mSourcePosArray.position() * 8 : 0; // mSourcePosArray は配列の方がいいかな, codepos, sorcepos の顺で、int型で登录した方がいいかも int srcpossize = 0; // 主にデバッグ用の情报なので出力抑止 int codesize = (mCode.Length % 2) == 1 ? mCode.Length * 2 + 2 : mCode.Length * 2; int datasize = mDataArray.Length * 4; int scgpsize = mSuperClassGetterPointer != null ? mSuperClassGetterPointer.Size() * 4 : 0; int propsize = (mProperties != null ? mProperties.Count * 8 : 0) + 4; int size = 12 * 4 + srcpossize + codesize + datasize + scgpsize + propsize + 4 * 4; ByteBuffer result = ByteBuffer.Allocate(size); result.Order(ByteOrder.LITTLE_ENDIAN); result.Clear(); IntBuffer buf = result.AsIntBuffer(); buf.Clear(); buf.Put(parent); buf.Put(name); buf.Put(mContextType); buf.Put(mMaxVariableCount); buf.Put(mVariableReserveCount); buf.Put(mMaxFrameCount); buf.Put(mFuncDeclArgCount); buf.Put(mFuncDeclUnnamedArgArrayBase); buf.Put(mFuncDeclCollapseBase); buf.Put(propSetter); buf.Put(propGetter); buf.Put(superClassGetter); //int count = mSourcePosArray != null ? mSourcePosArray.position() : 0; int count = 0; buf.Put(count); // 主にデバッグ用の情报なので出力抑止 count = mCode.Length; buf.Put(count); ShortBuffer sbuf = result.AsShortBuffer(); sbuf.Clear(); sbuf.Position(buf.Position() * 2); sbuf.Put(mCode); if ((count % 2) == 1) { // アライメント sbuf.Put((short)0); } buf.Position(sbuf.Position() / 2); count = mDataArray.Length; buf.Put(count); sbuf.Position(buf.Position() * 2); for (int i = 0; i < count; i++) { Variant val = mDataArray[i]; short type = constarray.GetType(val); short v = (short)constarray.PutVariant(val, block); sbuf.Put(type); sbuf.Put(v); } buf.Position(sbuf.Position() / 2); count = mSuperClassGetterPointer != null ? mSuperClassGetterPointer.Size() : 0; buf.Put(count); for (int i_1 = 0; i_1 < count; i_1++) { int v = mSuperClassGetterPointer.Get(i_1); buf.Put(v); } count = 0; if (mProperties != null) { count = mProperties.Count; buf.Put(count); if (count > 0) { for (int i_2 = 0; i_2 < count; i_2++) { InterCodeGenerator.Property prop = mProperties[i_2]; // .Value.dumpClassStructure(nest+1); int propname = constarray.PutString(prop.Name); int propobj = -1; if (prop.Value != null) { propobj = block.GetCodeIndex(prop.Value); } buf.Put(propname); buf.Put(propobj); } } } else { buf.Put(count); } result.Limit(result.Capacity()); result.Position(0); return result; }