CLanguage by praeclarum

<PackageReference Include="CLanguage" Version="0.16.36" />

.NET API 202,752 bytes

 ConditionalExpression

using CLanguage.Compiler; using CLanguage.Interpreter; using CLanguage.Types; using System.Runtime.CompilerServices; namespace CLanguage.Syntax { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class ConditionalExpression : Expression { public Expression Condition { get; set; } public Expression TrueValue { get; set; } public Expression FalseValue { get; set; } public ConditionalExpression(Expression condition, Expression trueValue, Expression falseValue) { Condition = condition; TrueValue = trueValue; FalseValue = falseValue; } public override CType GetEvaluatedCType(EmitContext ec) { return TrueValue.GetEvaluatedCType(ec); } protected override void DoEmit(EmitContext ec) { Label label = ec.DefineLabel(); Label label2 = ec.DefineLabel(); Condition.Emit(ec); ec.EmitCastToBoolean(Condition.GetEvaluatedCType(ec)); ec.Emit(OpCode.BranchIfFalse, label); TrueValue.Emit(ec); ec.Emit(OpCode.Jump, label2); ec.EmitLabel(label); FalseValue.Emit(ec); ec.EmitLabel(label2); } } }