Skip to content

Commit

Permalink
Merge branch 'master' into methods-opt
Browse files Browse the repository at this point in the history
  • Loading branch information
patiences committed Aug 22, 2018
2 parents ff49cba + 2a211d5 commit efe84be
Show file tree
Hide file tree
Showing 32 changed files with 212 additions and 378 deletions.
8 changes: 0 additions & 8 deletions python/common/org/python/Object.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ public interface Object extends Comparable {
*/
public java.lang.String typeName();

/**
* Return a version of the object that can be used when returning by
* value. For most objects, this will be itself; but primitive types
* need to return a copy of themselves to ensure that they aren't
* modified.
*/
public org.python.Object byValue();

/**
* Python interface compatibility
* Section 3.3.1 - Basic customization
Expand Down
22 changes: 5 additions & 17 deletions python/common/org/python/types/Bool.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,10 @@ public static org.python.types.Bool getBool(long int_val) {
return org.python.types.Bool.FALSE;
}

/**
* A utility method to update the internal value of this object.
*
* Used by __i*__ operations to do an in-place operation.
* obj must be of type org.python.types.Bool
*/
void setValue(org.python.Object obj) {
this.value = ((org.python.types.Bool) obj).value;
}

public java.lang.Object toJava() {
return this.value;
}

public org.python.Object byValue() {
return org.python.types.Bool.getBool(this.value);
}

public int hashCode() {
return new java.lang.Boolean(this.value).hashCode();
}
Expand All @@ -57,8 +43,10 @@ private Bool(boolean bool) {
public Bool(org.python.Object[] args, java.util.Map<java.lang.String, org.python.Object> kwargs) {
if (args[0] == null) {
this.value = false;
} else {
} else if (args.length == 1) {
this.value = args[0].toBoolean();
} else {
throw new org.python.exceptions.TypeError("bool() takes at most 1 argument (" + args.length + " given)");
}
}
// public org.python.Object __new__() {
Expand Down Expand Up @@ -173,7 +161,7 @@ public org.python.Object __ge__(org.python.Object other) {
__doc__ = "self != 0"
)
public org.python.types.Bool __bool__() {
return org.python.types.Bool.getBool(this.value);
return this;
}

public boolean __setattr_null(java.lang.String name, org.python.Object value) {
Expand Down Expand Up @@ -338,7 +326,7 @@ public org.python.Object __mod__(org.python.Object other) {
}
} else if (other_val > 1) {
if (org.Python.VERSION < 0x03060000) {
return org.python.types.Bool.getBool(this.value);
return this;
} else {
return org.python.types.Int.getInt(1);
}
Expand Down
10 changes: 0 additions & 10 deletions python/common/org/python/types/ByteArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@
public class ByteArray extends org.python.types.Object {
public byte[] value;

/**
* A utility method to update the internal value of this object.
*
* Used by __i*__ operations to do an in-place operation.
* obj must be of type org.python.types.ByteArray
*/
void setValue(org.python.Object obj) {
this.value = ((org.python.types.ByteArray) obj).value;
}

public int hashCode() {
return this.value.hashCode();
}
Expand Down
14 changes: 4 additions & 10 deletions python/common/org/python/types/Bytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
public class Bytes extends org.python.types.Object {
public byte[] value;

/**
* A utility method to update the internal value of this object.
*
* Used by __i*__ operations to do an in-place operation.
* obj must be of type org.python.types.Bytes
*/
void setValue(org.python.Object obj) {
this.value = ((org.python.types.Bytes) obj).value;
}

public int hashCode() {
return this.value.hashCode();
}
Expand Down Expand Up @@ -52,6 +42,10 @@ public Bytes(org.python.Object[] args, java.util.Map<java.lang.String, org.pytho
org.python.Object encoding = args[1];
org.python.Object errors = args[2];

if (args.length > 3) {
throw new org.python.exceptions.TypeError("bytes() takes at most 3 arguments (" + args.length + " given)");
}

if (encoding != null && !(encoding instanceof org.python.types.Str)) {
throw new org.python.exceptions.TypeError("bytes() argument 2 must be str, not " + encoding.typeName());
} else if (errors != null && !(errors instanceof org.python.types.Str)) {
Expand Down
9 changes: 0 additions & 9 deletions python/common/org/python/types/Closure.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
public class Closure extends org.python.types.Object {
public java.util.List<java.util.Map<java.lang.String, org.python.Object>> locals_list;

/**
* A utility method to update the internal value of this object.
*
* Used by __i*__ operations to do an in-place operation.
* obj must be of type org.python.types.Closure
*/
void setValue(org.python.Object obj) {
}

public Closure(java.util.List<java.util.Map<java.lang.String, org.python.Object>> locals_list) {
super();
this.locals_list = locals_list;
Expand Down
25 changes: 0 additions & 25 deletions python/common/org/python/types/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,6 @@ public class Code extends org.python.types.Object {
@org.python.Attribute
org.python.types.Tuple co_varnames;

/**
* A utility method to update the internal value of this object.
*
* Used by __i*__ operations to do an in-place operation.
* obj must be of type org.python.types.Class
*/
void setValue(org.python.Object obj) {
org.python.types.Object object = (org.python.types.Object) obj;
this.co_argcount = (org.python.types.Int) object.__getattribute__("co_argcount");
this.co_cellvars = (org.python.types.Tuple) object.__getattribute__("co_cellvars");
this.co_code = (org.python.types.Bytes) object.__getattribute__("co_code");
this.co_consts = (org.python.types.Tuple) object.__getattribute__("co_consts");
this.co_filename = (org.python.types.Str) object.__getattribute__("co_filename");
this.co_firstlineno = (org.python.types.Int) object.__getattribute__("co_firstlineno");
this.co_flags = (org.python.types.Int) object.__getattribute__("co_flags");
this.co_freevars = (org.python.types.Tuple) object.__getattribute__("co_freevars");
this.co_kwonlyargcount = (org.python.types.Int) object.__getattribute__("co_kwonlyargcount");
this.co_lnotab = (org.python.types.Bytes) object.__getattribute__("co_lnotab");
this.co_name = (org.python.types.Str) object.__getattribute__("co_name");
this.co_names = (org.python.types.Tuple) object.__getattribute__("co_names");
this.co_nlocals = (org.python.types.Int) object.__getattribute__("co_nlocals");
this.co_stacksize = (org.python.types.Int) object.__getattribute__("co_stacksize");
this.co_varnames = (org.python.types.Tuple) object.__getattribute__("co_varnames");
}

public Code(
org.python.types.Int co_argcount,
org.python.types.Tuple co_cellvars,
Expand Down
8 changes: 2 additions & 6 deletions python/common/org/python/types/Complex.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ public java.lang.Object toJava() {
return this;
}

public org.python.Object byValue() {
throw new org.python.exceptions.AttributeError("type object 'complex' has no attribute 'byValue'");
}

public int hashCode() {
return this.hashCode();
}
Expand Down Expand Up @@ -375,7 +371,7 @@ public org.python.Object __truediv__(org.python.Object other) {
if (!((Bool) other).value) {
throw new org.python.exceptions.ZeroDivisionError("complex division by zero");
}
return new org.python.types.Complex(this.real, this.imag);
return this;
} else if (other instanceof org.python.types.Float) {
if (((Float) other).value == 0.0) {
throw new org.python.exceptions.ZeroDivisionError("complex division by zero");
Expand Down Expand Up @@ -668,7 +664,7 @@ public org.python.Object __neg__() {
__doc__ = "+self"
)
public org.python.Object __pos__() {
return new org.python.types.Complex(this.real, this.imag);
return this;
}

@org.python.Method(
Expand Down
10 changes: 0 additions & 10 deletions python/common/org/python/types/Dict.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
public class Dict extends org.python.types.Object {
public java.util.Map<org.python.Object, org.python.Object> value;

/**
* A utility method to update the internal value of this object.
* <p>
* Used by __i*__ operations to do an in-place operation.
* obj must be of type org.python.types.Dict
*/
void setValue(org.python.Object obj) {
this.value = ((org.python.types.Dict) obj).value;
}

public java.lang.Object toJava() {
return this.value;
}
Expand Down
10 changes: 0 additions & 10 deletions python/common/org/python/types/DictItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ public class DictItems extends org.python.types.Object {
org.python.types.Type.declarePythonType(DictItems.class, "dict_items", null, null);
}

/**
* A utility method to update the internal value of this object.
* <p>
* Used by __i*__ operations to do an in-place operation.
* obj must be of type org.python.types.DictItems
*/
void setValue(org.python.Object obj) {
this.value = ((org.python.types.DictItems) obj).value;
}

public java.lang.Object toJava() {
return this.value;
}
Expand Down
10 changes: 0 additions & 10 deletions python/common/org/python/types/DictKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ public class DictKeys extends org.python.types.FrozenSet {
org.python.types.Type.declarePythonType(DictKeys.class, "dict_keys", null, null);
}

/**
* A utility method to update the internal value of this object.
*
* Used by __i*__ operations to do an in-place operation.
* obj must be of type org.python.types.FrozenSet
*/
void setValue(org.python.Object obj) {
this.value = ((org.python.types.DictKeys) obj).value;
}

@Override
public org.python.Object __hash__() {
throw new org.python.exceptions.AttributeError(this, "__hash__");
Expand Down
10 changes: 0 additions & 10 deletions python/common/org/python/types/DictValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ public class DictValues extends org.python.types.Object {
org.python.types.Type.declarePythonType(DictValues.class, "dict_values", null, null);
}

/**
* A utility method to update the internal value of this object.
* <p>
* Used by __i*__ operations to do an in-place operation.
* obj must be of type org.python.types.DictValues
*/
void setValue(org.python.Object obj) {
this.value = ((org.python.types.DictValues) obj).value;
}

public java.lang.Object toJava() {
return this.value;
}
Expand Down
48 changes: 20 additions & 28 deletions python/common/org/python/types/Float.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,10 @@ public class Float extends org.python.types.Object {
private static final long NEGATIVE_ZERO_RAW_BITS = Double.doubleToRawLongBits(-0.0);
public double value;

/**
* A utility method to update the internal value of this object.
*
* Used by __i*__ operations to do an in-place operation.
* obj must be of type org.python.types.Float
*/
void setValue(org.python.Object obj) {
this.value = ((org.python.types.Float) obj).value;
}

public java.lang.Object toJava() {
return this.value;
}

public org.python.Object byValue() {
return new org.python.types.Float(this.value);
}

public int hashCode() {
return new java.lang.Double(this.value).hashCode();
}
Expand All @@ -43,15 +29,21 @@ public Float(double value) {
__doc__ = "float(x) -> floating point number" +
"\n" +
"Convert a string or number to a floating point number, if possible.\n",
args = {"x"}
default_args = {"x"}
)
public Float(org.python.Object[] args, java.util.Map<java.lang.String, org.python.Object> kwargs) {
try {
this.value = ((org.python.types.Float) args[0].__float__()).value;
} catch (org.python.exceptions.AttributeError ae) {
throw new org.python.exceptions.TypeError(
"float() argument must be a string or a number, not '" + args[0].typeName() + "'"
);
if (args[0] == null) {
this.value = 0.0;
} else if (args.length == 1) {
try {
this.value = ((org.python.types.Float) args[0].__float__()).value;
} catch (org.python.exceptions.AttributeError ae) {
throw new org.python.exceptions.TypeError(
"float() argument must be a string or a number, not '" + args[0].typeName() + "'"
);
}
} else {
throw new org.python.exceptions.TypeError("float() takes at most 1 argument (" + args.length + " given)");
}
}

Expand Down Expand Up @@ -264,7 +256,7 @@ public org.python.Object __add__(org.python.Object other) {
if (((org.python.types.Bool) other).value) {
return new org.python.types.Float(this.value + 1.0);
}
return new org.python.types.Float(this.value);
return this;
} else if (other instanceof org.python.types.Float) {
double other_val = ((org.python.types.Float) other).value;
return new org.python.types.Float(this.value + other_val);
Expand All @@ -289,7 +281,7 @@ public org.python.Object __sub__(org.python.Object other) {
if (((org.python.types.Bool) other).value) {
return new org.python.types.Float(this.value - 1.0);
}
return new org.python.types.Float(this.value);
return this;
} else if (other instanceof org.python.types.Complex) {
return new org.python.types.Complex(
new org.python.types.Float(this.value - ((org.python.types.Complex) other).real.value),
Expand Down Expand Up @@ -363,7 +355,7 @@ public org.python.Object __truediv__(org.python.Object other) {
return new org.python.types.Float(this.value / other_val);
} else if (other instanceof org.python.types.Bool) {
if (((org.python.types.Bool) other).value) {
return new org.python.types.Float(this.value);
return this;
} else {
throw new org.python.exceptions.ZeroDivisionError("float division by zero");
}
Expand Down Expand Up @@ -493,7 +485,7 @@ public org.python.Object __pow__(org.python.Object other, org.python.Object modu
return new org.python.types.Float(java.lang.Math.pow(this.value, other_val));
} else if (other instanceof org.python.types.Bool) {
if (((org.python.types.Bool) other).value) {
return new org.python.types.Float(this.value);
return this;
} else {
return new org.python.types.Float(1);
}
Expand Down Expand Up @@ -596,7 +588,7 @@ public org.python.Object __neg__() {
__doc__ = "+self"
)
public org.python.Object __pos__() {
return new org.python.types.Float(this.value);
return this;
}

@org.python.Method(
Expand All @@ -606,7 +598,7 @@ public org.python.Object __abs__() {
if (this.value < 0.0) {
return new org.python.types.Float(-this.value);
} else {
return new org.python.types.Float(this.value);
return this;
}
}

Expand All @@ -621,7 +613,7 @@ public org.python.Object __int__() {
__doc__ = "float(self)"
)
public org.python.Object __float__() {
return new org.python.types.Float(this.value);
return this;
}

@org.python.Method(
Expand Down
10 changes: 0 additions & 10 deletions python/common/org/python/types/FrozenSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
public class FrozenSet extends org.python.types.Object {
public java.util.Set<org.python.Object> value;

/**
* A utility method to update the internal value of this object.
*
* Used by __i*__ operations to do an in-place operation.
* obj must be of type org.python.types.FrozenSet
*/
void setValue(org.python.Object obj) {
this.value = ((org.python.types.FrozenSet) obj).value;
}

public java.lang.Object toJava() {
return this.value;
}
Expand Down
Loading

0 comments on commit efe84be

Please sign in to comment.