internal static void length(Instruction i, LuaVm vm)
        {
            var abc = i.ABC();
            var a   = abc.Item1 + 1;
            var b   = abc.Item2 + 1;

            vm.Len(b);
            vm.Replace(a);
        }
        internal static void _unaryArith(Instruction i, LuaVm vm, ArithOp op)
        {
            var ab_ = i.ABC();
            var a   = ab_.Item1 + 1;
            var b   = ab_.Item2 + 1;

            vm.PushValue(b);
            vm.Arith(op);
            vm.Replace(a);
        }
        internal static void not(Instruction i, LuaVm vm)
        {
            var abc = i.ABC();
            var a   = abc.Item1 + 1;
            var b   = abc.Item2 + 1;
            var c   = abc.Item3 + 1;

            vm.PushBoolean(!vm.ToBoolean(b));
            vm.Replace(a);
        }
Exemple #4
0
        internal static void forPrep(Instruction i, LuaVm vm)
        {
            var asBx = i.AsBx();
            var a    = asBx.Item1 + 1;
            var sBx  = asBx.Item2;

            vm.PushValue(a);
            vm.PushValue(a + 2);
            vm.Arith(Consts.LUA_OPSUB);
            vm.Replace(a);
            vm.AddPC(sBx);
        }
        internal static void test(Instruction i, LuaVm vm)
        {
            var abc = i.ABC();
            var a   = abc.Item1 + 1;
            var b   = abc.Item2 + 1;
            var c   = abc.Item3 + 1;

            if (vm.ToBoolean(a) != (c != 0))
            {
                vm.AddPC(1);
            }
        }
        internal static void _binaryArith(Instruction i, LuaVm vm, ArithOp op)
        {
            var abc = i.ABC();
            var a   = abc.Item1 + 1;
            var b   = abc.Item2;
            var c   = abc.Item3;

            vm.GetRK(b);
            vm.GetRK(c);
            vm.Arith(op);
            vm.Replace(a);
        }
        internal static void _compare(Instruction i, LuaVm vm, CompareOp op)
        {
            var abc = i.ABC();
            var a   = abc.Item1 + 1;
            var b   = abc.Item2 + 1;
            var c   = abc.Item3 + 1;

            vm.GetRK(b);
            vm.GetRK(c);
            if (vm.Compare(-2, -1, op) != (a != 0))
            {
                vm.AddPC(1);
            }

            vm.Pop(2);
        }
        internal static void testSet(Instruction i, LuaVm vm)
        {
            var abc = i.ABC();
            var a   = abc.Item1 + 1;
            var b   = abc.Item2 + 1;
            var c   = abc.Item3 + 1;

            if (vm.ToBoolean(b) == (c != 0))
            {
                vm.Copy(b, a);
            }
            else
            {
                vm.AddPC(1);
            }
        }
        internal static void concat(Instruction i, LuaVm vm)
        {
            var abc = i.ABC();
            var a   = abc.Item1 + 1;
            var b   = abc.Item2 + 1;
            var c   = abc.Item3 + 1;

            var n = c - b + 1;

            vm.CheckStack(n);
            for (var l = b; l <= c; l++)
            {
                vm.PushValue(l);
            }

            vm.Concat(n);
            vm.Replace(a);
        }
Exemple #10
0
        internal static void forLoop(Instruction i, LuaVm vm)
        {
            var asBx = i.AsBx();
            var a    = asBx.Item1 + 1;
            var sBx  = asBx.Item2;

            // R(A)+=R(A+2);
            vm.PushValue(a + 2);
            vm.PushValue(a);
            vm.Arith(Consts.LUA_OPADD);
            vm.Replace(a);

            var isPositiveStep = vm.ToNumber(a + 2) >= 0;

            if (
                (isPositiveStep && vm.Compare(a, a + 1, Consts.LUA_OPLE)) ||
                (!isPositiveStep && vm.Compare(a + 1, a, Consts.LUA_OPLE)))
            {
                // pc+=sBx; R(A+3)=R(A)
                vm.AddPC(sBx);
                vm.Copy(a, a + 3);
            }
        }
 internal static void pow(Instruction i, LuaVm vm)
 {
     _binaryArith(i, vm, Consts.LUA_OPPOW);
 }
 internal static void bnot(Instruction i, LuaVm vm)
 {
     _unaryArith(i, vm, Consts.LUA_OPBNOT);
 }
 internal static void unm(Instruction i, LuaVm vm)
 {
     _unaryArith(i, vm, Consts.LUA_OPUNM);
 }
 internal static void shr(Instruction i, LuaVm vm)
 {
     _binaryArith(i, vm, Consts.LUA_OPSHR);
 }
 internal static void bxor(Instruction i, LuaVm vm)
 {
     _binaryArith(i, vm, Consts.LUA_OPBXOR);
 }
 internal static void band(Instruction i, LuaVm vm)
 {
     _binaryArith(i, vm, Consts.LUA_OPBAND);
 }
 internal static void idiv(Instruction i, LuaVm vm)
 {
     _binaryArith(i, vm, Consts.LUA_OPIDIV);
 }
 internal static void mod(Instruction i, LuaVm vm)
 {
     _binaryArith(i, vm, Consts.LUA_OPMOD);
 }
 internal static void le(Instruction i, LuaVm vm)
 {
     _compare(i, vm, Consts.LUA_OPLE);
 }