示例#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);
        }
示例#2
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);
    }
示例#3
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);
        }
示例#4
0
    public static void SetList(Instruction i, ILuaVM vm)
    {
        const int FIELDS_PER_FLUSH = 50;

        var(a, b, c) = i.ABC();
        a           += 1;

        bool bIsZero = b == 0;

        if (bIsZero)
        {
            b = (int)vm.ToInteger(-1) - a - 1;
            vm.Pop(1);
        }

        if (c > 0)
        {
            c -= 1;
        }
        else
        {
            c = ((Instruction)vm.Fetch()).Ax();
        }

        Int64 idx = (Int64)(c * FIELDS_PER_FLUSH);

        for (int j = 1; j <= b; j++)
        {
            idx++;
            vm.PushValue(a + j);
            vm.SetI(a, idx);
        }

        if (bIsZero)
        {
            for (int j = vm.RegisterCount() + 1; j <= vm.GetTop(); j++)
            {
                idx++;
                vm.PushValue(j);
                vm.SetI(a, idx);
            }
            vm.SetTop(vm.RegisterCount());
        }
    }
示例#5
0
        /// <summary>
        /// R(A)[(C - 1) * FPF + i] := R(A + i), 1 <= i <= B
        /// </summary>
        public static void SetList(Instruction ins, ILuaVM vm)
        {
            ins.ABC(out var a, out var b, out var c);
            a += 1;

            if (c > 0)
            {
                c--;
            }
            else
            {
                new Instruction(vm.Fetch()).Ax(out c);
            }

            var bIsZero = b == 0;

            if (bIsZero)
            {
                b = (int)vm.ToInteger(-1) - a - 1;
                vm.Pop(1);
            }

            vm.CheckStack(1);
            var idx = (LuaInt)(c * LFIELDS_PER_FLUSH);

            for (var j = 1; j <= b; j++)
            {
                idx++;
                vm.PushValue(a + j);
                vm.SetI(a, idx);
            }

            if (bIsZero)
            {
                for (var j = vm.RegisterCount() + 1; j <= vm.GetTop(); j++)
                {
                    idx++;
                    vm.PushValue(j);
                    vm.SetI(a, idx);
                }

                vm.SetTop(vm.RegisterCount());
            }
        }
示例#6
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);
    }
示例#7
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);
        }
示例#8
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)
        }
    }
示例#9
0
        private static void FixStack(int a, ILuaVM vm)
        {
            var x = (int)vm.ToInteger(-1);

            vm.Pop(1);

            vm.CheckStack(x - a);
            for (var i = a; i < x; i++)
            {
                vm.PushValue(i);
            }
            vm.Rotate(vm.RegisterCount() + 1, x - a);
        }
示例#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);
            }
        }
示例#11
0
 private static int PushFuncAndArgs(int a, int b, ILuaVM vm)
 {
     if (b >= 1)
     {
         vm.CheckStack(b);
         for (int i = a; i < a + b; i++)
         {
             vm.PushValue(i);
         }
         return(b - 1);
     }
     else
     {
         FixStack(a, vm);
         return(vm.GetTop() - vm.RegisterCount() - 1);
     }
 }
示例#12
0
    internal static void Concat(Instruction i, ILuaVM vm)
    {
        var(a, b, c) = i.ABC();
        a           += 1;
        b           += 1;
        c           += 1;

        int n = c - b + 1;

        vm.CheckStack(n);
        for (int j = b; j <= c; j++)
        {
            vm.PushValue(j);
        }
        vm.Concat(n);
        vm.Replace(a);
    }
示例#13
0
        //R(A)[(C - 1)*FPF+i] := R(A + i)
        public static void SetList(int i, ILuaVM vm)
        {
            int a = Instruction.GetA(i) + 1;
            int b = Instruction.GetB(i);
            int c = Instruction.GetC(i);

            c = c > 0 ? c - 1 : Instruction.GetAx(vm.Fetch());

            vm.CheckStack(1);
            int idx = c * LFIELDS_PER_FLUSH;

            for (int j = 1; j <= b; j++)
            {
                idx++;
                vm.PushValue(a + j);
                vm.SetI(a, idx);
            }
        }
示例#14
0
        /// <summary>
        /// return R(A), ..., R(A + B - 2)
        /// </summary>
        public static void Return(Instruction ins, ILuaVM vm)
        {
            ins.ABC(out var a, out var b, out _);
            a += 1;

            if (b == 1)
            {
            }
            else if (b > 1)
            {
                vm.CheckStack(b - 1);
                for (var i = a; i <= a + b - 2; i++)
                {
                    vm.PushValue(i);
                }
            }
            else
            {
                FixStack(a, vm);
            }
        }
示例#15
0
    public static void Return(Instruction i, ILuaVM vm)
    {
        var(a, b, _) = i.ABC();
        a           += 1;

        if (b == 1)
        {
        }
        else if (b > 1)
        {
            vm.CheckStack(b - 1);
            for (int j = a; j <= a + b - 2; j++)
            {
                vm.PushValue(j);
            }
        }
        else
        {
            FixStack(a, vm);
        }
    }
示例#16
0
        //(iABC) return R(A), R(A + 1), ......, + R(A + B - 2)
        public static void Return(int i, ILuaVM vm)
        {
            int a = Instruction.GetA(i) + 1;
            int b = Instruction.GetB(i);

            if (b == 1)
            {
            }
            else if (b > 1)
            {
                vm.CheckStack(b - 1);
                for (int j = a; j <= a + b - 2; j++)
                {
                    vm.PushValue(j);
                }
            }
            else
            {
                fixStack(a, vm);
            }
        }