|
30 | 30 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__CLASS__;
|
31 | 31 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__DICT__;
|
32 | 32 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__MRO__;
|
| 33 | +import static com.oracle.graal.python.nodes.SpecialAttributeNames.__NAME__; |
33 | 34 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__CALL__;
|
34 | 35 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__DELETE__;
|
35 | 36 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTRIBUTE__;
|
|
64 | 65 | import com.oracle.graal.python.nodes.argument.positional.PositionalArgumentsNode;
|
65 | 66 | import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
|
66 | 67 | import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
|
| 68 | +import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode; |
| 69 | +import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode; |
67 | 70 | import com.oracle.graal.python.nodes.call.special.CallTernaryMethodNode;
|
68 | 71 | import com.oracle.graal.python.nodes.call.special.CallVarargsMethodNode;
|
69 | 72 | import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
|
|
76 | 79 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
77 | 80 | import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
|
78 | 81 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
| 82 | +import com.oracle.graal.python.runtime.exception.PythonErrorType; |
79 | 83 | import com.oracle.truffle.api.CompilerAsserts;
|
80 | 84 | import com.oracle.truffle.api.CompilerDirectives;
|
81 | 85 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
@@ -457,4 +461,30 @@ PList getSubclasses(PythonClass cls) {
|
457 | 461 | return factory().createList(cls.getSubClasses().toArray());
|
458 | 462 | }
|
459 | 463 | }
|
| 464 | + |
| 465 | + @Builtin(name = __NAME__, minNumOfArguments = 1, maxNumOfArguments = 2, isGetter = true, isSetter = true) |
| 466 | + @GenerateNodeFactory |
| 467 | + static abstract class NameNode extends PythonBinaryBuiltinNode { |
| 468 | + @Specialization(guards = "isNoValue(value)") |
| 469 | + String getName(PythonBuiltinClass cls, @SuppressWarnings("unused") PNone value) { |
| 470 | + return cls.getName(); |
| 471 | + } |
| 472 | + |
| 473 | + @Specialization(guards = {"isNoValue(value)", "!isPythonBuiltinClass(cls)"}) |
| 474 | + Object getName(PythonClass cls, @SuppressWarnings("unused") PNone value, |
| 475 | + @Cached("create()") ReadAttributeFromObjectNode getName) { |
| 476 | + return getName.execute(cls, __NAME__); |
| 477 | + } |
| 478 | + |
| 479 | + @Specialization(guards = "!isNoValue(value)") |
| 480 | + Object setName(@SuppressWarnings("unused") PythonBuiltinClass cls, @SuppressWarnings("unused") Object value) { |
| 481 | + throw raise(PythonErrorType.RuntimeError, "can't set attributes of built-in/extension 'type'"); |
| 482 | + } |
| 483 | + |
| 484 | + @Specialization(guards = {"!isNoValue(value)", "!isPythonBuiltinClass(cls)"}) |
| 485 | + Object setName(PythonClass cls, Object value, |
| 486 | + @Cached("create()") WriteAttributeToObjectNode setName) { |
| 487 | + return setName.execute(cls, __NAME__, value); |
| 488 | + } |
| 489 | + } |
460 | 490 | }
|
0 commit comments