/// <summary>
 /// 加载参数,并写入条件转移指令
 /// </summary>
 /// <param name="op"></param>
 /// <param name="target"></param>
 private void GoToIf(LogicOperator op, ILabel target)
 {
     for (int i = 0; i < op.ArgumentCount; ++i)
     {
         // 参与验证的项
         _evalStack.Pop();
     }
     op.WriteBranch(_writer, target);
 }
Пример #2
0
 /// <summary>
 /// 比较操作
 /// </summary>
 /// <param name="op"></param>
 public void Compare(LogicOperator op)
 {
     for (int i = 0; i < op.ArgumentCount; ++i)
     {
         // todo validate better
         _evalStack.Pop();
     }
     op.WriteCompare(_writer);
     _evalStack.Push(typeof(bool));
 }
Пример #3
0
        static LogicOperator()
        {
            var op1 = new LogicOperator
            {
                //从堆栈中弹出value;如果 value 为 true、非空或非零,则将控制转移到目标指令l
                _branchWriter  = (w, l) => w.Emit(OpCodes.Brtrue, l),
                _compareWriter = w => { },//计算堆栈顶部的值,如果是true,那就是true,因此不需要额外的判断
                ArgumentCount  = 1
            };
            var op2 = new LogicOperator
            {
                //如果 value 为 false、空引用或零,则将控制转移到目标指令l
                _branchWriter = (w, l) => w.Emit(OpCodes.Brfalse, l),
                //求补(取反)
                _compareWriter = w => { NotBoolean(w); },
                ArgumentCount  = 1
            };

            SetOpposites(op1, op2);

            IsTrue  = op1;
            IsFalse = IsNull = op2;

            op1 = new LogicOperator
            {
                //从堆栈中弹出 value2 和 value1;如果 value1 等于 value2,则执行分支操作l
                _branchWriter = (w, l) => w.Emit(OpCodes.Beq, l),
                //从堆栈中弹出值2和值1,值1值2相比。
                //如果值1等于值2,被压入堆栈,否则为0压入堆栈。
                _compareWriter = w => w.Emit(OpCodes.Ceq),
                ArgumentCount  = 2
            };
            op2 = new LogicOperator
            {
                //將 value2 和 value1 自堆栈取出,如果 value1 不等于 value2,则会执行分支操作l
                _branchWriter = (wde, l) => wde.Emit(OpCodes.Bne_Un, l),
                //不等于的比较
                _compareWriter = w => { w.Emit(OpCodes.Ceq); NotBoolean(w); },
                ArgumentCount  = 2
            };

            SetOpposites(op1, op2);

            AreEqual    = op1;
            AreNotEqual = op2;

            // 大于
            op1 = new LogicOperator
            {
                //大于
                _branchWriter  = (wde, l) => wde.Emit(OpCodes.Bgt, l),
                _compareWriter = w => w.Emit(OpCodes.Cgt),
                ArgumentCount  = 2
            };
            op2 = new LogicOperator
            {
                //小于等于
                _branchWriter = (wde, l) => wde.Emit(OpCodes.Ble, l),
                //小于
                _compareWriter = w => w.Emit(OpCodes.Clt),
                ArgumentCount  = 2
            };

            SetOpposites(op1, op2);

            GreaterThan       = op1;
            LessThanOrEqualTo = op2;

            op1 = new LogicOperator
            {
                //大于等于
                _branchWriter = (wde, l) => wde.Emit(OpCodes.Bge, l),
                //大于等于的比较
                _compareWriter = w => { w.Emit(OpCodes.Clt); NotBoolean(w); },
                ArgumentCount  = 2
            };
            op2 = new LogicOperator
            {
                //小于的分支
                _branchWriter = (wde, l) => wde.Emit(OpCodes.Blt, l),
                //小于的比较
                _compareWriter = w => { w.Emit(OpCodes.Cgt); NotBoolean(w); },
                ArgumentCount  = 2
            };

            SetOpposites(op1, op2);

            GreaterThanOrEqualTo = op1;
            LessThan             = op2;
        }
Пример #4
0
 /// <summary>
 /// <para>设置op1的相反IL操作为op2</para>
 /// <para>设置op2的相反IL操作为op1</para>
 /// </summary>
 /// <param name="op1"></param>
 /// <param name="op2"></param>
 private static void SetOpposites(LogicOperator op1, LogicOperator op2)
 {
     op1._opposite = op2;
     op2._opposite = op1;
 }