public static void SetList(Instruction i, ILuaVM vm) { const int FIELDS_PER_FLUSH = 50; var(a, b, c) = i.ABC(); a += 1; bool bIsZero = b == 0; if (bIsZero) { b = (int)vm.ToInteger(-1) - a - 1; vm.Pop(1); } if (c > 0) { c -= 1; } else { c = ((Instruction)vm.Fetch()).Ax(); } Int64 idx = (Int64)(c * FIELDS_PER_FLUSH); for (int j = 1; j <= b; j++) { idx++; vm.PushValue(a + j); vm.SetI(a, idx); } if (bIsZero) { for (int j = vm.RegisterCount() + 1; j <= vm.GetTop(); j++) { idx++; vm.PushValue(j); vm.SetI(a, idx); } vm.SetTop(vm.RegisterCount()); } }
/// <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()); } }
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); } }