Skip to content

Commit 16295e9

Browse files
committed
Treat string as primitve.
1 parent 340924b commit 16295e9

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/TruffleObjectBuiltins.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ protected static boolean isNegativeNumber(InteropLibrary lib, Object right) {
203203
}
204204

205205
protected static boolean isPythonLikeSequence(InteropLibrary lib, Object receiver) {
206-
return lib.hasArrayElements(receiver) || lib.isString(receiver);
206+
return lib.hasArrayElements(receiver);
207207
}
208208

209209
@Specialization(guards = {"!reverse", "lib.isBoolean(left)"})
@@ -236,6 +236,15 @@ Object doComparisonDouble(Object left, Object right,
236236
}
237237
}
238238

239+
@Specialization(guards = {"!reverse", "lib.isString(left)"})
240+
Object doComparisonString(Object left, Object right,
241+
@CachedLibrary(limit = "3") InteropLibrary lib) {
242+
try {
243+
return op.executeObject(lib.asString(left), right);
244+
} catch (UnsupportedMessageException e) {
245+
return PNotImplemented.NOT_IMPLEMENTED;
246+
}
247+
}
239248
@Specialization(guards = {"reverse", "lib.isBoolean(right)"})
240249
Object doComparisonBoolR(Object left, Object right,
241250
@CachedLibrary(limit = "3") InteropLibrary lib) {
@@ -266,6 +275,16 @@ Object doComparisonDoubleR(Object left, Object right,
266275
}
267276
}
268277

278+
@Specialization(guards = {"reverse", "lib.isString(right)"})
279+
Object doComparisonStringR(Object left, Object right,
280+
@CachedLibrary(limit = "3") InteropLibrary lib) {
281+
try {
282+
return op.executeObject(left, lib.asString(right));
283+
} catch (UnsupportedMessageException e) {
284+
return PNotImplemented.NOT_IMPLEMENTED;
285+
}
286+
}
287+
269288
@SuppressWarnings("unused")
270289
@Specialization(guards = {"!reverse", "!lib.fitsInDouble(left)", "!lib.fitsInLong(left)", "!lib.isBoolean(left)"})
271290
public PNotImplemented doGeneric(Object left, Object right,
@@ -327,7 +346,7 @@ abstract static class MulNode extends ForeignBinaryNode {
327346
super(BinaryArithmetic.Mul.create(), false);
328347
}
329348

330-
@Specialization(insertBefore = "doGeneric", guards = {"isPythonLikeSequence(lib, left)", "lib.fitsInInt(right)"})
349+
@Specialization(insertBefore = "doComparisonBool", guards = {"isPythonLikeSequence(lib, left)", "lib.fitsInInt(right)"})
331350
static Object doForeignArray(Object left, Object right,
332351
@Cached PRaiseNode raise,
333352
@Cached PythonObjectFactory factory,
@@ -357,7 +376,7 @@ static Object doForeignArray(Object left, Object right,
357376
}
358377
}
359378

360-
@Specialization(insertBefore = "doGeneric", guards = {"isPythonLikeSequence(lib, left)", "lib.isBoolean(right)"})
379+
@Specialization(insertBefore = "doComparisonBool", guards = {"isPythonLikeSequence(lib, left)", "lib.isBoolean(right)"})
361380
static Object doForeignArrayForeignBoolean(Object left, Object right,
362381
@Cached PRaiseNode raise,
363382
@Cached PythonObjectFactory factory,
@@ -395,7 +414,7 @@ abstract static class RMulNode extends ForeignBinaryNode {
395414
super(BinaryArithmetic.Mul.create(), true);
396415
}
397416

398-
@Specialization(guards = {"isPythonLikeSequence(lib, right)", "lib.fitsInInt(left)"})
417+
@Specialization(insertBefore = "doComparisonBool", guards = {"isPythonLikeSequence(lib, right)", "lib.fitsInInt(left)"})
399418
Object doForeignArray(Object right, Object left,
400419
@Cached PRaiseNode raise,
401420
@Cached PythonObjectFactory factory,
@@ -404,7 +423,7 @@ Object doForeignArray(Object right, Object left,
404423
return MulNode.doForeignArray(right, left, raise, factory, convert, lib);
405424
}
406425

407-
@Specialization(guards = {"isPythonLikeSequence(lib, right)", "lib.isBoolean(left)"})
426+
@Specialization(insertBefore = "doComparisonBool", guards = {"isPythonLikeSequence(lib, right)", "lib.isBoolean(left)"})
408427
Object doForeignArrayForeignBoolean(Object right, Object left,
409428
@Cached PRaiseNode raise,
410429
@Cached PythonObjectFactory factory,

0 commit comments

Comments
 (0)