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); }
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); } }
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); }
private static void PopResults(int a, int c, ILuaVM vm) { if (c == 1) { } else if (c > 1) { for (var i = a + c - 2; i >= a; i--) { vm.Replace(i); } } else { vm.CheckStack(1); vm.PushInteger(a); } }
//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); } }
/// <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()); } }
/// <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); } }
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); } }
//(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); } }