public GetCodeIndex ( |
||
gen | ||
리턴 | int |
// 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; }
/// <summary>DaraArray の中の InterCodeGenerator を InterCodeObject に差し替える</summary> /// <param name="compiler"></param> public virtual void DateReplace(Compiler compiler) { int count = mInterCodeDataArea.Count; for (int i = 0; i < count; i++) { Variant d = mInterCodeDataArea[i]; object o = d.ToJavaObject(); if (o is InterCodeGenerator) { int idx = compiler.GetCodeIndex((InterCodeGenerator)o); if (idx < 0) { TJS.OutputToConsole("not found"); } d.Set(compiler.GetCodeObject(idx)); } } }
public int PutVariant(Variant v, Compiler block) { object o = v.ToJavaObject(); int type = GetType(v); switch (type) { case TYPE_VOID: { return 0; } case TYPE_OBJECT: { // 常に0 VariantClosure clo = (VariantClosure)o; if (clo.mObject == null && clo.mObjThis == null) { return 0; } else { // null の VariantClosure は受け入れる return -1; } goto case TYPE_INTER_OBJECT; } case TYPE_INTER_OBJECT: { // その他は入れない。Dictionary と Array は保存できるようにした方がいいが…… VariantClosure clo = (VariantClosure)o; Dispatch2 dsp = clo.mObject; return block.GetObjectIndex((InterCodeObject)dsp); } case TYPE_STRING: { return PutString(((string)o)); } case TYPE_OCTET: { return PutByteBuffer((ByteBuffer)o); } case TYPE_REAL: { return PutDouble(((Number)o)); } case TYPE_BYTE: { return PutByte(((Number)o)); } case TYPE_SHORT: { return PutShort(((Number)o)); } case TYPE_INTEGER: { return PutInteger(((Number)o)); } case TYPE_LONG: { return PutLong(((Number)o)); } case TYPE_INTER_GENERATOR: { return block.GetCodeIndex((InterCodeGenerator)o); } case TYPE_UNKNOWN: { return -1; } } return -1; }