예제 #1
0
        private static void printOperands(Instruction i)
        {
            int a, b, c, ax, bx, sbx;

            switch (i.OpMode())
            {
            case OpCodes.IABC:
                var abc = i.ABC();
                Console.Write($"{abc.Item1:D}", abc.Item1);
                if (i.BMode() != OpCodes.OpArgN)
                {
                    if (abc.Item2 > 0xFF)
                    {
                        Console.Write($" {-1 - (abc.Item2 & 0xFF):D}");
                    }
                    else
                    {
                        Console.Write($" {abc.Item2:D}");
                    }
                }

                if (i.CMode() != OpCodes.OpArgN)
                {
                    if (abc.Item3 > 0xFF)
                    {
                        Console.Write($"{-1 - (abc.Item3 & 0xFF):D}");
                    }
                    else
                    {
                        Console.Write($" {abc.Item3:D}");
                    }
                }

                break;

            case OpCodes.IABx:
                var aBx = i.ABx();
                Console.Write($" {aBx.Item1:D}");
                if (i.BMode() == OpCodes.OpArgK)
                {
                    Console.Write($"{-1 - aBx.Item2:D}");
                }
                else if (i.BMode() == OpCodes.OpArgU)
                {
                    Console.Write($" {aBx.Item2:D}");
                }

                break;

            case OpCodes.IAsBx:
                var asBx = i.AsBx();
                Console.Write($"{asBx.Item1:D} {asBx.Item2:D}");
                break;

            case OpCodes.IAx:
                ax = i.Ax();
                Console.Write($"{-1 - ax:D}");
                break;
            }
        }
예제 #2
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);
        }
    }
예제 #3
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);
    }
예제 #4
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)
        }
    }