private void InsertJumpLabelInstructionIfNeeded(CodeLine insertedLine, int index, CodeLine parentLine)
        {
            if (unpinnedCodeline != null)
            {
                return;
            }
            if (!InstructionHelper.IsJumpInstruction(insertedLine.instruction))
            {
                return;
            }
            if (InstructionHelper.IsJumpInstructionLabel(insertedLine.instruction))
            {
                return;
            }
            var jumpLabel     = insertedLine.instruction.GetComponent <JumpInstructionScript>().CreateBindedLabel();
            var labelCodeLine = CodeLineFactory.GetStandardCodeLine(jumpLabel);

            InsertAtLine(labelCodeLine, index, parentLine);
            insertedLine.instruction.GetComponent <JumpInstructionScript>().AttachArrow();
        }
        public void GenerateCodeForInstruction(CodeLine line)
        {
            if (InstructionHelper.IsMoveInstruction(line.instruction))
            {
                var command = new MoveCommand(InstructionHelper.GetInstructionDirection(line.instruction), currentCodeLineNumber + 1);
                commandToCodeLineMapping.Add(command, line);
                allCommands.Add(command);
            }
            if (InstructionHelper.IsPutInstruction(line.instruction))
            {
                var command = new PutCommand(currentCodeLineNumber + 1);
                commandToCodeLineMapping.Add(command, line);
                allCommands.Add(command);
            }
            if (InstructionHelper.IsPickInstruction(line.instruction))
            {
                var command = new PickCommand(currentCodeLineNumber + 1);
                commandToCodeLineMapping.Add(command, line);
                allCommands.Add(command);
            }
            if (InstructionHelper.IsJumpInstruction(line.instruction))
            {
                ICommand command;

                if (InstructionHelper.IsJumpInstructionLabel(line.instruction))
                {
                    command = new JumpCommand(currentCodeLineNumber + 1);
                    allCommands.Add(command);
                }
                else
                {
                    //this is being set in code later - otherwise forward jumps will not work - see RepairJumps for reference.
                    command = new JumpCommand(currentCodeLineNumber + 1);
                    allCommands.Add(command);
                }
                commandToCodeLineMapping.Add(command, line);
            }

            if (InstructionHelper.IsIfInstruction(line.instruction))
            {
                int trueLineNumber = currentCodeLineNumber + 1;
                int elseLineNumber = currentCodeLineNumber + line.TotalChildrenCount + 1;
                var command        = new IfCommand(trueLineNumber, elseLineNumber, GetConditions(line), GetLogicalOperators(line));
                allCommands.Add(command);
                commandToCodeLineMapping.Add(command, line);
                currentCodeLineNumber++;
                foreach (var child in line.children)
                {
                    GenerateCodeForInstruction(child);
                }
                command.NextCommandId = currentCodeLineNumber;
                currentCodeLineNumber--; //this may seem wrong but actually it is not
            }

            if (InstructionHelper.IsWhileInstruction(line.instruction))
            {
                int trueLineNumber  = currentCodeLineNumber + 1;
                int falseLineNumber = currentCodeLineNumber + line.TotalChildrenCount + 1;
                var command         = new WhileCommand(trueLineNumber, falseLineNumber, GetConditions(line), GetLogicalOperators(line));
                allCommands.Add(command);
                commandToCodeLineMapping.Add(command, line);
                currentCodeLineNumber++;
                foreach (var child in line.children)
                {
                    GenerateCodeForInstruction(child);
                }
                var loopJumpCommand = new JumpCommand(trueLineNumber - 1);
                commandToCodeLineMapping.Add(loopJumpCommand, null);
                command.NextCommandId = currentCodeLineNumber + 1;
                allCommands.Add(loopJumpCommand);
            }

            if (InstructionHelper.IsRepeatInstruction(line.instruction))
            {
                int trueLineNumber  = currentCodeLineNumber + 1;
                int falseLineNumber = currentCodeLineNumber + line.TotalChildrenCount + 1;
                var command         = new RepeatCommand(trueLineNumber, falseLineNumber, InstructionHelper.GetRepeatTimes(line.instruction));
                allCommands.Add(command);
                commandToCodeLineMapping.Add(command, line);
                currentCodeLineNumber++;
                foreach (var child in line.children)
                {
                    GenerateCodeForInstruction(child);
                }
                var loopJumpCommand = new JumpCommand(trueLineNumber - 1);
                commandToCodeLineMapping.Add(loopJumpCommand, null);
                command.NextCommandId = currentCodeLineNumber;
                allCommands.Add(loopJumpCommand);
            }

            currentCodeLineNumber++;
        }