|
48 | 48 | import com.oracle.graal.python.builtins.CoreFunctions;
|
49 | 49 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
50 | 50 | import com.oracle.graal.python.builtins.objects.PNone;
|
| 51 | +import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; |
| 52 | +import com.oracle.graal.python.builtins.objects.dict.PDict; |
51 | 53 | import com.oracle.graal.python.builtins.objects.ints.PInt;
|
52 | 54 | import com.oracle.graal.python.nodes.SpecialMethodNames;
|
53 | 55 | import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
|
| 56 | +import com.oracle.graal.python.nodes.expression.BinaryComparisonNode; |
54 | 57 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
55 | 58 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
56 | 59 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
57 | 60 | import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
|
| 61 | +import com.oracle.graal.python.runtime.sequence.PSequence; |
58 | 62 | import com.oracle.truffle.api.CompilerDirectives;
|
59 | 63 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
| 64 | +import com.oracle.truffle.api.dsl.Cached; |
60 | 65 | import com.oracle.truffle.api.dsl.Fallback;
|
61 | 66 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
62 | 67 | import com.oracle.truffle.api.dsl.NodeFactory;
|
@@ -136,6 +141,79 @@ public boolean doObject(VirtualFrame frame, Object value) {
|
136 | 141 | }
|
137 | 142 | }
|
138 | 143 |
|
| 144 | + @Builtin(name = "eq", minNumOfPositionalArgs = 2) |
| 145 | + @TypeSystemReference(PythonArithmeticTypes.class) |
| 146 | + @GenerateNodeFactory |
| 147 | + public abstract static class EqualsNode extends PythonBinaryBuiltinNode { |
| 148 | + |
| 149 | + @Specialization |
| 150 | + public boolean doBoolean(boolean value1, boolean value2) { |
| 151 | + return value1 == value2; |
| 152 | + } |
| 153 | + |
| 154 | + @Specialization |
| 155 | + public boolean doNone(@SuppressWarnings("unused") PNone value1, @SuppressWarnings("unused") PNone value2) { |
| 156 | + return true; |
| 157 | + } |
| 158 | + |
| 159 | + @Specialization |
| 160 | + public boolean doInt(long value1, long value2) { |
| 161 | + return value1 == value2; |
| 162 | + } |
| 163 | + |
| 164 | + @Specialization |
| 165 | + @TruffleBoundary |
| 166 | + public boolean doPInt(PInt value1, PInt value2) { |
| 167 | + return value1.getValue().equals(value2.getValue()); |
| 168 | + } |
| 169 | + |
| 170 | + @Specialization |
| 171 | + public boolean doDouble(double value1, double value2) { |
| 172 | + return value1 == value2; |
| 173 | + } |
| 174 | + |
| 175 | + @Specialization |
| 176 | + public boolean doString(String value1, String value2) { |
| 177 | + return value1.equals(value2); |
| 178 | + } |
| 179 | + |
| 180 | + private @Child BinaryComparisonNode equalsNode; |
| 181 | + |
| 182 | + @Fallback |
| 183 | + public boolean doObject(VirtualFrame frame, Object value1, Object value2) { |
| 184 | + if (value1 == value2) { |
| 185 | + return true; |
| 186 | + } |
| 187 | + if (equalsNode == null) { |
| 188 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 189 | + equalsNode = insert((BinaryComparisonNode.create(SpecialMethodNames.__EQ__, SpecialMethodNames.__EQ__, "=="))); |
| 190 | + } |
| 191 | + return equalsNode.executeBool(frame, value1, value2); |
| 192 | + } |
| 193 | + } |
| 194 | + |
| 195 | + @Builtin(name = "getitem", minNumOfPositionalArgs = 2) |
| 196 | + @TypeSystemReference(PythonArithmeticTypes.class) |
| 197 | + @GenerateNodeFactory |
| 198 | + public abstract static class GetItemNode extends PythonBinaryBuiltinNode { |
| 199 | + |
| 200 | + @Specialization |
| 201 | + public Object doDict(PDict dict, Object item) { |
| 202 | + return dict.getItem(item); |
| 203 | + } |
| 204 | + |
| 205 | + @Specialization |
| 206 | + public Object doSequence(PSequence value, Object index, |
| 207 | + @Cached("create()") SequenceStorageNodes.GetItemNode getItemNode) { |
| 208 | + return getItemNode.execute(value.getSequenceStorage(), index); |
| 209 | + } |
| 210 | + |
| 211 | + @Fallback |
| 212 | + public Object doObject(@SuppressWarnings("unused") Object value, @SuppressWarnings("unused") Object index) { |
| 213 | + return PNone.NONE; |
| 214 | + } |
| 215 | + } |
| 216 | + |
139 | 217 | // _compare_digest
|
140 | 218 | @Builtin(name = "_compare_digest", minNumOfPositionalArgs = 2)
|
141 | 219 | @TypeSystemReference(PythonArithmeticTypes.class)
|
|
0 commit comments