internal static void Jmp(Instruction i, ref LuaVM vm) { var(a, sBx) = i.AsBx(); vm.AddPC(sBx); if (a != 0) { vm.CloseUpvalues(a); } }
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); }
// 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); } }
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); } }
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); }
internal static void test(Instruction i, ref LuaVM vm) { var abc = i.ABC(); var a = abc.Item1 + 1; var b = abc.Item2 + 1; var c = abc.Item3 + 1; if (vm.ToBoolean(a) != (c != 0)) { vm.AddPC(1); } }
internal static void jmp(Instruction i, ref LuaVM vm) { var asBx = i.AsBx(); var a = asBx.Item1; var sBx = asBx.Item2; vm.AddPC(sBx); if (a != 0) { throw new Exception("todo: jmp!"); } }
internal static void Test(Instruction i, ref LuaVM vm) { var(a, _, c) = i.ABC(); a += 1; c += 1; if (vm.ToBoolean(a) != (c != 0)) { vm.AddPC(1); } }
internal static void loadBool(Instruction i, ref LuaVM vm) { var abc = i.ABC(); var a = abc.Item1 + 1; var b = abc.Item2; var c = abc.Item3; vm.PushBoolean(b != 0); vm.Replace(a); if (c != 0) { vm.AddPC(1); } }
private static void Compare(Instruction i, ref LuaVM vm, CompareOp op) { var(a, b, c) = i.ABC(); vm.GetRK(b); vm.GetRK(c); var br = vm.Compare(-2, -1, op) != (a != 0); if (br) { vm.AddPC(1); } vm.Pop(2); }
internal static void testSet(Instruction i, ref LuaVM vm) { var abc = i.ABC(); var a = abc.Item1 + 1; var b = abc.Item2 + 1; var c = abc.Item3 + 1; if (vm.ToBoolean(b) == (c != 0)) { vm.Copy(b, a); } else { vm.AddPC(1); } }
internal static void _compare(Instruction i, ref LuaVM vm, CompareOp op) { var abc = i.ABC(); var a = abc.Item1; var b = abc.Item2; var c = abc.Item3; vm.GetRK(b); vm.GetRK(c); if (vm.Compare(-2, -1, op) != (a != 0)) { vm.AddPC(1); } vm.Pop(2); }
internal static void TestSet(Instruction i, ref LuaVM vm) { var(a, b, c) = i.ABC(); a += 1; b += 1; c += 1; if (vm.ToBoolean(b) == (c != 0)) { vm.Copy(b, a); } else { vm.AddPC(1); } }
internal static void ForLoop(Instruction i, ref LuaVM vm) { var(a, sBx) = i.AsBx(); a += 1; // R(A)+=R(A+2); vm.PushValue(a + 2); vm.PushValue(a); vm.Arith(Constant.LUA_OPADD); vm.Replace(a); var isPositiveStep = vm.ToNumber(a + 2) >= 0; if ( (isPositiveStep && vm.Compare(a, a + 1, Constant.LUA_OPLE)) || (!isPositiveStep && vm.Compare(a + 1, a, Constant.LUA_OPLE))) { // pc+=sBx; R(A+3)=R(A) vm.AddPC(sBx); vm.Copy(a, a + 3); } }