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
 /// <summary>
 /// if R(A + 1) != null
 ///     R(A) = R(A + 1); pc += sBx
 /// </summary>
 public static void TForLoop(Instruction ins, ILuaVM vm)
 {
     ins.AsBx(out var a, out var sbx);
     a += 1;
     if (!vm.IsNil(a + 1))
     {
         vm.Copy(a + 1, a);
         vm.AddPC(sbx);
     }
 }
Exemple #3
0
    internal static void Test(Instruction i, ILuaVM vm)
    {
        var(a, _, c) = i.ABC();
        a           += 1;

        if (vm.ToBoolean(a) != (c != 0))
        {
            vm.AddPC(1);
        }
    }
Exemple #4
0
        /// <summary>
        /// pc += sBx
        /// if (A) close all upvalues >= R(A - 1)
        /// </summary>
        public static void Jump(Instruction ins, ILuaVM vm)
        {
            ins.AsBx(out var a, out var sbx);
            vm.AddPC(sbx);

            if (a != 0)
            {
                vm.CloseUpvalues(a);
            }
        }
Exemple #5
0
    internal static void TForLoop(Instruction i, ILuaVM vm)
    {
        var(a, sBx) = i.AsBx();
        a          += 1;

        if (!vm.IsNil(a + 1))
        {
            vm.Copy(a + 1, a);
            vm.AddPC(sBx);
        }
    }
Exemple #6
0
 internal static void LoadBool(Instruction i, ILuaVM vm)
 {
     var(a, b, c) = i.ABC();
     a           += 1;
     vm.PushBoolean(b != 0);
     vm.Replace(a);
     if (c != 0)
     {
         vm.AddPC(1);
     }
 }
Exemple #7
0
        public static void Jmp(int i, ILuaVM vm)
        {
            int a   = Instruction.GetA(i);
            int sBx = Instruction.GetSBx(i);

            vm.AddPC(sBx);
            if (a != 0)
            {
                throw new Exception("Jmp: a != 0");
            }
        }
Exemple #8
0
    private static void Compare(Instruction i, ILuaVM vm, CompareOp op)
    {
        var(a, b, c) = i.ABC();

        vm.GetRK(b);
        vm.GetRK(c);
        if (vm.Compare(-2, -1, op) != (a != 0))
        {
            vm.AddPC(1);
        }
        vm.Pop(2);
    }
Exemple #9
0
        /// <summary>
        /// R(A) = (bool) B
        /// if (C) pc++
        /// </summary>
        public static void LoadBool(Instruction ins, ILuaVM vm)
        {
            ins.ABC(out var a, out var b, out var c);
            a += 1;

            vm.PushBoolean(b != 0);
            vm.Replace(a);

            if (c != 0)
            {
                vm.AddPC(1);
            }
        }
Exemple #10
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 #11
0
        /// <summary>
        /// if ((RK(B) op RK(C)) != A)
        ///     pc++
        /// </summary>
        private static void Compare(Instruction ins, ILuaVM vm, ECompOp op)
        {
            ins.ABC(out var a, out var b, out var c);

            vm.GetRK(b);
            vm.GetRK(c);

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

            vm.Pop(2);
        }
Exemple #12
0
    internal static void TestSet(Instruction i, ILuaVM vm)
    {
        var(a, b, c) = i.ABC();
        a           += 1;
        b           += 1;

        if (vm.ToBoolean(b) == (c != 0))
        {
            vm.Copy(b, a);
        }
        else
        {
            vm.AddPC(1);
        }
    }
Exemple #13
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 #14
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);
            }
        }