// Runtime content can be summarised as follows: // - Evaluate an expression if necessary to branch on // - Branch to a named container if true // - Divert back to main flow // (owner Conditional is in control of this target point) public override Runtime.Object GenerateRuntimeObject() { var container = new Runtime.Container (); // Are we testing against a condition that's used for more than just this // branch? If so, the first thing we need to do is replicate the value that's // on the evaluation stack so that we don't fully consume it, in case other // branches need to use it. bool duplicatesStackValue = shouldMatchEquality && !isElse; if ( duplicatesStackValue ) container.AddContent (Runtime.ControlCommand.Duplicate ()); _conditionalDivert = new Runtime.Divert (); // else clause is unconditional catch-all, otherwise the divert is conditional _conditionalDivert.isConditional = !isElse; // Need extra evaluation? if( !isTrueBranch && !isElse ) { bool needsEval = ownExpression != null; if( needsEval ) container.AddContent (Runtime.ControlCommand.EvalStart ()); if (ownExpression) ownExpression.GenerateIntoContainer (container); // Uses existing duplicated value if (shouldMatchEquality) container.AddContent (Runtime.NativeFunctionCall.CallWithName ("==")); if( needsEval ) container.AddContent (Runtime.ControlCommand.EvalEnd ()); } // Will pop from stack if conditional container.AddContent (_conditionalDivert); _contentContainer = GenerateRuntimeForContent (); _contentContainer.name = "b"; if( duplicatesStackValue ) _contentContainer.InsertContent (Runtime.ControlCommand.PopEvaluatedValue (), 0); container.AddToNamedContentOnly (_contentContainer); returnDivert = new Runtime.Divert (); _contentContainer.AddContent (returnDivert); return container; }