예제 #1
0
 internal static void Move(Instruction i, ref LuaVM vm)
 {
     var(a, b, _) = i.ABC();
     a           += 1;
     b           += 1;
     vm.Copy(b, a);
 }
예제 #2
0
        public void Execute(LuaVM vm)
        {
            var action = OpCodes.opcodes[Opcode()].action;

            //Console.Write(Opcode());
            //printStack(vm);

//            var ints = new int[] {11, 45, 43, 4};
//            foreach (var i in ints)
//            {
//                if (Opcode() == i)
//                {
//                    Console.Write(Opcode());
//                    printStack(vm);
//                }
//            }

            if (action != null)
            {
                action(this, ref vm);
            }
            else
            {
                throw new Exception(OpName());
            }
        }
예제 #3
0
        // R(A) := closure(KPROTO[Bx])
        internal static void closure(Instruction i, ref LuaVM vm)
        {
            var(a, Bx) = i.ABx();
            a         += 1;

            vm.LoadProto(Bx);
            vm.Replace(a);
        }
예제 #4
0
        internal static void getUpval(Instruction i, ref LuaVM vm)
        {
            var(a, b, _) = i.ABC();
            a           += 1;
            b           += 1;

            vm.Copy(LuaVM.LuaUpvalueIndex(b), a);
        }
예제 #5
0
        internal static void NewTable(Instruction i, ref LuaVM vm)
        {
            var(a, b, c) = i.ABC();
            a           += 1;

            vm.CreateTable(Fpb.Fb2Int(b), Fpb.Fb2Int(c));
            vm.Replace(a);
        }
예제 #6
0
        internal static void loadK(Instruction i, ref LuaVM vm)
        {
            var(a, bx) = i.ABx();
            a         += 1;

            vm.GetConst(bx);
            vm.Replace(a);
        }
예제 #7
0
        internal static void move(Instruction i, ref LuaVM vm)
        {
            var ab_ = i.ABC();
            var a   = ab_.Item1 + 1;
            var b   = ab_.Item2 + 1;

            vm.Copy(b, a);
        }
예제 #8
0
        // UpValue[A][RK(B)] := RK(C)
        internal static void setTabUp(Instruction i, ref LuaVM vm)
        {
            var(a, b, c) = i.ABC();
            a           += 1;

            vm.GetRK(b);
            vm.GetRK(c);
            vm.SetTable(LuaVM.LuaUpvalueIndex(a));
        }
예제 #9
0
        // R(A) := closure(KPROTO[Bx])
        internal static void closure(Instruction i, ref LuaVM vm)
        {
            var aBx = i.ABx();
            var a   = aBx.Item1 + 1;
            var bx  = aBx.Item2;

            vm.LoadProto(bx);
            vm.Replace(a);
        }
예제 #10
0
        internal static void loadKx(Instruction i, ref LuaVM vm)
        {
            var aBx = i.ABx();
            var a   = aBx.Item1 + 1;
            var ax  = new Instruction(vm.Fetch()).Ax();

            vm.GetConst(ax);
            vm.Replace(a);
        }
예제 #11
0
        internal static void loadK(Instruction i, ref LuaVM vm)
        {
            var aBx = i.ABx();
            var a   = aBx.Item1 + 1;
            var bx  = aBx.Item2;

            vm.GetConst(bx);
            vm.Replace(a);
        }
예제 #12
0
        internal static void TForCall(Instruction i, ref LuaVM vm)
        {
            var(a, _, c) = i.ABC();
            a           += 1;

            PushFuncAndArgs(a, 3, ref vm);
            vm.Call(2, c);
            PopResults(a + 3, c + 1, ref vm);
        }
예제 #13
0
        internal static void length(Instruction i, ref LuaVM vm)
        {
            var abc = i.ABC();
            var a   = abc.Item1 + 1;
            var b   = abc.Item2 + 1;

            vm.Len(b);
            vm.Replace(a);
        }
예제 #14
0
        internal static void loadKx(Instruction i, ref LuaVM vm)
        {
            var(a, _) = i.ABx();
            a        += 1;
            var ax = new Instruction(vm.Fetch()).Ax();

            vm.GetConst(ax);
            vm.Replace(a);
        }
예제 #15
0
        internal static void Not(Instruction i, ref LuaVM vm)
        {
            var(a, b, _) = i.ABC();
            a           += 1;
            b           += 1;

            vm.PushBoolean(!vm.ToBoolean(b));
            vm.Replace(a);
        }
예제 #16
0
        internal static void length(Instruction i, ref LuaVM vm)
        {
            var(a, b, _) = i.ABC();
            a           += 1;
            b           += 1;

            vm.Len(b);
            vm.Replace(a);
        }
예제 #17
0
        internal static void SetTable(Instruction i, ref LuaVM vm)
        {
            var(a, b, c) = i.ABC();
            a           += 1;

            vm.GetRK(b);
            vm.GetRK(c);
            vm.SetTable(a);
        }
예제 #18
0
        private 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);
        }
예제 #19
0
        // R(A) := UpValue[B][RK(C)]
        internal static void getTabUp(Instruction i, ref LuaVM vm)
        {
            var(a, b, c) = i.ABC();
            a           += 1;
            b           += 1;

            vm.GetRK(c);
            vm.GetTable(LuaVM.LuaUpvalueIndex(b));
            vm.Replace(a);
        }
예제 #20
0
        internal static void Jmp(Instruction i, ref LuaVM vm)
        {
            var(a, sBx) = i.AsBx();

            vm.AddPC(sBx);
            if (a != 0)
            {
                vm.CloseUpvalues(a);
            }
        }
예제 #21
0
        // R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1))
        internal static void call(Instruction i, ref LuaVM vm)
        {
            var(a, b, c) = i.ABC();
            a           += 1;
            // println(":::"+ vm.StackToString())
            var nArgs = pushFuncAndArgs(a, b, ref vm);

            vm.Call(nArgs, c - 1);
            popResults(a, c, vm);
        }
예제 #22
0
        private static void _binaryArith(Instruction i, LuaVM vm, ArithOp op)
        {
            var(a, b, c) = i.ABC();
            a           += 1;

            vm.GetRK(b);
            vm.GetRK(c);
            vm.Arith(op);
            vm.Replace(a);
        }
예제 #23
0
        private static void _unaryArith(Instruction i, LuaVM vm, ArithOp op)
        {
            var(a, b, _) = i.ABC();
            a           += 1;
            b           += 1;

            vm.PushValue(b);
            vm.Arith(op);
            vm.Replace(a);
        }
예제 #24
0
        internal static void not(Instruction i, ref 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);
        }
예제 #25
0
        // if R(A+1) ~= nil then {
        //   R(A)=R(A+1); pc += sBx
        // }
        internal static void TForLoop(Instruction i, ref LuaVM vm)
        {
            var(a, sBx) = i.AsBx();
            a          += 1;

            if (!vm.IsNil(a + 1))
            {
                vm.Copy(a + 1, a);
                vm.AddPC(sBx);
            }
        }
예제 #26
0
        internal static void newTable(Instruction i, ref LuaVM vm)
        {
            var abc = i.ABC();
            var a   = abc.Item1;
            var b   = abc.Item2;
            var c   = abc.Item3;

            a += 1;
            vm.CreateTable(Fpb.Fb2int(b), Fpb.Fb2int(c));
            vm.Replace(a);
        }
예제 #27
0
        internal static void forPrep(Instruction i, ref LuaVM vm)
        {
            var(a, sBx) = i.AsBx();
            a          += 1;

            vm.PushValue(a);
            vm.PushValue(a + 2);
            vm.Arith(Consts.LUA_OPSUB);
            vm.Replace(a);
            vm.AddPC(sBx);
        }
예제 #28
0
        // R(A+1) := R(B); R(A) := R(B)[RK(C)]
        internal static void Self(Instruction i, ref LuaVM vm)
        {
            var(a, b, c) = i.ABC();
            a           += 1;
            b           += 1;

            vm.Copy(b, a + 1);
            vm.GetRK(c);
            vm.GetTable(b);
            vm.Replace(a);
        }
예제 #29
0
        internal static void loadBool(Instruction i, ref LuaVM vm)
        {
            var(a, b, c) = i.ABC();
            a           += 1;

            vm.PushBoolean(b != 0);
            vm.Replace(a);
            if (c != 0)
            {
                vm.AddPC(1);
            }
        }
예제 #30
0
        internal static void forPrep(Instruction i, ref 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);
        }