|
44 | 44 | import static com.oracle.graal.python.builtins.modules.BuiltinFunctions.CompileNode.PyCF_ONLY_AST;
|
45 | 45 | import static com.oracle.graal.python.builtins.modules.BuiltinFunctions.CompileNode.PyCF_TYPE_COMMENTS;
|
46 | 46 | import static com.oracle.graal.python.util.PythonUtils.EMPTY_OBJECT_ARRAY;
|
| 47 | +import static com.oracle.graal.python.util.PythonUtils.toTruffleStringUncached; |
47 | 48 | import static com.oracle.graal.python.util.PythonUtils.tsLiteral;
|
48 | 49 |
|
49 | 50 | import java.util.ArrayList;
|
50 | 51 | import java.util.List;
|
51 | 52 |
|
| 53 | +import com.oracle.graal.python.PythonLanguage; |
52 | 54 | import com.oracle.graal.python.builtins.CoreFunctions;
|
53 | 55 | import com.oracle.graal.python.builtins.Python3Core;
|
54 | 56 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
55 | 57 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
56 | 58 | import com.oracle.graal.python.builtins.objects.module.PythonModule;
|
57 | 59 | import com.oracle.graal.python.builtins.objects.tuple.PTuple;
|
| 60 | +import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass; |
58 | 61 | import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
|
59 | 62 | import com.oracle.graal.python.builtins.objects.type.PythonClass;
|
60 | 63 | import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
|
61 | 64 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
62 | 65 | import com.oracle.graal.python.pegparser.sst.ModTy;
|
63 | 66 | import com.oracle.graal.python.runtime.PythonContext;
|
| 67 | +import com.oracle.graal.python.runtime.object.PythonObjectFactory; |
64 | 68 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
65 | 69 | import com.oracle.truffle.api.dsl.NodeFactory;
|
66 | 70 | import com.oracle.truffle.api.object.HiddenKey;
|
@@ -98,6 +102,32 @@ public void initialize(Python3Core core) {
|
98 | 102 | AstTypeFactory astTypeFactory = new AstTypeFactory(core.getLanguage(), core.factory(), astModule);
|
99 | 103 | AstState state = new AstState(astTypeFactory, core.lookupType(PythonBuiltinClassType.AST));
|
100 | 104 | astModule.setAttribute(AST_STATE_KEY, state);
|
| 105 | + |
| 106 | + createBackwardCompatibilityClasses(core, astModule, state); |
| 107 | + } |
| 108 | + |
| 109 | + private void createBackwardCompatibilityClasses(Python3Core core, PythonModule astModule, AstState state) { |
| 110 | + // ast.py from cpython 3.10.5 defines classes for backwards compatibility |
| 111 | + // As long as we are still using ast.py from 3.8.6, we need to provide these classes somehow. |
| 112 | + PythonLanguage language = core.getLanguage(); |
| 113 | + PythonObjectFactory factory = core.factory(); |
| 114 | + |
| 115 | + makeType(language, factory, astModule, "Suite", state.clsModTy); |
| 116 | + |
| 117 | + PythonClass slice_type = makeType(language, factory, astModule, "slice", state.clsAst); |
| 118 | + makeType(language, factory, astModule, "ExtSlice", slice_type); |
| 119 | + makeType(language, factory, astModule, "Index", slice_type); |
| 120 | + |
| 121 | + makeType(language, factory, astModule, "AugLoad", state.clsExprContextTy); |
| 122 | + makeType(language, factory, astModule, "AugStore", state.clsExprContextTy); |
| 123 | + makeType(language, factory, astModule, "Param", state.clsExprContextTy); |
| 124 | + } |
| 125 | + |
| 126 | + private static PythonClass makeType(PythonLanguage language, PythonObjectFactory factory, PythonModule astModule, String name, PythonAbstractClass base) { |
| 127 | + TruffleString tsName = toTruffleStringUncached(name); |
| 128 | + PythonClass newType = factory.createPythonClassAndFixupSlots(language, PythonBuiltinClassType.PythonClass, tsName, new PythonAbstractClass[]{base}); |
| 129 | + astModule.setAttribute(tsName, newType); |
| 130 | + return newType; |
101 | 131 | }
|
102 | 132 |
|
103 | 133 | private static AstState getAstState(PythonContext context) {
|
|
0 commit comments