Skip to content

Commit 136c64c

Browse files
committed
[GR-57748] Migrate remaining binary nb slots
PullRequest: graalpython/3631
2 parents ba794c5 + 6bbf4d2 commit 136c64c

File tree

48 files changed

+2480
-2068
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2480
-2068
lines changed

graalpython/com.oracle.graal.python.annotations/src/com/oracle/graal/python/annotations/Slot.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -97,7 +97,30 @@ enum SlotKind {
9797
nb_bool("__bool__"),
9898
/** foo + bar */
9999
nb_add("__add__, __radd__"),
100+
/** foo - bar */
101+
nb_subtract("__sub__, __rsub__"),
102+
/** foo * bar */
100103
nb_multiply("__mul__, __rmul__"),
104+
/** foo % bar */
105+
nb_remainder("__mod__, __rmod__"),
106+
/** divmod(foo, bar) */
107+
nb_divmod("__divmod__, __rdivmod__"),
108+
/** foo << bar */
109+
nb_lshift("__lshift__, __rlshift__"),
110+
/** foo >> bar */
111+
nb_rshift("__rshift__, __rrshift__"),
112+
/** foo & bar */
113+
nb_and("__and__, __rand__"),
114+
/** foo ^ bar */
115+
nb_xor("__xor__, __rxor__"),
116+
/** foo | bar */
117+
nb_or("__or__, __ror__"),
118+
/** foo // bar */
119+
nb_floor_divide("__floordiv__, __rfloordiv__"),
120+
/** foo / bar */
121+
nb_true_divide("__truediv__, __rtruediv__"),
122+
/** foo @ bar */
123+
nb_matrix_multiply("__matmul__, __rmatmul__"),
101124
/** sequence length/size */
102125
sq_length("__len__"),
103126
/** sequence item: read element at index */

graalpython/com.oracle.graal.python.processor/src/com/oracle/graal/python/processor/SlotsMapping.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -52,7 +52,9 @@ private static String getSuffix(boolean isComplex) {
5252
static String getSlotBaseClass(Slot s) {
5353
return switch (s.value()) {
5454
case nb_bool -> "TpSlotInquiry.TpSlotInquiryBuiltin";
55-
case nb_add, nb_multiply -> "TpSlotBinaryOp.TpSlotBinaryOpBuiltin";
55+
case nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift, nb_and, nb_xor, nb_or,
56+
nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
57+
"TpSlotBinaryOp.TpSlotBinaryOpBuiltin";
5658
case sq_concat -> "TpSlotBinaryFunc.TpSlotSqConcat";
5759
case sq_length, mp_length -> "TpSlotLen.TpSlotLenBuiltin" + getSuffix(s.isComplex());
5860
case sq_item, sq_repeat -> "TpSlotSizeArgFun.TpSlotSizeArgFunBuiltin";
@@ -68,7 +70,9 @@ static String getSlotNodeBaseClass(Slot s) {
6870
return switch (s.value()) {
6971
case tp_descr_get -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrGet.DescrGetBuiltinNode";
7072
case nb_bool -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotInquiry.NbBoolBuiltinNode";
71-
case nb_add, nb_multiply -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode";
73+
case nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift, nb_and, nb_xor, nb_or,
74+
nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
75+
"com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryOp.BinaryOpBuiltinNode";
7276
case sq_concat -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.SqConcatBuiltinNode";
7377
case sq_length, mp_length -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.LenBuiltinNode";
7478
case sq_item -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqItemBuiltinNode";
@@ -85,7 +89,9 @@ static String getUncachedExecuteSignature(SlotKind s) {
8589
case nb_bool -> "boolean executeUncached(Object self)";
8690
case tp_descr_get -> "Object executeUncached(Object self, Object obj, Object type)";
8791
case sq_length, mp_length -> "int executeUncached(Object self)";
88-
case tp_getattro, tp_descr_set, tp_setattro, sq_item, mp_subscript, nb_add, sq_concat, sq_repeat, nb_multiply ->
92+
case tp_getattro, tp_descr_set, tp_setattro, sq_item, mp_subscript, sq_concat, sq_repeat,
93+
nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift,
94+
nb_and, nb_xor, nb_or, nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
8995
throw new AssertionError("Should not reach here: should be always complex");
9096
};
9197
}
@@ -94,17 +100,19 @@ static boolean supportsComplex(SlotKind s) {
94100
return switch (s) {
95101
case nb_bool -> false;
96102
case sq_length, mp_length, tp_getattro, tp_descr_get, tp_descr_set,
97-
tp_setattro, sq_item, mp_subscript, nb_add, sq_concat,
98-
sq_repeat, nb_multiply ->
103+
tp_setattro, sq_item, mp_subscript, sq_concat, sq_repeat,
104+
nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift,
105+
nb_and, nb_xor, nb_or, nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
99106
true;
100107
};
101108
}
102109

103110
static boolean supportsSimple(SlotKind s) {
104111
return switch (s) {
105112
case nb_bool, sq_length, mp_length, tp_descr_get -> true;
106-
case tp_getattro, tp_descr_set, tp_setattro, sq_item, mp_subscript,
107-
nb_add, sq_concat, sq_repeat, nb_multiply ->
113+
case tp_getattro, tp_descr_set, tp_setattro, sq_item, mp_subscript, sq_concat, sq_repeat,
114+
nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift,
115+
nb_and, nb_xor, nb_or, nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
108116
false;
109117
};
110118
}
@@ -114,16 +122,28 @@ static String getUncachedExecuteCall(SlotKind s) {
114122
case nb_bool -> "executeBool(null, self)";
115123
case sq_length, mp_length -> "executeInt(null, self)";
116124
case tp_descr_get -> "execute(null, self, obj, type)";
117-
case tp_getattro, tp_descr_set, tp_setattro, sq_item, mp_subscript,
118-
nb_add, sq_concat, nb_multiply, sq_repeat ->
125+
case tp_getattro, tp_descr_set, tp_setattro, sq_item, mp_subscript, sq_concat, sq_repeat,
126+
nb_add, nb_subtract, nb_multiply, nb_remainder, nb_divmod, nb_lshift, nb_rshift,
127+
nb_and, nb_xor, nb_or, nb_floor_divide, nb_true_divide, nb_matrix_multiply ->
119128
throw new AssertionError("Should not reach here: should be always complex");
120129
};
121130
}
122131

123132
public static String getExtraCtorArgs(TpSlotData slot) {
124133
return switch (slot.slot().value()) {
125134
case nb_add -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___ADD__";
135+
case nb_subtract -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___SUB__";
126136
case nb_multiply -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___MUL__";
137+
case nb_remainder -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___MOD__";
138+
case nb_divmod -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___DIVMOD__";
139+
case nb_lshift -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___LSHIFT__";
140+
case nb_rshift -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___RSHIFT__";
141+
case nb_and -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___AND__";
142+
case nb_xor -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___XOR__";
143+
case nb_or -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___OR__";
144+
case nb_floor_divide -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___FLOORDIV__";
145+
case nb_true_divide -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___TRUEDIV__";
146+
case nb_matrix_multiply -> ", com.oracle.graal.python.nodes.SpecialMethodNames.J___MATMUL__";
127147
default -> "";
128148
};
129149
}

0 commit comments

Comments
 (0)