static BinaryOperator() { // IsNull, IsFalse, IsTrue var op1 = new BinaryOperator { _branchWriter = (w, l) => w.Emit(OpCodes.Brtrue, l), _compareWriter = w => { }, ArgumentCount = 1 }; var op2 = new BinaryOperator { _branchWriter = (w, l) => w.Emit(OpCodes.Brfalse, l), _compareWriter = w => w.Emit(OpCodes.Not), ArgumentCount = 1 }; SetOpposites(op1, op2); IsTrue = op1; IsFalse = IsNull = op2; // AreEqual, AreNotEqual op1 = new BinaryOperator { _branchWriter = (wde, l) => wde.Emit(OpCodes.Beq, l), _compareWriter = w => w.Emit(OpCodes.Ceq), ArgumentCount = 2 }; op2 = new BinaryOperator { _branchWriter = (wde, l) => wde.Emit(OpCodes.Bne_Un, l), _compareWriter = w => { w.Emit(OpCodes.Ceq); w.Emit(OpCodes.Not); }, ArgumentCount = 2 }; SetOpposites(op1, op2); AreEqual = op1; AreNotEqual = op2; // GreaterThan, LessThanOrEqualTo op1 = new BinaryOperator { _branchWriter = (wde, l) => wde.Emit(OpCodes.Bgt, l), _compareWriter = w => w.Emit(OpCodes.Cgt), ArgumentCount = 2 }; op2 = new BinaryOperator { _branchWriter = (wde, l) => wde.Emit(OpCodes.Ble, l), _compareWriter = w => w.Emit(OpCodes.Clt), ArgumentCount = 2 }; SetOpposites(op1, op2); GreaterThan = op1; LessThanOrEqualTo = op2; // GreaterThanOrEqualTo, LessThan op1 = new BinaryOperator { _branchWriter = (wde, l) => wde.Emit(OpCodes.Bge, l), _compareWriter = w => { w.Emit(OpCodes.Clt); w.Emit(OpCodes.Not); }, ArgumentCount = 2 }; op2 = new BinaryOperator { _branchWriter = (wde, l) => wde.Emit(OpCodes.Blt, l), _compareWriter = w => { w.Emit(OpCodes.Cgt); w.Emit(OpCodes.Not); }, ArgumentCount = 2 }; SetOpposites(op1, op2); GreaterThanOrEqualTo = op1; LessThan = op2; }
private static void SetOpposites(BinaryOperator op1, BinaryOperator op2) { op1._opposite = op2; op2._opposite = op1; }