Esempio n. 1
0
		// the encoded byte code begins with the word CRAYON followed by a @ char.
		// The word crayon serves as a version stamp. For example, in a later version of byte code, CRAYON can be
		// swapped out with CRAYON2.
		// The first @ will always be the terminator of the version ID.

		// Following the @ will be an encoded integer indicating how many rows are in the byte code.
		// After that is each encoded row.
		public static String Encode(ByteBuffer buffer)
		{
			StringBuilder sb = new StringBuilder();
			sb.Append("CRAYON@");

			int[][] code = buffer.ToIntList().ToArray();
			string[] stringArgs = buffer.ToStringList().ToArray();
			int size = code.Length;

			sb.Append(EncodeInteger(size));

			for (int i = 0; i < size; ++i)
			{
				int[] row = code[i];
				string stringArg = stringArgs[i];
				EncodeRow(sb, row, stringArg);
			}
			return sb.ToString();
		}
Esempio n. 2
0
        // the encoded byte code begins with the word CRAYON followed by a @ char.
        // The word crayon serves as a version stamp. For example, in a later version of byte code, CRAYON can be
        // swapped out with CRAYON2.
        // The first @ will always be the terminator of the version ID.

        // Following the @ will be an encoded integer indicating how many rows are in the byte code.
        // After that is each encoded row.
        public static String Encode(ByteBuffer buffer)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("CRAYON@");

            int[][]  code       = buffer.ToIntList().ToArray();
            string[] stringArgs = buffer.ToStringList().ToArray();
            int      size       = code.Length;

            sb.Append(EncodeInteger(size));

            for (int i = 0; i < size; ++i)
            {
                int[]  row       = code[i];
                string stringArg = stringArgs[i];
                EncodeRow(sb, row, stringArg);
            }
            return(sb.ToString());
        }
Esempio n. 3
0
        private string GenerateReadableByteCode(ByteBuffer byteCode)
        {
            List <string> output     = new List <string>();
            List <int[]>  rows       = byteCode.ToIntList();
            List <string> stringArgs = byteCode.ToStringList();
            int           length     = rows.Count;
            int           rowLength;

            int[] row;
            Dictionary <int, string> opCodes = new Dictionary <int, string>();

            foreach (OpCode opCode in Enum.GetValues(typeof(OpCode)))
            {
                opCodes[(int)opCode] = opCode.ToString();
            }
            List <string> rowOutput = new List <string>();

            for (int i = 0; i < length; ++i)
            {
                row       = rows[i];
                rowLength = row.Length;
                rowOutput.Add(i + "\t");
                rowOutput.Add(opCodes[row[0]] + ":");
                for (int j = 1; j < row.Length; ++j)
                {
                    rowOutput.Add(" " + row[j]);
                }

                string sArg = stringArgs[i];
                if (sArg != null)
                {
                    rowOutput.Add(" " + sArg.Replace("\n", "\\n").Replace("\r", "\\r").Replace("\t", "\\t"));
                }

                output.Add(string.Join("", rowOutput));
                rowOutput.Clear();
            }

            return(string.Join("\r\n", output));
        }
Esempio n. 4
0
		private void GenerateReadableByteCode(string path, ByteBuffer byteCode)
		{
			List<string> output = new List<string>();
			List<int[]> rows = byteCode.ToIntList();
			List<string> stringArgs = byteCode.ToStringList();
			int length = rows.Count;
			int rowLength;
			int[] row;
			Dictionary<int, string> opCodes = new Dictionary<int, string>();
			foreach (OpCode opCode in Enum.GetValues(typeof(OpCode)))
			{
				opCodes[(int)opCode] = opCode.ToString();
			}
			List<string> rowOutput = new List<string>();
			for (int i = 0; i < length; ++i)
			{
				row = rows[i];
				rowLength = row.Length;
				rowOutput.Add(i + "\t");
				rowOutput.Add(opCodes[row[0]] + ":");
				for (int j = 1; j < row.Length; ++j)
				{
					rowOutput.Add(" " + row[j]);
				}

				string sArg = stringArgs[i];
				if (sArg != null)
				{
					rowOutput.Add(" " + sArg.Replace("\n", "\\n").Replace("\r", "\\r").Replace("\t", "\\t"));
				}

				output.Add(string.Join("", rowOutput));
				rowOutput.Clear();
			}

			System.IO.File.WriteAllText(path, string.Join("\r\n", output));
		}