public virtual bool AddTrace(ScriptBlock block, int srcpos) { int len = mTrace.Length; if (len >= MAX_TRACE_TEXT_LEN) { return false; } if (len != 0) { mTrace += " <-- "; } mTrace += block.GetLineDescriptionString(srcpos); return true; }
/// <exception cref="Kirikiri.Tjs2.TJSException"></exception> /// <exception cref="Kirikiri.Tjs2.VariantException"></exception> protected internal static void ThrowScriptException(Variant val, ScriptBlock block , int srcpos) { string msg = null; if (val.IsObject()) { VariantClosure clo = val.AsObjectClosure(); if (clo.mObject != null) { Variant v2 = new Variant(); string message_name = "message"; int hr = clo.PropGet(0, message_name, v2, null); if (hr >= 0) { msg = "script exception : " + v2.AsString(); } } } if (msg == null || msg.Length == 0) { msg = "script exception"; } throw new TJSScriptException(msg, block, srcpos, val); }
// 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; }
/// <summary>生成一段阶目</summary> /// <returns></returns> public virtual InterCodeObject CreteCodeObject(ScriptBlock block) { SortSourcePos(); // 常にソートして渡す LongBuffer srcPos = null; if (mSourcePosArray != null) { srcPos = LongBuffer.Wrap(mSourcePosArray); srcPos.Position(mSrcPosArrayPos); } return new InterCodeObject(block, mName, mContextType, mCode, mDataArray, mMaxVariableCount , mVariableReserveCount, mMaxFrameCount, mFuncDeclArgCount, mFuncDeclUnnamedArgArrayBase , mFuncDeclCollapseBase, mSourcePosArraySorted, srcPos, mSuperClassGetterPointer .ToArray()); }
public int PutVariant(Variant v, ScriptBlock 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_UNKNOWN: { return -1; } } return -1; }
/// <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); }
/// <exception cref="Kirikiri.Tjs2.TJSException"></exception> public virtual ScriptBlock ReadByteCode(TJS owner, string name, BinaryStream input ) { try { int size = (int)input.GetSize(); if (mReadBuffer == null || mReadBuffer.Length < size) { int buflen = size < MIN_READ_BUFFER_SIZE ? MIN_READ_BUFFER_SIZE : size; mReadBuffer = new byte[buflen]; } byte[] databuff = mReadBuffer; input.Read(databuff); input.Close(); input = null; // TJS2 int tag = (databuff[0] & unchecked((int)(0xff))) | (databuff[1] & unchecked((int) (0xff))) << 8 | (databuff[2] & unchecked((int)(0xff))) << 16 | (databuff[3] & unchecked( (int)(0xff))) << 24; if (tag != FILE_TAG_LE) { return null; } // 100'\0' int ver = (databuff[4] & unchecked((int)(0xff))) | (databuff[5] & unchecked((int) (0xff))) << 8 | (databuff[6] & unchecked((int)(0xff))) << 16 | (databuff[7] & unchecked( (int)(0xff))) << 24; if (ver != VER_TAG_LE) { return null; } int filesize = (databuff[8] & unchecked((int)(0xff))) | (databuff[9] & unchecked( (int)(0xff))) << 8 | (databuff[10] & unchecked((int)(0xff))) << 16 | (databuff[11 ] & unchecked((int)(0xff))) << 24; if (filesize != size) { return null; } //// DATA tag = (databuff[12] & unchecked((int)(0xff))) | (databuff[13] & unchecked((int)(0xff ))) << 8 | (databuff[14] & unchecked((int)(0xff))) << 16 | (databuff[15] & unchecked( (int)(0xff))) << 24; if (tag != DATA_TAG_LE) { return null; } size = (databuff[16] & unchecked((int)(0xff))) | (databuff[17] & unchecked((int)( 0xff))) << 8 | (databuff[18] & unchecked((int)(0xff))) << 16 | (databuff[19] & unchecked( (int)(0xff))) << 24; ReadDataArea(databuff, 20, size); int offset = 12 + size; // これがデータエリア后の位置 // OBJS tag = (databuff[offset] & unchecked((int)(0xff))) | (databuff[offset + 1] & unchecked( (int)(0xff))) << 8 | (databuff[offset + 2] & unchecked((int)(0xff))) << 16 | (databuff [offset + 3] & unchecked((int)(0xff))) << 24; offset += 4; if (tag != OBJ_TAG_LE) { return null; } //int objsize = ibuff.get(); int objsize = (databuff[offset] & unchecked((int)(0xff))) | (databuff[offset + 1] & unchecked((int)(0xff))) << 8 | (databuff[offset + 2] & unchecked((int)(0xff)) ) << 16 | (databuff[offset + 3] & unchecked((int)(0xff))) << 24; offset += 4; ScriptBlock block = new ScriptBlock(owner, name, 0, null, null); ReadObjects(block, databuff, offset, objsize); return block; } finally { if (mDeleteBuffer) { mReadBuffer = null; mByteArray = null; mShortArray = null; mIntArray = null; mLongArray = null; mDoubleArray = null; mDoubleTmpArray = null; mStringArray = null; mByteBufferArray = null; mObjectsCache.Release(); mVariantTypeData = null; } } }
public InterCodeObject(ScriptBlock block, string name, int type, short[] code, Variant [] da, int varcount, int verrescount, int maxframe, int argcount, int arraybase, int colbase, bool srcsorted, LongBuffer srcpos, int[] superpointer) : base(GetContextHashSize (type)) { //super.mCallFinalize = false; mBlock = block; //mBlock.add( this ); mName = name; mContextType = type; mCode = code; mDataArray = da; mMaxVariableCount = varcount; mVariableReserveCount = verrescount; mMaxFrameCount = maxframe; mFuncDeclArgCount = argcount; mFuncDeclUnnamedArgArrayBase = arraybase; mFuncDeclCollapseBase = colbase; //mSourcePosArraySorted = srcsorted; mSourcePosArray = srcpos; mSuperClassGetterPointer = superpointer; }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public virtual void Disassemble(ScriptBlock data, int start, int end) { if (mDisassembler == null) { mDisassembler = new Disassembler(mCode, mDataArray, this); } else { mDisassembler.Set(mCode, mDataArray, this); } mDisassembler.Disassemble(data, start, end); }
public TJSScriptException(string Msg, ScriptBlock block, int pos, Variant val) : base(Msg, block, pos) { mValue = val; }
/// <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(); }
/// <exception cref="Kirikiri.Tjs2.VariantException"></exception> public virtual void Disassemble(ScriptBlock data, int start, int end) { // dis-assemble the intermediate code. // "output_func" points a line output function. //String s; string msg; string com; int prevline = -1; int curline = -1; if (end <= 0) { end = mCode.Length; } if (end > mCode.Length) { end = mCode.Length; } for (int i = start; i < end; ) { msg = null; com = null; int size; int srcpos = mAccessor.CodePosToSrcPos(i); int line = mAccessor.SrcPosToLine(srcpos); // output source lines as comment if (curline == -1 || curline <= line) { if (curline == -1) { curline = line; } int nl = line - curline; while (curline <= line) { if (nl < 3 || nl >= 3 && line - curline <= 2) { //int len; string src = mAccessor.GetLine(curline); OutputFuncSrc(src, string.Empty, curline, data); curline++; } else { curline = line - 2; } } } else { if (prevline != line) { string src = mAccessor.GetLine(line); OutputFuncSrc(src, string.Empty, line, data); } } prevline = line; switch (mCode[i]) { case VM_NOP: { // decode each instructions msg = "nop"; size = 1; break; } case VM_NF: { msg = "nf"; size = 1; break; } case VM_CONST: { msg = string.Format("const %%%d, *%d", mCode[i + 1], mCode[i + 2]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 2], Utils.VariantToReadableString(mData [mCode[i + 2]])); } size = 3; break; } case VM_CP: { // instructions that // 1. have two operands that represent registers. // 2. do not have property access variants. msg = string.Format("cp %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_CEQ: { msg = string.Format("ceq %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_CDEQ: { msg = string.Format("cdeq %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_CLT: { msg = string.Format("clt %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_CGT: { msg = string.Format("cgt %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_CHKINS: { msg = string.Format("chkins %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_LOR: { // instructions that // 1. have two operands that represent registers. // 2. have property access variants msg = string.Format("lor %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_LOR + 1: { msg = string.Format("lorpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_LOR + 2: { msg = string.Format("lorpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_LOR + 3: { msg = string.Format("lorp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_LAND: { // OP2_DISASM msg = string.Format("land %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_LAND + 1: { msg = string.Format("landpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_LAND + 2: { msg = string.Format("landpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_LAND + 3: { msg = string.Format("landp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_BOR: { // OP2_DISASM msg = string.Format("bor %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_BOR + 1: { msg = string.Format("borpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_BOR + 2: { msg = string.Format("borpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_BOR + 3: { msg = string.Format("borp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_BXOR: { // OP2_DISASM msg = string.Format("bxor %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_BXOR + 1: { msg = string.Format("bxorpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_BXOR + 2: { msg = string.Format("bxorpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_BXOR + 3: { msg = string.Format("bxorp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_BAND: { // OP2_DISASM msg = string.Format("band %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_BAND + 1: { msg = string.Format("bandpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_BAND + 2: { msg = string.Format("bandpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_BAND + 3: { msg = string.Format("bandp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_SAR: { // OP2_DISASM msg = string.Format("sar %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_SAR + 1: { msg = string.Format("sarpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_SAR + 2: { msg = string.Format("sarpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_SAR + 3: { msg = string.Format("sarp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_SAL: { // OP2_DISASM msg = string.Format("sal %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_SAL + 1: { msg = string.Format("salpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_SAL + 2: { msg = string.Format("salpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_SAL + 3: { msg = string.Format("salp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_SR: { // OP2_DISASM msg = string.Format("sr %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_SR + 1: { msg = string.Format("srpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_SR + 2: { msg = string.Format("srpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_SR + 3: { msg = string.Format("srp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_ADD: { // OP2_DISASM msg = string.Format("add %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_ADD + 1: { msg = string.Format("addpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_ADD + 2: { msg = string.Format("addpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_ADD + 3: { msg = string.Format("addp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_SUB: { // OP2_DISASM msg = string.Format("sub %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_SUB + 1: { msg = string.Format("subpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_SUB + 2: { msg = string.Format("subpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_SUB + 3: { msg = string.Format("subp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_MOD: { // OP2_DISASM msg = string.Format("mod %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_MOD + 1: { msg = string.Format("modpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_MOD + 2: { msg = string.Format("modpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_MOD + 3: { msg = string.Format("modp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_DIV: { // OP2_DISASM msg = string.Format("div %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_DIV + 1: { msg = string.Format("divpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_DIV + 2: { msg = string.Format("divpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_DIV + 3: { msg = string.Format("divp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_IDIV: { // OP2_DISASM msg = string.Format("idiv %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_IDIV + 1: { msg = string.Format("idivpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_IDIV + 2: { msg = string.Format("idivpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_IDIV + 3: { msg = string.Format("idivp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_MUL: { // OP2_DISASM msg = string.Format("mul %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_MUL + 1: { msg = string.Format("mulpd %%%d, %%%d.*%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 5; break; } case VM_MUL + 2: { msg = string.Format("mulpi %%%d, %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode [i + 3], mCode[i + 4]); size = 5; break; } case VM_MUL + 3: { msg = string.Format("mulp %%%d, %%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_TT: { // OP2_DISASM // instructions that have one operand which represent a register, // except for inc, dec msg = string.Format("tt %%%d", mCode[i + 1]); size = 2; break; } case VM_TF: { msg = string.Format("tf %%%d", mCode[i + 1]); size = 2; break; } case VM_SETF: { msg = string.Format("setf %%%d", mCode[i + 1]); size = 2; break; } case VM_SETNF: { msg = string.Format("setnf %%%d", mCode[i + 1]); size = 2; break; } case VM_LNOT: { msg = string.Format("lnot %%%d", mCode[i + 1]); size = 2; break; } case VM_BNOT: { msg = string.Format("bnot %%%d", mCode[i + 1]); size = 2; break; } case VM_ASC: { msg = string.Format("asc %%%d", mCode[i + 1]); size = 2; break; } case VM_CHR: { msg = string.Format("chr %%%d", mCode[i + 1]); size = 2; break; } case VM_NUM: { msg = string.Format("num %%%d", mCode[i + 1]); size = 2; break; } case VM_CHS: { msg = string.Format("chs %%%d", mCode[i + 1]); size = 2; break; } case VM_CL: { msg = string.Format("cl %%%d", mCode[i + 1]); size = 2; break; } case VM_INV: { msg = string.Format("inv %%%d", mCode[i + 1]); size = 2; break; } case VM_CHKINV: { msg = string.Format("chkinv %%%d", mCode[i + 1]); size = 2; break; } case VM_TYPEOF: { msg = string.Format("typeof %%%d", mCode[i + 1]); size = 2; break; } case VM_EVAL: { msg = string.Format("eval %%%d", mCode[i + 1]); size = 2; break; } case VM_EEXP: { msg = string.Format("eexp %%%d", mCode[i + 1]); size = 2; break; } case VM_INT: { msg = string.Format("int %%%d", mCode[i + 1]); size = 2; break; } case VM_REAL: { msg = string.Format("real %%%d", mCode[i + 1]); size = 2; break; } case VM_STR: { msg = string.Format("str %%%d", mCode[i + 1]); size = 2; break; } case VM_OCTET: { msg = string.Format("octet %%%d", mCode[i + 1]); size = 2; break; } case VM_CCL: { msg = string.Format("ccl %%%d-%%%d", mCode[i + 1], mCode[i + 1] + mCode[i + 2] - 1); size = 3; break; } case VM_INC: { // inc and dec msg = string.Format("inc %%%d", mCode[i + 1]); size = 2; break; } case VM_INC + 1: { msg = string.Format("incpd %%%d, %%%d.*%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 4; break; } case VM_INC + 2: { msg = string.Format("incpi %%%d, %%%d.%%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_INC + 3: { msg = string.Format("incp %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_DEC: { // inc and dec msg = string.Format("dec %%%d", mCode[i + 1]); size = 2; break; } case VM_DEC + 1: { msg = string.Format("decpd %%%d, %%%d.*%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 4; break; } case VM_DEC + 2: { msg = string.Format("decpi %%%d, %%%d.%%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_DEC + 3: { msg = string.Format("decp %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_JF: { // instructions that have one operand which represents code area msg = string.Format("jf %09d", mCode[i + 1] + i); size = 2; break; } case VM_JNF: { msg = string.Format("jnf %09d", mCode[i + 1] + i); size = 2; break; } case VM_JMP: { msg = string.Format("jmp %09d", mCode[i + 1] + i); size = 2; break; } case VM_CALL: case VM_CALLD: case VM_CALLI: case VM_NEW: { // function call variants msg = string.Format(mCode[i] == VM_CALL ? "call %%%d, %%%d(" : mCode[i] == VM_CALLD ? "calld %%%d, %%%d.*%d(" : mCode[i] == VM_CALLI ? "calli %%%d, %%%d.%%%d(" : "new %%%d, %%%d(" , mCode[i + 1], mCode[i + 2], mCode[i + 3]); int st; // start of arguments if (mCode[i] == VM_CALLD || mCode[i] == VM_CALLI) { st = 5; } else { st = 4; } int num = mCode[i + st - 1]; // st-1 = argument count bool first = true; string buf = null; int c = 0; if (num == -1) { // omit arg size = st; msg += "..."; } else { if (num == -2) { // expand arg st++; num = mCode[i + st - 1]; size = st + num * 2; for (int j = 0; j < num; j++) { if (!first) { msg += ", "; } first = false; switch (mCode[i + st + j * 2]) { case fatNormal: { buf = string.Format("%%%d", mCode[i + st + j * 2 + 1]); break; } case fatExpand: { buf = string.Format("%%%d*", mCode[i + st + j * 2 + 1]); break; } case fatUnnamedExpand: { buf = "*"; break; } } msg += buf; } } else { // normal operation size = st + num; while (num > 0) { if (!first) { msg += ", "; } first = false; buf = string.Format("%%%d", mCode[i + c + st]); c++; msg += buf; num--; } } } msg += ")"; if (mData != null && mCode[i] == VM_CALLD) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } break; } case VM_GPD: case VM_GPDS: { // property get direct msg = string.Format(mCode[i] == VM_GPD ? "gpd %%%d, %%%d.*%d" : "gpds %%%d, %%%d.*%d" , mCode[i + 1], mCode[i + 2], mCode[i + 3]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 4; break; } case VM_SPD: case VM_SPDE: case VM_SPDEH: case VM_SPDS: { // property set direct msg = string.Format(mCode[i] == VM_SPD ? "spd %%%d.*%d, %%%d" : mCode[i] == VM_SPDE ? "spde %%%d.*%d, %%%d" : mCode[i] == VM_SPDEH ? "spdeh %%%d.*%d, %%%d" : "spds %%%d.*%d, %%%d" , mCode[i + 1], mCode[i + 2], mCode[i + 3]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 2], Utils.VariantToReadableString(mData [mCode[i + 2]])); } size = 4; break; } case VM_GPI: case VM_GPIS: { // property get indirect msg = string.Format(mCode[i] == VM_GPI ? "gpi %%%d, %%%d.%%%d" : "gpis %%%d, %%%d.%%%d" , mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_SPI: case VM_SPIE: case VM_SPIS: { // property set indirect msg = string.Format(mCode[i] == VM_SPI ? "spi %%%d.%%%d, %%%d" : mCode[i] == VM_SPIE ? "spie %%%d.%%%d, %%%d" : "spis %%%d.%%%d, %%%d", mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_SETP: { // property set msg = string.Format("setp %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_GETP: { // property get msg = string.Format("getp %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_DELD: case VM_TYPEOFD: { // member delete direct / typeof direct msg = string.Format(mCode[i] == VM_DELD ? "deld %%%d, %%%d.*%d" : "typeofd %%%d, %%%d.*%d" , mCode[i + 1], mCode[i + 2], mCode[i + 3]); if (mData != null) { com = string.Format("*%d = %s", mCode[i + 3], Utils.VariantToReadableString(mData [mCode[i + 3]])); } size = 4; break; } case VM_DELI: case VM_TYPEOFI: { // member delete indirect / typeof indirect msg = string.Format(mCode[i] == VM_DELI ? "deli %%%d, %%%d.%%%d" : "typeofi %%%d, %%%d.%%%d" , mCode[i + 1], mCode[i + 2], mCode[i + 3]); size = 4; break; } case VM_SRV: { // set return value msg = string.Format("srv %%%d", mCode[i + 1]); size = 2; break; } case VM_RET: { // return msg = "ret"; size = 1; break; } case VM_ENTRY: { // enter try-protected block msg = string.Format("entry %09d, %%%d", mCode[i + 1] + i, mCode[i + 2]); size = 3; break; } case VM_EXTRY: { // exit from try-protected block msg = "extry"; size = 1; break; } case VM_THROW: { msg = string.Format("throw %%%d", mCode[i + 1]); size = 2; break; } case VM_CHGTHIS: { msg = string.Format("chgthis %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_GLOBAL: { msg = string.Format("global %%%d", mCode[i + 1]); size = 2; break; } case VM_ADDCI: { msg = string.Format("addci %%%d, %%%d", mCode[i + 1], mCode[i + 2]); size = 3; break; } case VM_REGMEMBER: { msg = "regmember"; size = 1; break; } case VM_DEBUGGER: { msg = "debugger"; size = 1; break; } default: { msg = string.Format("unknown instruction %d", mCode[i]); size = 1; break; break; } } OutputFunc(msg, com, i, i, size, data); // call the callback i += size; } }
private void OutputFuncSrc(string msg, string name, int line, ScriptBlock data) { string buf; if (line >= 0) { buf = string.Format("#%s(%d) %s", name, line + 1, msg); } else { buf = string.Format("#%s %s", name, msg); } TJS.OutputToConsole(buf); }
private void OutputFunc(string msg, string comment, int addr, int codestart, int size, ScriptBlock data) { string buf = string.Format("%08d %s", addr, msg); if (comment != null) { buf += "\t// " + comment; } TJS.OutputToConsole(buf); }
public virtual void RemoveScriptBlock(ScriptBlock block) { int count = mScriptBlocks.Count; for (int i = 0; i < count; i++) { if (mScriptBlocks[i].Get() == block) { mScriptBlocks.Remove(i); break; } } CompactScriptBlock(); }
public virtual void AddScriptBlock(ScriptBlock block) { mScriptBlocks.AddItem(new WeakReference<ScriptBlock>(block)); }