Exemple #1
0
        /// <summary>
        /// R(A) -= R(A + 2)
        /// pc += sBx
        /// </summary>
        public static void ForPrep(Instruction ins, ILuaVM vm)
        {
            ins.AsBx(out var a, out var sbx);
            a += 1;

            if (vm.Type(a) == ELuaType.String)
            {
                vm.PushNumber(vm.ToNumber(a));
                vm.Replace(a);
            }

            if (vm.Type(a + 1) == ELuaType.String)
            {
                vm.PushNumber(vm.ToNumber(a + 1));
                vm.Replace(a + 1);
            }

            if (vm.Type(a + 2) == ELuaType.String)
            {
                vm.PushNumber(vm.ToNumber(a + 2));
                vm.Replace(a + 2);
            }

            // R(A) -= R(A + 2)
            vm.PushValue(a);
            vm.PushValue(a + 2);
            vm.Arith(EArithOp.Sub);
            vm.Replace(a);

            // pc += sBx
            vm.AddPC(sbx);
        }
Exemple #2
0
        private static void unaryArith(int i, ILuaVM vm, ArithOpEnum op)
        {
            int a = Instruction.GetA(i) + 1;
            int b = Instruction.GetB(i) + 1;

            vm.PushValue(b);
            vm.Arith(op);
            vm.Replace(a);
        }
Exemple #3
0
    private static void BinaryArith(Instruction i, ILuaVM vm, ArithOp op)
    {
        var(a, b, c) = i.ABC();
        a           += 1;

        vm.GetRK(b);
        vm.GetRK(c);
        vm.Arith(op);
        vm.Replace(a);
    }
Exemple #4
0
    private static void UnaryArith(Instruction i, ILuaVM vm, ArithOp op)
    {
        var(a, b, _) = i.ABC();
        a           += 1;
        b           += 1;

        vm.PushValue(b);
        vm.Arith(op);
        vm.Replace(a);
    }
Exemple #5
0
        /// <summary>
        /// R(A) = op R(B)
        /// </summary>
        private static void UnaryArith(Instruction ins, ILuaVM vm, EArithOp op)
        {
            ins.ABC(out var a, out var b, out _);
            a += 1;
            b += 1;

            vm.PushValue(b);
            vm.Arith(op);
            vm.Replace(a);
        }
Exemple #6
0
        /// <summary>
        /// R(A) = RK(B) op RK(C)
        /// </summary>
        private static void BinaryArith(Instruction ins, ILuaVM vm, EArithOp op)
        {
            ins.ABC(out var a, out var b, out var c);
            a += 1;

            vm.GetRK(b);
            vm.GetRK(c);
            vm.Arith(op);
            vm.Replace(a);
        }
Exemple #7
0
        private static void binaryArith(int i, ILuaVM vm, ArithOpEnum op)
        {
            int a = Instruction.GetA(i) + 1;
            int b = Instruction.GetB(i);
            int c = Instruction.GetC(i);

            vm.GetRK(b);
            vm.GetRK(c);
            vm.Arith(op);
            vm.Replace(a);
        }
Exemple #8
0
    internal static void ForPrep(Instruction i, ILuaVM vm)
    {
        var(a, sBx) = i.AsBx();
        a          += 1;

        // R(A)-=R(A+2)
        vm.PushValue(a);
        vm.PushValue(a + 2);
        vm.Arith(ArithOp.Sub);
        vm.Replace(a);
        // pc += sBx
        vm.AddPC(sBx);
    }
Exemple #9
0
    internal static void ForLoop(Instruction i, ILuaVM vm)
    {
        var(a, sBx) = i.AsBx();
        a          += 1;

        // R(A)+=R(A+2)
        vm.PushValue(a + 2);
        vm.PushValue(a);
        vm.Arith(ArithOp.Add);
        vm.Replace(a);

        // R(A)<?=R(A+1)
        bool isPositiveStep = vm.ToNumber(a + 2) >= 0;

        if ((isPositiveStep && vm.Compare(a, a + 1, CompareOp.Le)) ||
            (!isPositiveStep && vm.Compare(a + 1, a, CompareOp.Le)))
        {
            vm.AddPC(sBx);     // pc+=sBx
            vm.Copy(a, a + 3); // R(A+3)=R(A)
        }
    }
Exemple #10
0
        /// <summary>
        /// R(A) += R(A + 2)
        /// if R(A) <?= R(A + 1) {
        ///     pc += sBx
        ///     R(A + 3) = R(A)
        /// }
        /// </summary>
        public static void ForLoop(Instruction ins, ILuaVM vm)
        {
            ins.AsBx(out var a, out var sbx);
            a += 1;

            // R(A) += R(A + 2)
            vm.PushValue(a + 2);
            vm.PushValue(a);
            vm.Arith(EArithOp.Add);
            vm.Replace(a);

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

            if (isPositiveStep && vm.Compare(a, a + 1, ECompOp.Le) ||
                !isPositiveStep && vm.Compare(a + 1, a, ECompOp.Le))
            {
                // pc += sBx
                vm.AddPC(sbx);
                // R(A + 3) = R(A)
                vm.Copy(a, a + 3);
            }
        }