/// <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); }
/// <summary> /// UpValue[B] = R(A) /// </summary> public static void SetUpval(Instruction ins, ILuaVM vm) { ins.ABC(out var a, out var b, out _); a += 1; b += 1; vm.Copy(a, vm.LuaUpvalueIndex(b)); }
internal static void LoadK(Instruction i, ILuaVM vm) { var(a, bx) = i.ABx(); a += 1; vm.GetConst(bx); vm.Replace(a); }
/// <summary> /// R(A) = R(B) /// </summary> public static void Move(Instruction ins, ILuaVM vm) { ins.ABC(out var a, out var b, out _); a += 1; b += 1; vm.Copy(b, a); }
public static void Move(int i, ILuaVM vm) { int a = Instruction.GetA(i) + 1; int b = Instruction.GetB(i) + 1; vm.Copy(b, a); }
//R(A) := {} (size = B,C) public static void NewTable(int i, ILuaVM vm) { int a = Instruction.GetA(i) + 1; int b = Instruction.GetB(i) + 1; int c = Instruction.GetC(i); vm.GetRK(c); }
public static void LoadKx(int i, ILuaVM vm) { int a = Instruction.GetA(i) + 1; int ax = Instruction.GetAx(vm.Fetch()); vm.GetConst(ax); vm.Replace(a); }
public static void LoadK(int i, ILuaVM vm) { int a = Instruction.GetA(i) + 1; int bx = Instruction.GetBx(i); vm.GetConst(bx); vm.Replace(a); }
/// <summary> /// R(A) = Kst(extra arg) /// </summary> public static void LoadKx(Instruction ins, ILuaVM vm) { ins.ABx(out var a, out _); a += 1; new Instruction(vm.Fetch()).Ax(out var ax); vm.GetConst(ax); vm.Replace(a); }
/// <summary> /// R(A) = {} (size = B, C) /// </summary> public static void NewTable(Instruction ins, ILuaVM vm) { ins.ABC(out var a, out var b, out var c); a += 1; vm.CreateTable(Fpb.Fb2Int(b), Fpb.Fb2Int(c)); vm.Replace(a); }
internal static void GetUpval(Instruction i, ILuaVM vm) { var(a, b, _) = i.ABC(); a += 1; b += 1; vm.Copy(LuaState.LuaUpvalueIndex(b), a); }
/// <summary> /// UpValue[A][RK(B)] = RK(C) /// </summary> public static void SetTabUp(Instruction ins, ILuaVM vm) { ins.ABC(out var a, out var b, out var c); a += 1; vm.GetRK(b); vm.GetRK(c); vm.SetTable(vm.LuaUpvalueIndex(a)); }
public void Execute(ILuaVM luaVM) { var action = OpCodes.Codes[(int)Opcode()].Action; if (!(action is null)) { action(this, luaVM); }
/// <summary> /// R(A + 3, ..., R(A + 2 + C) = R(A)(R(A + 1), R(A + 2)) /// </summary> public static void TForCall(Instruction ins, ILuaVM vm) { ins.ABC(out var a, out _, out var c); a += 1; PushFuncAndArgs(a, 3, vm); vm.Call(2, c); PopResults(a + 3, c + 1, vm); }
/// <summary> /// R(A) = closure(KPROTO[Bx]) /// </summary> public static void Closure(Instruction ins, ILuaVM vm) { ins.ABx(out var a, out var bx); a += 1; vm.LoadProto(bx); vm.Replace(a); }
internal static void NewTable(Instruction i, ILuaVM vm) { var(a, b, c) = i.ABC(); a += 1; vm.CreateTable(Fb2int(b), Fb2int(c)); vm.Replace(a); }
//(iBx) R(A) := closure(KPROTO[Bx]) public static void Closure(int i, ILuaVM vm) { int a = Instruction.GetA(i); int bx = Instruction.GetBx(i); vm.LoadProto(bx); vm.Replace(a); }
internal static void Closure(Instruction i, ILuaVM vm) { var(a, bx) = i.ABx(); a += 1; vm.LoadProto(bx); vm.Replace(a); }
/// <summary> /// R(A) = Kst(Bx) /// </summary> public static void LoadK(Instruction ins, ILuaVM vm) { ins.ABx(out var a, out var bx); a += 1; vm.GetConst(bx); vm.Replace(a); }
public static void SetTable(Instruction i, ILuaVM vm) { var(a, b, c) = i.ABC(); a += 1; vm.GetRK(b); vm.GetRK(c); vm.SetTable(a); }
internal static void Not(Instruction i, ILuaVM vm) { var(a, b, _) = i.ABC(); a += 1; b += 1; vm.PushBoolean(!vm.ToBoolean(b)); vm.Replace(a); }
internal static void TForCall(Instruction i, ILuaVM vm) { var(a, _, c) = i.ABC(); a += 1; PushFuncAndArgs(a, 3, vm); vm.Call(2, c); PopResults(a + 3, c + 1, vm); }
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); }
internal static void SetTabUp(Instruction i, ILuaVM vm) { var(a, b, c) = i.ABC(); a += 1; vm.GetRK(b); vm.GetRK(c); vm.SetTable(LuaState.LuaUpvalueIndex(a)); }
internal static void LoadKx(Instruction i, ILuaVM vm) { var(a, _) = i.ABx(); a += 1; int ax = ((Instruction)vm.Fetch()).Ax(); vm.GetConst(ax); vm.Replace(a); }
/// <summary> /// R(A)[RK(B)] = RK(C) /// </summary> public static void SetTable(Instruction ins, ILuaVM vm) { ins.ABC(out var a, out var b, out var c); a += 1; vm.GetRK(b); vm.GetRK(c); vm.SetTable(a); }
internal static void Len(Instruction i, ILuaVM vm) { var(a, b, _) = i.ABC(); a += 1; b += 1; vm.Len(b); vm.Replace(a); }
/// <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); } }
internal static void Call(Instruction i, ILuaVM vm) { var(a, b, c) = i.ABC(); a += 1; int nArgs = PushFuncAndArgs(a, b, vm); vm.Call(nArgs, c - 1); PopResults(a, c, vm); }
/// <summary> /// R(A), ..., R(A + C - 2) = R(A)(R(A + 1), ..., R(A + B - 1)) /// </summary> public static void Call(Instruction ins, ILuaVM vm) { ins.ABC(out var a, out var b, out var c); a += 1; var nArgs = PushFuncAndArgs(a, b, vm); vm.Call(nArgs, c - 1); PopResults(a, c, vm); }