Axiom.Runtime.AMProgram.AddLabelAndPatchPredicates C# (CSharp) Method

AddLabelAndPatchPredicates() private method

private AddLabelAndPatchPredicates ( string label, ProgramClause procedure ) : void
label string
procedure ProgramClause
return void
        private void AddLabelAndPatchPredicates(string label, ProgramClause procedure)
        {
            AMInstructionSet instructionSet = new AMInstructionSet();

            int occurrence = (int)_labelOccurrence[label];

            if (occurrence == 1)
            {
                ProgramClause p = (ProgramClause)_labels[label];
                string nextLabelName = p.Name + "%" + occurrence + "/" + p.Arity;

                p.Instruction = instructionSet.CreateInstruction("try_me_else", nextLabelName);

                ProgramClause newClause = new ProgramClause(nextLabelName, p.Arity, instructionSet.CreateInstruction("trust_me"));

                p.NextPredicate = newClause;

                AddProgramNode(newClause);

                _labels[nextLabelName] = newClause;
            }
            else
            {
                ProgramClause pc = (ProgramClause)_labels[label];
                string nextLabelName = pc.Name + "%" + occurrence + "/" + pc.Arity;

                ProgramClause lastLabel = this[pc.Name + "%" + (occurrence - 1) + "/" + pc.Arity];

                lastLabel.Instruction = instructionSet.CreateInstruction("retry_me_else", nextLabelName);

                ProgramClause newClause = new ProgramClause(nextLabelName, pc.Arity, instructionSet.CreateInstruction("trust_me"));

                lastLabel.NextPredicate = newClause;

                AddProgramNode(newClause);

                _labels[nextLabelName] = newClause;
            }
        }