Exemple #1
0
 public LFunction(LFunc F)
 {
     Native     = true;
     NativeFunc = F;
     Top        = 16;
 }
Exemple #2
0
        public void Step()
        {
            if (LFunc.Native)
            {
                LFunc.NativeFunc(this, LFunc);
                Return(LFunc);
                return;
            }

            Instruction I = Func.Code[PC++];

            LObject RKB = GetReg(I.B);
            LObject RKC = GetReg(I.C);

            if (I.B >= (1 << 8))
            {
                RKB = Func.Constants[I.B - (1 << 8)];
            }
            if (I.C >= (1 << 8))
            {
                RKC = Func.Constants[I.C - (1 << 8)];
            }

            if (I == OpCode.MOVE)
            {
            }
            else if (I == OpCode.LOADK)
            {
                SetReg(I.A, Func.Constants[I.Bx]);
            }
            else if (I == OpCode.LOADBOOL)
            {
            }
            else if (I == OpCode.LOADNIL)
            {
            }
            else if (I == OpCode.GETUPVAL)
            {
            }
            else if (I == OpCode.GETGLOBAL)
            {
                SetReg(I.A, Global.Get(Func.Constants[I.Bx]));
            }
            else if (I == OpCode.GETTABLE)
            {
            }
            else if (I == OpCode.SETGLOBAL)
            {
                Global.Set(Func.Constants[I.Bx], GetReg(I.A));
            }
            else if (I == OpCode.SETUPVAL)
            {
            }
            else if (I == OpCode.SETTABLE)
            {
            }
            else if (I == OpCode.NEWTABLE)
            {
            }
            else if (I == OpCode.SELF)
            {
            }
            else if (I == OpCode.ADD)
            {
                SetReg(I.A, Meta.Add(RKB, RKC));
            }
            else if (I == OpCode.SUB)
            {
            }
            else if (I == OpCode.MUL)
            {
            }
            else if (I == OpCode.DIV)
            {
            }
            else if (I == OpCode.MOD)
            {
            }
            else if (I == OpCode.POW)
            {
            }
            else if (I == OpCode.UNM)
            {
            }
            else if (I == OpCode.NOT)
            {
            }
            else if (I == OpCode.LEN)
            {
            }
            else if (I == OpCode.CONCAT)
            {
            }
            else if (I == OpCode.JMP)
            {
            }
            else if (I == OpCode.EQ)
            {
            }
            else if (I == OpCode.LT)
            {
            }
            else if (I == OpCode.LE)
            {
            }
            else if (I == OpCode.TEST)
            {
            }
            else if (I == OpCode.TESTSET)
            {
            }
            else if (I == OpCode.CALL)
            {
                Call(GetReg(I.A).As <LFunction>(), I.A, I.B == 0 ? I.B - 1 : I.B - 1, I.C, false);
            }
            else if (I == OpCode.TAILCALL)
            {
            }
            else if (I == OpCode.RETURN)
            {
                Return(LFunc);
            }
            else if (I == OpCode.FORLOOP)
            {
            }
            else if (I == OpCode.FORPREP)
            {
            }
            else if (I == OpCode.TFORLOOP)
            {
            }
            else if (I == OpCode.SETLIST)
            {
            }
            else if (I == OpCode.CLOSE)
            {
            }
            else if (I == OpCode.CLOSURE)
            {
                SetReg(I.A, Func.Constants.Functions[I.B]);
            }
            else if (I == OpCode.VARARG)
            {
            }
            else
            {
                throw new Exception("Instruction not implemented: " + I.ToString());
            }

            //Console.WriteLine(I);
        }