|
63 | 63 | import com.oracle.graal.python.builtins.objects.cext.PythonClassNativeWrapper;
|
64 | 64 | import com.oracle.graal.python.builtins.objects.cext.PythonObjectNativeWrapper;
|
65 | 65 | import com.oracle.graal.python.builtins.objects.cext.UnicodeObjectNodes.UnicodeAsWideCharNode;
|
| 66 | +import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes; |
66 | 67 | import com.oracle.graal.python.builtins.objects.complex.PComplex;
|
| 68 | +import com.oracle.graal.python.builtins.objects.dict.PDict; |
67 | 69 | import com.oracle.graal.python.builtins.objects.exception.PBaseException;
|
68 | 70 | import com.oracle.graal.python.builtins.objects.floats.PFloat;
|
69 | 71 | import com.oracle.graal.python.builtins.objects.function.Arity;
|
@@ -487,27 +489,50 @@ boolean op5(Object a, Object b, @SuppressWarnings("unused") int op,
|
487 | 489 | }
|
488 | 490 | }
|
489 | 491 |
|
490 |
| - @Builtin(name = "PyType_Ready", fixedNumOfArguments = 5) |
| 492 | + @Builtin(name = "PyType_Ready", fixedNumOfArguments = 4) |
491 | 493 | @GenerateNodeFactory
|
492 | 494 | abstract static class PyType_ReadyNode extends PythonBuiltinNode {
|
493 | 495 | @Child WriteAttributeToObjectNode writeNode = WriteAttributeToObjectNode.create();
|
| 496 | + @Child private HashingStorageNodes.GetItemNode getItemNode; |
| 497 | + |
| 498 | + private HashingStorageNodes.GetItemNode getGetItemNode() { |
| 499 | + if (getItemNode == null) { |
| 500 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 501 | + getItemNode = insert(HashingStorageNodes.GetItemNode.create()); |
| 502 | + } |
| 503 | + return getItemNode; |
| 504 | + } |
494 | 505 |
|
495 | 506 | @Specialization
|
496 |
| - PythonClass run(TruffleObject typestruct, PythonClass metaClass, PTuple baseClasses, String name, String doc) { |
| 507 | + PythonClass run(TruffleObject typestruct, PythonClass metaClass, PTuple baseClasses, PDict nativeMembers) { |
497 | 508 | Object[] array = baseClasses.getArray();
|
498 | 509 | PythonClass[] bases = new PythonClass[array.length];
|
499 | 510 | for (int i = 0; i < array.length; i++) {
|
500 | 511 | bases[i] = (PythonClass) array[i];
|
501 | 512 | }
|
502 | 513 |
|
| 514 | + String name = getStringItem(nativeMembers, "tp_name"); |
| 515 | + String doc = getStringItem(nativeMembers, "tp_doc"); |
503 | 516 | PythonClass cclass = factory().createNativeClassWrapper(typestruct, metaClass, name, bases);
|
504 | 517 | writeNode.execute(cclass, SpecialAttributeNames.__DOC__, doc);
|
| 518 | + writeNode.execute(cclass, SpecialAttributeNames.__BASICSIZE__, getLongItem(nativeMembers, "tp_basicsize")); |
505 | 519 | return cclass;
|
506 | 520 | }
|
507 | 521 |
|
508 |
| - @Specialization |
509 |
| - PythonClass run(TruffleObject typestruct, PythonClass metaClass, PTuple baseClasses, PString name, PString doc) { |
510 |
| - return run(typestruct, metaClass, baseClasses, name.getValue(), doc.getValue()); |
| 522 | + private String getStringItem(PDict nativeMembers, String key) { |
| 523 | + Object item = getGetItemNode().execute(nativeMembers.getDictStorage(), key); |
| 524 | + if (item instanceof PString) { |
| 525 | + return ((PString) item).getValue(); |
| 526 | + } |
| 527 | + return (String) item; |
| 528 | + } |
| 529 | + |
| 530 | + private Object getLongItem(PDict nativeMembers, String key) { |
| 531 | + Object item = getGetItemNode().execute(nativeMembers.getDictStorage(), key); |
| 532 | + if (item instanceof PInt || item instanceof Number) { |
| 533 | + return item; |
| 534 | + } |
| 535 | + return (long) item; |
511 | 536 | }
|
512 | 537 | }
|
513 | 538 |
|
|
0 commit comments