Logical or/and

This commit is contained in:
nub31
2025-09-09 16:29:42 +02:00
parent 5fd4909f81
commit 4e0aabd60a
8 changed files with 45 additions and 21 deletions

View File

@@ -725,13 +725,13 @@ public class QBEGenerator
var outputName = TmpName();
var instruction = BinaryInstructionFor(binaryExpression.Operator, binaryExpression.Left.Type);
var instruction = EmitBinaryInstructionForOperator(binaryExpression.Operator, binaryExpression.Left.Type);
_writer.Indented($"{outputName} {QBEAssign(binaryExpression.Left.Type)} {instruction} {left}, {right}");
return outputName;
}
private string BinaryInstructionFor(BinaryOperator op, TypeNode type)
private static string EmitBinaryInstructionForOperator(BinaryOperator op, TypeNode type)
{
return op switch
{
@@ -881,6 +881,9 @@ public class QBEGenerator
},
_ => throw new NotSupportedException($"Greater than or equal comparison not supported for type '{type}'")
},
// todo(nub31): Implement short circuiting
BinaryOperator.LogicalAnd => "and",
BinaryOperator.LogicalOr => "or",
_ => throw new ArgumentOutOfRangeException(nameof(op))
};
}