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