|
42 | 42 |
|
43 | 43 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.IndexError;
|
44 | 44 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
|
45 |
| -import static com.oracle.graal.python.nodes.SpecialAttributeNames.__BASICSIZE__; |
46 |
| -import static com.oracle.graal.python.nodes.SpecialAttributeNames.__DICTOFFSET__; |
47 | 45 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETITEM__;
|
48 | 46 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
|
49 | 47 |
|
|
97 | 95 | import com.oracle.graal.python.builtins.objects.cext.UnicodeObjectNodes.UnicodeAsWideCharNode;
|
98 | 96 | import com.oracle.graal.python.builtins.objects.code.PCode;
|
99 | 97 | import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes;
|
100 |
| -import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes; |
101 | 98 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
|
102 | 99 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.CastToByteNode;
|
103 | 100 | import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.NormalizeIndexNode;
|
|
127 | 124 | import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
|
128 | 125 | import com.oracle.graal.python.builtins.objects.type.PythonClass;
|
129 | 126 | import com.oracle.graal.python.builtins.objects.type.TypeNodes;
|
130 |
| -import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroNode; |
131 | 127 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetTypeFlagsNode;
|
132 | 128 | import com.oracle.graal.python.nodes.PGuards;
|
133 | 129 | import com.oracle.graal.python.nodes.PNodeWithContext;
|
@@ -551,153 +547,6 @@ Object setattr(PythonNativeClass object, String key, Object value,
|
551 | 547 | }
|
552 | 548 | }
|
553 | 549 |
|
554 |
| - @Builtin(name = "PyType_Ready", fixedNumOfPositionalArgs = 4) |
555 |
| - @GenerateNodeFactory |
556 |
| - abstract static class PyType_ReadyNode extends PythonBuiltinNode { |
557 |
| - @Child private WriteAttributeToObjectNode writeAttrNode = WriteAttributeToObjectNode.create(); |
558 |
| - @Child private HashingStorageNodes.GetItemNode getItemNode; |
559 |
| - @Child private CastToIndexNode castToIntNode; |
560 |
| - @Child private ReadAttributeFromObjectNode readAttrNode; |
561 |
| - @Child private SequenceStorageNodes.LenNode slotLenNode; |
562 |
| - @Child private SequenceStorageNodes.GetItemNode getSlotItemNode; |
563 |
| - @Child private SequenceStorageNodes.AppendNode setSlotItemNode; |
564 |
| - @Child private HashingStorageNodes.ContainsKeyNode containsKeyNode; |
565 |
| - @Child private CExtNodes.PCallCapiFunction callAddNativeSlotsNode; |
566 |
| - @Child private CExtNodes.ToSulongNode toSulongNode; |
567 |
| - @Child private GetMroNode getMroNode; |
568 |
| - |
569 |
| - private HashingStorageNodes.GetItemNode getGetItemNode() { |
570 |
| - if (getItemNode == null) { |
571 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
572 |
| - getItemNode = insert(HashingStorageNodes.GetItemNode.create()); |
573 |
| - } |
574 |
| - return getItemNode; |
575 |
| - } |
576 |
| - |
577 |
| - @Specialization |
578 |
| - Object run(Object typestruct, PythonObjectNativeWrapper metaClass, PythonObjectNativeWrapper baseClasses, PythonObjectNativeWrapper nativeMembers, |
579 |
| - @Cached("create()") CExtNodes.ToJavaNode toJavaNode) { |
580 |
| - // TODO(fa) use recursive node |
581 |
| - return run(typestruct, (PythonClass) toJavaNode.execute(metaClass), (PTuple) toJavaNode.execute(baseClasses), (PDict) toJavaNode.execute(nativeMembers)); |
582 |
| - } |
583 |
| - |
584 |
| - @Specialization |
585 |
| - Object run(Object typestruct, PythonClass metaClass, PTuple baseClasses, PDict nativeMembers) { |
586 |
| -// Object[] array = baseClasses.getArray(); |
587 |
| -// PythonClass[] bases = new PythonClass[array.length]; |
588 |
| -// for (int i = 0; i < array.length; i++) { |
589 |
| -// bases[i] = (PythonClass) array[i]; |
590 |
| -// } |
591 |
| -// |
592 |
| -// if (castToIntNode == null) { |
593 |
| -// CompilerDirectives.transferToInterpreterAndInvalidate(); |
594 |
| -// castToIntNode = insert(CastToIndexNode.create()); |
595 |
| -// } |
596 |
| -// |
597 |
| -// // 'tp_name' contains the fully-qualified name, i.e., 'module.A.B...' |
598 |
| -// String fqname = getStringItem(nativeMembers, TP_NAME); |
599 |
| -// String doc = getStringItem(nativeMembers, TP_DOC); |
600 |
| -// // the qualified name (i.e. without module name) like 'A.B...' |
601 |
| -// String qualName = getQualName(fqname); |
602 |
| -// PythonNativeClass cclass = factory().createNativeClassWrapper(typestruct, metaClass, qualName, |
603 |
| -// bases); |
604 |
| -// writeAttrNode.execute(cclass, SpecialAttributeNames.__DOC__, doc); |
605 |
| -// |
606 |
| -// long basicsize = castToIntNode.execute(getLongItem(nativeMembers, TP_BASICSIZE)); |
607 |
| -// long itemsize = castToIntNode.execute(getLongItem(nativeMembers, TP_ITEMSIZE)); |
608 |
| -// writeAttrNode.execute(cclass, __BASICSIZE__, basicsize); |
609 |
| -// writeAttrNode.execute(cclass, __ITEMSIZE__, itemsize); |
610 |
| -// computeAndSetDictoffset(getLongItem(nativeMembers, TP_DICTOFFSET), cclass, basicsize, itemsize); |
611 |
| -// |
612 |
| -// String moduleName = getModuleName(fqname); |
613 |
| -// if (moduleName != null) { |
614 |
| -// writeAttrNode.execute(cclass, SpecialAttributeNames.__MODULE__, moduleName); |
615 |
| -// } |
616 |
| -// return new PythonClassInitNativeWrapper(cclass); |
617 |
| - return null; |
618 |
| - } |
619 |
| - |
620 |
| - // may also update '__basicsize__' if necessary |
621 |
| - private void computeAndSetDictoffset(Object tpDictoffset, PythonNativeClass cclass, long basicsize, long itemsize) { |
622 |
| - int initialDictoffset = castToIntNode.execute(tpDictoffset); |
623 |
| - if (initialDictoffset == 0) { |
624 |
| - for (Object cls : getMro(cclass)) { |
625 |
| - if (cls != cclass) { |
626 |
| - if (PGuards.isNativeClass(cls)) { |
627 |
| - int baseDictoffset = castToIntNode.execute(ensureReadAttrNode().execute(cls, __DICTOFFSET__)); |
628 |
| - if (baseDictoffset != 0) { |
629 |
| - long dictoffset; |
630 |
| - // add_dict |
631 |
| - if (itemsize != 0) { |
632 |
| - dictoffset = -Long.BYTES; |
633 |
| - } else { |
634 |
| - dictoffset = basicsize; |
635 |
| - } |
636 |
| - writeAttrNode.execute(cclass, __DICTOFFSET__, dictoffset); |
637 |
| - writeAttrNode.execute(cclass, __BASICSIZE__, basicsize + Long.BYTES); |
638 |
| - return; |
639 |
| - } |
640 |
| - } else if (!(cls instanceof PythonBuiltinClass)) { |
641 |
| - writeAttrNode.execute(cclass, __DICTOFFSET__, itemsize == 0 ? basicsize : -Long.BYTES); |
642 |
| - writeAttrNode.execute(cclass, __BASICSIZE__, basicsize + Long.BYTES); |
643 |
| - return; |
644 |
| - } |
645 |
| - } |
646 |
| - } |
647 |
| - } |
648 |
| - writeAttrNode.execute(cclass, __DICTOFFSET__, 0); |
649 |
| - return; |
650 |
| - } |
651 |
| - |
652 |
| - private ReadAttributeFromObjectNode ensureReadAttrNode() { |
653 |
| - if (readAttrNode == null) { |
654 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
655 |
| - readAttrNode = insert(ReadAttributeFromObjectNode.create()); |
656 |
| - } |
657 |
| - return readAttrNode; |
658 |
| - } |
659 |
| - |
660 |
| - private static String getQualName(String fqname) { |
661 |
| - int firstDot = fqname.indexOf('.'); |
662 |
| - if (firstDot != -1) { |
663 |
| - return fqname.substring(firstDot + 1); |
664 |
| - } |
665 |
| - return fqname; |
666 |
| - } |
667 |
| - |
668 |
| - private static String getModuleName(String fqname) { |
669 |
| - int firstDotIdx = fqname.indexOf('.'); |
670 |
| - if (firstDotIdx != -1) { |
671 |
| - return fqname.substring(0, firstDotIdx); |
672 |
| - } |
673 |
| - return null; |
674 |
| - } |
675 |
| - |
676 |
| - private String getStringItem(PDict nativeMembers, String key) { |
677 |
| - Object item = getGetItemNode().execute(nativeMembers.getDictStorage(), key); |
678 |
| - if (item instanceof PString) { |
679 |
| - return ((PString) item).getValue(); |
680 |
| - } |
681 |
| - return (String) item; |
682 |
| - } |
683 |
| - |
684 |
| - private Object getLongItem(PDict nativeMembers, String key) { |
685 |
| - Object item = getGetItemNode().execute(nativeMembers.getDictStorage(), key); |
686 |
| - if (item instanceof PInt || item instanceof Number) { |
687 |
| - return item; |
688 |
| - } |
689 |
| - return (long) item; |
690 |
| - } |
691 |
| - |
692 |
| - private AbstractPythonClass[] getMro(AbstractPythonClass clazz) { |
693 |
| - if (getMroNode == null) { |
694 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
695 |
| - getMroNode = insert(GetMroNode.create()); |
696 |
| - } |
697 |
| - return getMroNode.execute(clazz); |
698 |
| - } |
699 |
| - } |
700 |
| - |
701 | 550 | @Builtin(name = "PyTruffle_Type_Slots", fixedNumOfPositionalArgs = 2, declaresExplicitSelf = true)
|
702 | 551 | @GenerateNodeFactory
|
703 | 552 | @ImportStatic(SpecialAttributeNames.class)
|
|
0 commit comments