|
70 | 70 | import com.oracle.graal.python.builtins.objects.cext.PythonNativeObject;
|
71 | 71 | import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage;
|
72 | 72 | import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
|
| 73 | +import com.oracle.graal.python.builtins.objects.common.SequenceNodes.GetObjectArrayNode; |
73 | 74 | import com.oracle.graal.python.builtins.objects.dict.PDict;
|
74 | 75 | import com.oracle.graal.python.builtins.objects.function.PKeyword;
|
75 | 76 | import com.oracle.graal.python.builtins.objects.list.PList;
|
76 | 77 | import com.oracle.graal.python.builtins.objects.mappingproxy.PMappingproxy;
|
77 | 78 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
78 | 79 | import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
|
| 80 | +import com.oracle.graal.python.builtins.objects.tuple.PTuple; |
79 | 81 | import com.oracle.graal.python.builtins.objects.type.TypeBuiltinsFactory.CallNodeFactory;
|
80 | 82 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroNode;
|
| 83 | +import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode; |
81 | 84 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetSubclassesNode;
|
82 | 85 | import com.oracle.graal.python.builtins.objects.type.TypeNodesFactory.IsSameTypeNodeGen;
|
83 | 86 | import com.oracle.graal.python.nodes.BuiltinNames;
|
|
105 | 108 | import com.oracle.graal.python.nodes.truffle.PythonTypes;
|
106 | 109 | import com.oracle.graal.python.runtime.exception.PException;
|
107 | 110 | import com.oracle.graal.python.runtime.exception.PythonErrorType;
|
| 111 | +import static com.oracle.graal.python.runtime.exception.PythonErrorType.NotImplementedError; |
108 | 112 | import com.oracle.truffle.api.CompilerAsserts;
|
109 | 113 | import com.oracle.truffle.api.CompilerDirectives;
|
110 | 114 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
@@ -518,14 +522,48 @@ Object doIt(Object args, Object kwargs) {
|
518 | 522 | }
|
519 | 523 | }
|
520 | 524 |
|
521 |
| - @Builtin(name = __BASES__, minNumOfPositionalArgs = 1, isGetter = true) |
| 525 | + @Builtin(name = __BASES__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true) |
522 | 526 | @GenerateNodeFactory
|
523 |
| - abstract static class BasesNode extends PythonBuiltinNode { |
| 527 | + @ImportStatic(PGuards.class) |
| 528 | + abstract static class BasesNode extends PythonBinaryBuiltinNode { |
| 529 | + |
524 | 530 | @Specialization
|
525 |
| - Object bases(Object self, |
| 531 | + Object getBases(Object self, @SuppressWarnings("unused") PNone value, |
526 | 532 | @Cached("create()") TypeNodes.GetBaseClassesNode getBaseClassesNode) {
|
527 | 533 | return factory().createTuple(getBaseClassesNode.execute(self));
|
528 | 534 | }
|
| 535 | + |
| 536 | + @Specialization |
| 537 | + Object setBases(PythonClass cls, PTuple value, |
| 538 | + @Cached GetNameNode getName, |
| 539 | + @Cached GetObjectArrayNode getArray) { |
| 540 | + |
| 541 | + Object[] a = getArray.execute(value); |
| 542 | + PythonAbstractClass[] baseClasses = new PythonAbstractClass[a.length]; |
| 543 | + for (int i = 0; i < a.length; i++) { |
| 544 | + if (a[i] instanceof PythonAbstractClass) { |
| 545 | + baseClasses[i] = (PythonAbstractClass) a[i]; |
| 546 | + } else { |
| 547 | + throw raise(TypeError, ErrorMessages.MUST_BE_TUPLE_OF_CLASSES_NOT_P, getName.execute(cls), "__bases__", a[i]); |
| 548 | + } |
| 549 | + } |
| 550 | + |
| 551 | + throw raise(NotImplementedError); |
| 552 | + // return PNone.NONE; |
| 553 | + } |
| 554 | + |
| 555 | + @Specialization(guards = "!isPTuple(value)") |
| 556 | + Object setObject(@SuppressWarnings("unused") PythonClass cls, @SuppressWarnings("unused") Object value, |
| 557 | + @Cached GetNameNode getName) { |
| 558 | + throw raise(TypeError, ErrorMessages.CAN_ONLY_ASSIGN_S_TO_S_S_NOT_P, "tuple", getName.execute(cls), "__bases__", value); |
| 559 | + } |
| 560 | + |
| 561 | + @Specialization |
| 562 | + Object setBuiltin(@SuppressWarnings("unused") PythonBuiltinClass cls, @SuppressWarnings("unused") Object value, |
| 563 | + @Cached GetNameNode getName) { |
| 564 | + throw raise(TypeError, ErrorMessages.CANT_SET_ATTRIBUTES_OF_TYPE_S, getName.execute(cls)); |
| 565 | + } |
| 566 | + |
529 | 567 | }
|
530 | 568 |
|
531 | 569 | @Builtin(name = __BASE__, minNumOfPositionalArgs = 1, isGetter = true)
|
|
0 commit comments