@Override public void write(Kryo kryo, Output output, PyInteger object) { output.writeInt(object.getValue()); }
@Override public PyObject __finditem__(PyObject key) { if (key instanceof PyInteger) { return __finditem__(((PyInteger) key).getValue()); } return __finditem__(key.toString()); }
public static byte py2byte(PyObject o) { if (o instanceof PyInteger) { return (byte) ((PyInteger) o).getValue(); } Object i = o.__tojava__(Byte.TYPE); if (i == null || i == Py.NoConversion) { throw Py.TypeError("integer required"); } return ((Byte) i).byteValue(); }
public static short py2short(PyObject o) { if (o instanceof PyInteger) { return (short) ((PyInteger) o).getValue(); } Object i = o.__tojava__(Short.TYPE); if (i == null || i == Py.NoConversion) { throw Py.TypeError("integer required"); } return ((Short) i).shortValue(); }
public static int py2int(PyObject o, String msg) { if (o instanceof PyInteger) { return ((PyInteger) o).getValue(); } Object obj = o.__tojava__(Integer.TYPE); if (obj == Py.NoConversion) { throw Py.TypeError(msg); } return ((Integer) obj).intValue(); }
public static long py2long(PyObject o) { if (o instanceof PyInteger) { return ((PyInteger) o).getValue(); } Object i = o.__tojava__(Long.TYPE); if (i == null || i == Py.NoConversion) { throw Py.TypeError("integer required"); } return ((Long) i).longValue(); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___and___doc) final PyObject int___and__(PyObject right) { int rightv; if (right instanceof PyInteger) { rightv = ((PyInteger)right).getValue(); } else if (right instanceof PyLong) { return int___long__().__and__(right); } else { return null; } return Py.newInteger(getValue() & rightv); }
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); } } }
@Override public PyObject __rpow__(PyObject left) { if (!canCoerce(left)) { return null; } return _pow(coerce(left), getValue(), null, left, this); }
@ExposedMethod final int instance___len__() { PyObject ret = invoke("__len__"); if (ret instanceof PyInteger) return ((PyInteger) ret).getValue(); throw Py.TypeError("__len__() should return an int"); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___sub___doc) final PyObject int___sub__(PyObject right) { if (!canCoerce(right)) { return null; } return _sub(getValue(), coerce(right)); }
@ExposedMethod(type = MethodType.BINARY, defaults = {"null"}, // doc = BuiltinDocs.int___pow___doc) final PyObject int___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.int___rdiv___doc) final PyObject int___rdiv__(PyObject left) { if (!canCoerce(left)) { return null; } if (Options.division_warning > 0) { Py.warning(Py.DeprecationWarning, "classic int division"); } return Py.newInteger(divide(coerce(left), getValue())); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___rmod___doc) final PyObject int___rmod__(PyObject left) { if (!canCoerce(left)) { return null; } int leftv = coerce(left); int v = getValue(); return Py.newInteger(modulo(leftv, v, divide(leftv, v))); }
private final PyComplex coerce(PyObject other) { if (other instanceof PyComplex) { return (PyComplex)other; } else if (other instanceof PyFloat) { return new PyComplex(((PyFloat)other).getValue(), 0); } else if (other instanceof PyInteger) { return new PyComplex(((PyInteger)other).getValue(), 0); } else if (other instanceof PyLong) { return new PyComplex(((PyLong)other).doubleValue(), 0); } throw Py.TypeError("xxx"); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___div___doc) final PyObject int___div__(PyObject right) { if (!canCoerce(right)) { return null; } if (Options.division_warning > 0) { Py.warning(Py.DeprecationWarning, "classic int division"); } return Py.newInteger(divide(getValue(), coerce(right))); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.int___mod___doc) final PyObject int___mod__(PyObject right) { if (!canCoerce(right)) { return null; } int rightv = coerce(right); int v = getValue(); return Py.newInteger(modulo(v, rightv, divide(v, rightv))); }
@ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.bool___or___doc) final PyObject bool___or__(PyObject right) { if (right instanceof PyBoolean) { return Py.newBoolean(getBooleanValue() | ((PyBoolean) right).getBooleanValue()); } else if (right instanceof PyInteger) { return Py.newInteger(getValue() | ((PyInteger)right).getValue()); } else { return null; } }
public void emitNum(Num node, Code code) throws Exception { if (node.getInternalN() instanceof PyInteger) { integerConstant(((PyInteger)node.getInternalN()).getValue()).get(code); } else if (node.getInternalN() instanceof PyLong) { longConstant(((PyObject)node.getInternalN()).__str__().toString()).get(code); } else if (node.getInternalN() instanceof PyFloat) { floatConstant(((PyFloat)node.getInternalN()).getValue()).get(code); } else if (node.getInternalN() instanceof PyComplex) { complexConstant(((PyComplex)node.getInternalN()).imag).get(code); } }