Skip to content

Commit 6a17989

Browse files
committed
[GR-57764] New item assignment slots
PullRequest: graalpython/3639
2 parents f4495fe + e52c8cd commit 6a17989

40 files changed

+1857
-864
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ enum SlotKind {
125125
sq_length("__len__"),
126126
/** sequence item: read element at index */
127127
sq_item("__getitem__"),
128+
/** write sequence element at index */
129+
sq_ass_item("__setitem__"),
128130
/** seq + seq, nb_add is tried before */
129131
sq_concat("__add__"),
130132
/** seq * number, nb_multiply is tried before */
@@ -133,6 +135,8 @@ enum SlotKind {
133135
mp_length("__len__"),
134136
/** mapping subscript, e.g. o[key], o[i:j] */
135137
mp_subscript("__getitem__"),
138+
/** o[key] = value */
139+
mp_ass_subscript("__setitem__"),
136140
/** type descriptor get */
137141
tp_descr_get("__get__"),
138142
/** type descriptor set/delete */

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ static String getSlotBaseClass(Slot s) {
5858
case sq_concat -> "TpSlotBinaryFunc.TpSlotSqConcat";
5959
case sq_length, mp_length -> "TpSlotLen.TpSlotLenBuiltin" + getSuffix(s.isComplex());
6060
case sq_item, sq_repeat -> "TpSlotSizeArgFun.TpSlotSizeArgFunBuiltin";
61+
case sq_ass_item -> "TpSlotSqAssItem.TpSlotSqAssItemBuiltin";
6162
case mp_subscript -> "TpSlotBinaryFunc.TpSlotMpSubscript";
63+
case mp_ass_subscript -> "TpSlotMpAssSubscript.TpSlotMpAssSubscriptBuiltin";
6264
case tp_getattro -> "TpSlotGetAttr.TpSlotGetAttrBuiltin";
6365
case tp_descr_get -> "TpSlotDescrGet.TpSlotDescrGetBuiltin" + getSuffix(s.isComplex());
6466
case tp_descr_set -> "TpSlotDescrSet.TpSlotDescrSetBuiltin";
@@ -76,8 +78,10 @@ static String getSlotNodeBaseClass(Slot s) {
7678
case sq_concat -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.SqConcatBuiltinNode";
7779
case sq_length, mp_length -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotLen.LenBuiltinNode";
7880
case sq_item -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqItemBuiltinNode";
81+
case sq_ass_item -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSqAssItem.SqAssItemBuiltinNode";
7982
case sq_repeat -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSizeArgFun.SqRepeatBuiltinNode";
8083
case mp_subscript -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotBinaryFunc.MpSubscriptBuiltinNode";
84+
case mp_ass_subscript -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotMpAssSubscript.MpAssSubscriptBuiltinNode";
8185
case tp_getattro -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotGetAttr.GetAttrBuiltinNode";
8286
case tp_descr_set -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotDescrSet.DescrSetBuiltinNode";
8387
case tp_setattro -> "com.oracle.graal.python.builtins.objects.type.slots.TpSlotSetAttr.SetAttrBuiltinNode";
@@ -89,31 +93,21 @@ static String getUncachedExecuteSignature(SlotKind s) {
8993
case nb_bool -> "boolean executeUncached(Object self)";
9094
case tp_descr_get -> "Object executeUncached(Object self, Object obj, Object type)";
9195
case sq_length, mp_length -> "int executeUncached(Object self)";
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 ->
95-
throw new AssertionError("Should not reach here: should be always complex");
96+
default -> throw new AssertionError("Should not reach here: should be always complex");
9697
};
9798
}
9899

99100
static boolean supportsComplex(SlotKind s) {
100101
return switch (s) {
101102
case nb_bool -> false;
102-
case sq_length, mp_length, tp_getattro, tp_descr_get, tp_descr_set,
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 ->
106-
true;
103+
default -> true;
107104
};
108105
}
109106

110107
static boolean supportsSimple(SlotKind s) {
111108
return switch (s) {
112109
case nb_bool, sq_length, mp_length, tp_descr_get -> true;
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 ->
116-
false;
110+
default -> false;
117111
};
118112
}
119113

@@ -122,10 +116,7 @@ static String getUncachedExecuteCall(SlotKind s) {
122116
case nb_bool -> "executeBool(null, self)";
123117
case sq_length, mp_length -> "executeInt(null, self)";
124118
case tp_descr_get -> "execute(null, self, obj, type)";
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 ->
128-
throw new AssertionError("Should not reach here: should be always complex");
119+
default -> throw new AssertionError("Should not reach here: should be always complex");
129120
};
130121
}
131122

graalpython/com.oracle.graal.python.test/src/tests/cpyext/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -650,19 +650,22 @@ def CPyExtTypeDecl(name, code='', **kwargs):
650650
}};
651651
652652
static PySequenceMethods {name}_sequence_methods = {{
653-
{sq_length}, /* sq_length */
654-
{sq_concat}, /* sq_concat */
655-
0, /* sq_repeat */
656-
{sq_item}, /* sq_item */
657-
0, /* sq_slice */
658-
{sq_ass_item}, /* sq_ass_item */
659-
0, /* sq_ass_slice */
660-
{sq_contains}, /* sq_contains */
653+
{sq_length}, /* sq_length */
654+
{sq_concat}, /* sq_concat */
655+
{sq_repeat}, /* sq_repeat */
656+
{sq_item}, /* sq_item */
657+
0, /* was_sq_slice */
658+
{sq_ass_item}, /* sq_ass_item */
659+
0, /* was_sq_ass_slice */
660+
{sq_contains}, /* sq_contains */
661+
{sq_inplace_concat}, /* sq_inplace_concat */
662+
{sq_inplace_repeat}, /* sq_inplace_repeat */
661663
}};
662664
663665
static PyMappingMethods {name}_mapping_methods = {{
664666
{mp_length}, /* mp_length */
665667
{mp_subscript}, /* mp_subscript */
668+
{mp_ass_subscript}, /* mp_subscript */
666669
}};
667670
668671
static struct PyMethodDef {name}_methods[] = {{

0 commit comments

Comments
 (0)