Exemplo n.º 1
0
        public void FindEndIfTest()
        {
            string IfBlock = @"IF 0,0,0
ELSE
	IF 0,0,0
	ELSE
	END_IF
END_IF";

            int       ValidifIndex = 0, inValidifIndex = 0;
            HLProgram p = new HLProgram(IfBlock);

            try
            {
                int i = p.FindEndIf(ValidifIndex);
                Assert.AreNotEqual(-1, i);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Assert.Fail("Invalid if index :", inValidifIndex);
            }

            try
            {
                int i = p.FindEndIf(inValidifIndex);
                Assert.AreNotEqual(-1, i);
            }
            catch (IfUnmatchedException ex)
            {
                Console.WriteLine(ex.ToString());
                Assert.Fail("Invalid if index :", inValidifIndex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the sub-program pointed by the pointer at specified index.
        /// </summary>
        /// <param name="index">The index of pointer.</param>
        /// <returns>The sub-program pointed by the pointer.</returns>
        public HLProgram GetSubProgram(int pvmIndex)
        {
            int         programIndex = this[pvmIndex];
            Instruction ins          = program[programIndex];

            if (ins.opcode == Instruction.IF)
            {
                return(program.SubProgram(programIndex, program.FindEndIf(programIndex)));
            }
            else if (ins.opcode == Instruction.LOOP)
            {
                return(program.SubProgram(programIndex, program.FindEndLoop(programIndex)));
            }
            else
            {
                // A HLProgram with only one instruction.
                HLProgram result = new HLProgram();
                result.Add(ins);
                return(result);
            }
        }
Exemplo n.º 3
0
 public ProgramViewModel(HLProgram program)
 {
     this.program = program;
     for (int i = 0; i < program.Count; i++)
     {
         if (program[i].opcode == Instruction.IF)
         {
             base.Add(i);
             i = program.FindEndIf(i);
         }
         else if (program[i].opcode == Instruction.LOOP)
         {
             base.Add(i);
             i = program.FindEndLoop(i);
         }
         else
         {
             base.Add(i);
         }
     }
 }