Example #1
0
    public override string GenCode()
    {
        Condition.GenCode();
        string elseLabel  = "";
        var    afterLabel = Compiler.GenerateLabel();

        if (ElseStatement != null)
        {
            elseLabel = Compiler.GenerateLabel();
            Compiler.EmitCode($"brfalse {elseLabel}");
        }
        else
        {
            Compiler.EmitCode($"brfalse {afterLabel}");
        }
        ThenStatement.GenCode();

        if (ElseStatement != null)
        {
            Compiler.EmitCode($"br {afterLabel}");
            Compiler.EmitCode("nop", true, elseLabel);
            ElseStatement.GenCode();
        }
        Compiler.EmitCode("nop", true, afterLabel);

        return("");
    }