|
75 | 75 | import com.oracle.graal.python.builtins.objects.ints.PInt;
|
76 | 76 | import com.oracle.graal.python.builtins.objects.iterator.PForeignArrayIterator;
|
77 | 77 | import com.oracle.graal.python.builtins.objects.object.ObjectBuiltinsFactory;
|
| 78 | +import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary; |
78 | 79 | import com.oracle.graal.python.nodes.PRaiseNode;
|
79 | 80 | import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
|
80 | 81 | import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
|
81 | 82 | import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
|
82 | 83 | import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
|
83 |
| -import com.oracle.graal.python.nodes.expression.CastToBooleanNode; |
84 | 84 | import com.oracle.graal.python.nodes.expression.CastToListExpressionNode.CastToListNode;
|
85 | 85 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
86 | 86 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
@@ -120,25 +120,10 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
|
120 | 120 | @Builtin(name = __BOOL__, minNumOfPositionalArgs = 1)
|
121 | 121 | @GenerateNodeFactory
|
122 | 122 | abstract static class BoolNode extends PythonUnaryBuiltinNode {
|
123 |
| - @Specialization |
124 |
| - boolean doForeignObject(VirtualFrame frame, Object self, |
125 |
| - @CachedLibrary(limit = "3") InteropLibrary lib, |
126 |
| - @Cached("createIfTrueNode()") CastToBooleanNode cast) { |
127 |
| - try { |
128 |
| - if (lib.isBoolean(self)) { |
129 |
| - return lib.asBoolean(self); |
130 |
| - } else if (lib.fitsInLong(self)) { |
131 |
| - return cast.executeBoolean(frame, lib.asLong(self)); |
132 |
| - } else if (lib.fitsInDouble(self)) { |
133 |
| - return cast.executeBoolean(frame, lib.asDouble(self)); |
134 |
| - } else if (lib.hasArrayElements(self)) { |
135 |
| - return cast.executeBoolean(frame, lib.getArraySize(self)); |
136 |
| - } else { |
137 |
| - return !lib.isNull(self); |
138 |
| - } |
139 |
| - } catch (UnsupportedMessageException e) { |
140 |
| - throw raise(AttributeError, "'foreign' object has no attribute '__bool__'"); |
141 |
| - } |
| 123 | + @Specialization(limit = "1") |
| 124 | + boolean doForeignObject(Object self, |
| 125 | + @CachedLibrary("self") PythonObjectLibrary lib) { |
| 126 | + return lib.isTrue(self); |
142 | 127 | }
|
143 | 128 | }
|
144 | 129 |
|
|
0 commit comments