/// <summary> /// 执行算术和按位运算 /// </summary> public void Arith(EArithOp op) { var b = _stack.Pop(); var a = b; if (op != EArithOp.Unm && op != EArithOp.BNot) { a = _stack.Pop(); } var o = Operators.Ops[(int)op]; var ret = InnerArith(a, b, o); if (ret != null) { _stack.Push(ret); return; } var mm = Operators.Ops[(int)op].MetaMethod; if (LuaValue.CallMetaMethod(a, b, mm, this, out ret)) { _stack.Push(ret); return; } Debug.Panic("arithmetic error!"); }
/// <summary> /// R(A) = op R(B) /// </summary> private static void UnaryArith(Instruction ins, ILuaVM vm, EArithOp op) { ins.ABC(out var a, out var b, out _); a += 1; b += 1; vm.PushValue(b); vm.Arith(op); vm.Replace(a); }
/// <summary> /// R(A) = RK(B) op RK(C) /// </summary> private static void BinaryArith(Instruction ins, ILuaVM vm, EArithOp op) { ins.ABC(out var a, out var b, out var c); a += 1; vm.GetRK(b); vm.GetRK(c); vm.Arith(op); vm.Replace(a); }