/// <exception cref="Kirikiri.Tjs2.TJSException"></exception> private void ExportByteCode(BinaryStream output) { byte[] filetag = FILE_TAG; byte[] codetag = new byte[] { (byte)('T'), (byte)('J'), (byte)('S'), (byte)('2') }; byte[] objtag = new byte[] { (byte)('O'), (byte)('B'), (byte)('J'), (byte)('S') }; byte[] datatag = new byte[] { (byte)('D'), (byte)('A'), (byte)('T'), (byte)('A') }; int count = mInterCodeGeneratorList.Count; AList<ByteBuffer> objarray = new AList<ByteBuffer>(count * 2); ConstArrayData constarray = new ConstArrayData(); int objsize = 0; for (int i = 0; i < count; i++) { InterCodeGenerator obj = mInterCodeGeneratorList[i]; ByteBuffer buf = obj.ExportByteCode(this, constarray); objarray.AddItem(buf); objsize += buf.Capacity() + TAG_SIZE + CHUNK_SIZE_LEN; } // tag + size objsize += TAG_SIZE + CHUNK_SIZE_LEN + 4 + 4; // OBJS tag + size + toplevel + count ByteBuffer dataarea = constarray.ExportBuffer(); int datasize = dataarea.Capacity() + TAG_SIZE + CHUNK_SIZE_LEN; // DATA tag + size int filesize = objsize + datasize + FILE_TAG_SIZE + CHUNK_SIZE_LEN; // TJS2 tag + file size byte[] filesizearray = new byte[] { unchecked((byte)(filesize & unchecked((int)(0xff )))), unchecked((byte)(((int)(((uint)filesize) >> 8)) & unchecked((int)(0xff)))) , unchecked((byte)(((int)(((uint)filesize) >> 16)) & unchecked((int)(0xff)))), unchecked( (byte)(((int)(((uint)filesize) >> 24)) & unchecked((int)(0xff)))) }; byte[] datasizearray = new byte[] { unchecked((byte)(datasize & unchecked((int)(0xff )))), unchecked((byte)(((int)(((uint)datasize) >> 8)) & unchecked((int)(0xff)))) , unchecked((byte)(((int)(((uint)datasize) >> 16)) & unchecked((int)(0xff)))), unchecked( (byte)(((int)(((uint)datasize) >> 24)) & unchecked((int)(0xff)))) }; byte[] objsizearray = new byte[] { unchecked((byte)(objsize & unchecked((int)(0xff )))), unchecked((byte)(((int)(((uint)objsize) >> 8)) & unchecked((int)(0xff)))), unchecked((byte)(((int)(((uint)objsize) >> 16)) & unchecked((int)(0xff)))), unchecked( (byte)(((int)(((uint)objsize) >> 24)) & unchecked((int)(0xff)))) }; byte[] objcountarray = new byte[] { unchecked((byte)(count & unchecked((int)(0xff )))), unchecked((byte)(((int)(((uint)count) >> 8)) & unchecked((int)(0xff)))), unchecked( (byte)(((int)(((uint)count) >> 16)) & unchecked((int)(0xff)))), unchecked((byte) (((int)(((uint)count) >> 24)) & unchecked((int)(0xff)))) }; int toplevel = -1; if (mTopLevelGenerator != null) { toplevel = GetCodeIndex(mTopLevelGenerator); } byte[] toparray = new byte[] { unchecked((byte)(toplevel & unchecked((int)(0xff)) )), unchecked((byte)(((int)(((uint)toplevel) >> 8)) & unchecked((int)(0xff)))), unchecked((byte)(((int)(((uint)toplevel) >> 16)) & unchecked((int)(0xff)))), unchecked( (byte)(((int)(((uint)toplevel) >> 24)) & unchecked((int)(0xff)))) }; output.Write(filetag); output.Write(filesizearray); output.Write(datatag); output.Write(datasizearray); output.Write(dataarea); output.Write(objtag); output.Write(objsizearray); output.Write(toparray); output.Write(objcountarray); for (int i_1 = 0; i_1 < count; i_1++) { ByteBuffer buf = objarray[i_1]; int size = buf.Capacity(); byte[] bufsizearray = new byte[] { unchecked((byte)(size & unchecked((int)(0xff)) )), unchecked((byte)(((int)(((uint)size) >> 8)) & unchecked((int)(0xff)))), unchecked( (byte)(((int)(((uint)size) >> 16)) & unchecked((int)(0xff)))), unchecked((byte)( ((int)(((uint)size) >> 24)) & unchecked((int)(0xff)))) }; output.Write(codetag); output.Write(bufsizearray); output.Write(buf); } output.Close(); output = null; objarray.Clear(); objarray = null; constarray = null; dataarea = null; }