@Override public void write(Kryo kryo, Output output, PyLong object) { byte[] data = object.getValue().toByteArray(); output.writeShort(data.length); output.writeBytes(data); }
private static final BigInteger coerce(PyObject other) { if (other instanceof PyLong) { return ((PyLong)other).getValue(); } else if (other instanceof PyInteger) { return BigInteger.valueOf(((PyInteger)other).getValue()); } else { throw Py.TypeError("xxx"); } }
private static final long __long__value(PyObject value) { PyObject l = value.__long__(); if (l instanceof PyLong) { return ((PyLong) l).getValue().longValue(); } else if (l instanceof PyInteger) { return ((PyInteger) l).getValue(); } throw Py.TypeError("invalid __long__() result"); }
@ExposedMethod(type = MethodType.CMP, doc = BuiltinDocs.long___cmp___doc) final int long___cmp__(PyObject other) { if (!canCoerce(other)) { return -2; } return getValue().compareTo(coerce(other)); }
@ExposedMethod(doc = BuiltinDocs.long___abs___doc) final PyObject long___abs__() { if (getValue().signum() == -1) { return long___neg__(); } return long___long__(); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___add___doc) final PyObject long___add__(PyObject right) { if (!canCoerce(right)) { return null; } return Py.newLong(getValue().add(coerce(right))); }
public static int intValue(PyObject parameter) { if (parameter instanceof PyInteger) { return ((PyInteger) parameter).getValue(); } else if (parameter instanceof PyLong) { return ((PyLong) parameter).getValue().intValue(); } else if (parameter instanceof ScalarCData) { return intValue(((ScalarCData) parameter).getValue()); } else { return (int) __long__value(parameter); } }
public static long longValue(PyObject parameter) { if (parameter instanceof PyInteger) { return ((PyInteger) parameter).getValue(); } else if (parameter instanceof PyLong) { return ((PyLong) parameter).getValue().longValue(); } else if (parameter instanceof ScalarCData) { return longValue(((ScalarCData) parameter).getValue()); } else { return __long__value(parameter); } } }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rshift___doc) final PyObject long___rshift__(PyObject right) { if (!canCoerce(right)) { return null; } int rightv = coerceInt(right); if (rightv < 0) { throw Py.ValueError("negative shift count"); } return Py.newLong(getValue().shiftRight(rightv)); }
static final DirectMemory getMemoryForAddress(PyObject address) { if (address instanceof Pointer) { return ((Pointer) address).getMemory(); } else if (address instanceof PyInteger) { return new NativeMemory(address.asInt()); } else if (address instanceof PyLong) { return new NativeMemory(((PyLong) address).getValue().longValue()); } throw Py.TypeError("invalid address"); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rtruediv___doc) final PyObject long___rtruediv__(PyObject left) { if (!canCoerce(left)) { return null; } return true_divide(coerce(left), this.getValue()); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rdivmod___doc) final PyObject long___rdivmod__(PyObject left) { if (!canCoerce(left)) { return null; } BigInteger leftv = coerce(left); BigInteger xdivy = divide(leftv, getValue()); return new PyTuple(Py.newLong(xdivy), Py.newLong(modulo(leftv, getValue(), xdivy))); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___truediv___doc) final PyObject long___truediv__(PyObject right) { if (!canCoerce(right)) { return null; } return true_divide(this.getValue(), coerce(right)); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rmul___doc) final PyObject long___rmul__(PyObject left) { if (left instanceof PySequence) { return ((PySequence)left).repeat(coerceInt(this)); } if (!canCoerce(left)) { return null; } return Py.newLong(coerce(left).multiply(getValue())); }
@ExposedMethod(type = MethodType.BINARY, defaults = {"null"}, doc = BuiltinDocs.long___pow___doc) final PyObject long___pow__(PyObject right, PyObject modulo) { if (!canCoerce(right)) { return null; } modulo = (modulo == Py.None) ? null : modulo; if (modulo != null && !canCoerce(modulo)) { return null; } return _pow(getValue(), coerce(right), modulo, this, right); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___floordiv___doc) final PyObject long___floordiv__(PyObject right) { if (!canCoerce(right)) { return null; } return Py.newLong(divide(getValue(), coerce(right))); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rfloordiv___doc) final PyObject long___rfloordiv__(PyObject left) { if (!canCoerce(left)) { return null; } return Py.newLong(divide(coerce(left), getValue())); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.long___rxor___doc) final PyObject long___rxor__(PyObject left) { if (!canCoerce(left)) { return null; } return Py.newLong(coerce(left).xor(getValue())); }