public void Compile(CodeBuilder builder) { /* * Build: * * if (condition) { * ifExec * } else { * elseExec * } */ var conditionVar = builder.PortToValue(GetPort("Condition"), condition); builder.AppendLine(); builder.AppendLine($"if ({conditionVar})"); builder.BeginScope(); var next = GetNextExec(); if (next is ICanCompile ifNode) { ifNode.Compile(builder); } else { builder.AppendLine($"// TODO: Handling no ICanCompile {(next as AbstractNode)?.name}"); } builder.EndScope(); // Conditionally add an else block iff there's an exec next = GetNextExec("Else"); if (next is ICanCompile elseNode) { builder.AppendLine("else"); builder.BeginScope(); elseNode.Compile(builder); builder.EndScope(); } builder.AppendLine(); }
/// <param name="builder"></param> public void Compile(CodeBuilder builder) { /* * Build: * * for (int i = 0; i < count; i++) { * loopExec * } * * thenExec */ // Get either a constant value for the count or the input variable // if the port has a connection var countVar = builder.PortToValue(GetInputPort("Count"), count); builder.AppendLine(); builder.AppendLine($"for (int i = 0; i < {countVar}; i++)"); // Add the loop body in scope builder.BeginScope(); var loopExec = GetNextExec(); if (loopExec is ICanCompile loopNode) { loopNode.Compile(builder); } else { builder.AppendLine($"// TODO: Handling no ICanCompile {loopExec?.name}"); } builder.EndScope(); builder.AppendLine(); // Add the after-loop code var thenExec = GetNextExec("Then"); if (thenExec is ICanCompile thenNode) { thenNode.Compile(builder); } }
public void Compile(CodeBuilder builder) { // For an EntryPoint with inputs from the host, they'd be added here. builder.AppendLine("public static void Run()"); builder.BeginScope(); ICanExec next = GetNextExec(); if (next is ICanCompile node) { node.Compile(builder); } else { builder.AppendLine($"// Not ICanCompile {(next as AbstractNode).name}"); } builder.EndScope(); }