Example #1
0
        public void Compile(CodeBuilder builder)
        {
            var aVar = builder.PortToValue(GetInputPort("A"), a);
            var bVar = builder.PortToValue(GetInputPort("B"), b);

            string varName      = builder.PortToVariableName(GetOutputPort(""));
            string constKeyword = (aVar.isConst && bVar.isConst) ? "const " : "";
            string returnType   = builder.HoistNamespace(typeof(R));
            string operation    = CompileOperation(aVar.value, bVar.value);

            // If the operation executes on two constants, also make the operation constant.
            if (aVar.isConst && bVar.isConst)
            {
                builder.AddConstToScope(varName);
            }

            builder.AppendLine($"{constKeyword}{returnType} {varName} = {operation};");
        }
Example #2
0
        public void Compile(CodeBuilder builder)
        {
            NodePort valuePort = GetInputPort("Value");
            NodePort objPort   = GetInputPort("Obj");

            var valueVar = builder.PortToValue(valuePort, value);
            var objVar   = builder.PortToValue(objPort, obj);

            if (objVar.fragment != "null")
            {
                objVar.fragment = $" + {objVar}.ToString()";
            }
            else
            {
                objVar.fragment = "";
            }

            string method = "Log";

            switch (level)
            {
            case LogLevel.Info: method = "Log"; break;

            case LogLevel.Warning: method = "LogWarning"; break;

            case LogLevel.Error: method = "LogError"; break;
            }

            builder.AppendLine($"Debug.{method}({valueVar}{objVar});");

            // Continue to next executable node
            var next = GetNextExec();

            if (next is ICanCompile nextNode)
            {
                nextNode.Compile(builder);
            }
        }
Example #3
0
        public void Compile(CodeBuilder builder)
        {
            /*
             * Build:
             *
             * if (condition) {
             *   ifExec
             * } else {
             *   elseExec
             * }
             */
            var conditionVar = builder.PortToValue(GetInputPort("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?.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();
        }
Example #4
0
        /// <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);
            }
        }
Example #5
0
        /// <summary>
        /// If the given input port has a connection, compile and return the connection's
        /// output variable name. If not, return a constant representing the default (inline) value.
        /// </summary>
        private string ConstantOrVariable <T>(CodeBuilder builder, string portName, T defaultValue = default)
        {
            NodePort port = GetInputPort(portName);

            return(builder.PortToValue(port, defaultValue).ToString());
        }