public override bool EmitBranchable(EmitContext ec, Label truecase, bool v)
 {
     Emit(ec);
     ec.EmitInstruction(new Compare()
     {
         DestinationReg = EmitContext.A, SourceValue = (ushort)1
     });
     ec.EmitBooleanBranch(v, truecase, ConditionalTestEnum.Equal, ConditionalTestEnum.NotEqual);
     return(true);
 }
        public override bool EmitBranchable(EmitContext ec, Label truecase, bool v)
        {
            Left.EmitToStack(ec);
            //ec.MarkOptimizable(); // Marks last instruction as last push
            Right.EmitToStack(ec);
            //ec.MarkOptimizable(); // Marks last instruction as last push


            ec.EmitComment(Operator + "  " + Left.CommentString() + ",  " + Right.CommentString());


            if (Operator == Operators.Equal)
            {
                ec.EmitPop(RegistersEnum.BX);
                ec.EmitPop(RegistersEnum.AX);
                ec.EmitInstruction(new Compare()
                {
                    DestinationReg = RegistersEnum.AX, SourceReg = RegistersEnum.BX, Size = 80, OptimizingBehaviour = OptimizationKind.PPO
                });
                ec.EmitBooleanBranch(v, truecase, ConditionalTestEnum.Equal, ConditionalTestEnum.NotEqual);
            }
            else if (Operator == Operators.NotEqual)
            {
                ec.EmitPop(RegistersEnum.BX);
                ec.EmitPop(RegistersEnum.AX);
                ec.EmitInstruction(new Compare()
                {
                    DestinationReg = RegistersEnum.AX, SourceReg = RegistersEnum.BX, Size = 80, OptimizingBehaviour = OptimizationKind.PPO
                });
                ec.EmitBooleanBranch(v, truecase, ConditionalTestEnum.NotEqual, ConditionalTestEnum.Equal);
            }
            else if (Operator == Operators.LT)
            {
                ec.EmitPop(RegistersEnum.BX);
                ec.EmitPop(RegistersEnum.AX);
                ec.EmitInstruction(new Compare()
                {
                    DestinationReg = RegistersEnum.AX, SourceReg = RegistersEnum.BX, Size = 80, OptimizingBehaviour = OptimizationKind.PPO
                });
                ec.EmitBooleanBranch(v, truecase, ConditionalTestEnum.LessThan, ConditionalTestEnum.GreaterThanOrEqualTo);
            }
            else if (Operator == Operators.GT)
            {
                ec.EmitPop(RegistersEnum.BX);
                ec.EmitPop(RegistersEnum.AX);
                ec.EmitInstruction(new Compare()
                {
                    DestinationReg = RegistersEnum.AX, SourceReg = RegistersEnum.BX, Size = 80, OptimizingBehaviour = OptimizationKind.PPO
                });
                ec.EmitBooleanBranch(v, truecase, ConditionalTestEnum.GreaterThan, ConditionalTestEnum.LessThanOrEqualTo);
            }
            else if (Operator == Operators.GTE)
            {
                ec.EmitPop(RegistersEnum.BX);
                ec.EmitPop(RegistersEnum.AX);
                ec.EmitInstruction(new Compare()
                {
                    DestinationReg = RegistersEnum.AX, SourceReg = RegistersEnum.BX, Size = 80, OptimizingBehaviour = OptimizationKind.PPO
                });
                ec.EmitBooleanBranch(v, truecase, ConditionalTestEnum.GreaterThanOrEqualTo, ConditionalTestEnum.LessThan);
            }
            else if (Operator == Operators.LTE)
            {
                ec.EmitPop(RegistersEnum.BX);
                ec.EmitPop(RegistersEnum.AX);
                ec.EmitInstruction(new Compare()
                {
                    DestinationReg = RegistersEnum.AX, SourceReg = RegistersEnum.BX, Size = 80, OptimizingBehaviour = OptimizationKind.PPO
                });
                ec.EmitBooleanBranch(v, truecase, ConditionalTestEnum.LessThanOrEqualTo, ConditionalTestEnum.GreaterThan);
            }

            // jumps
            ec.EmitBooleanBranch(v, truecase, ConditionalTestEnum.Equal, ConditionalTestEnum.NotEqual);

            return(true);
        }