|
49 | 49 | import com.oracle.graal.python.nodes.control.TopLevelExceptionHandler;
|
50 | 50 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
51 | 51 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
52 |
| -import com.oracle.graal.python.nodes.statement.ImportNode; |
53 | 52 | import com.oracle.graal.python.parser.PythonParserImpl;
|
54 | 53 | import com.oracle.graal.python.runtime.PythonContext;
|
55 | 54 | import com.oracle.graal.python.runtime.PythonCore;
|
@@ -216,29 +215,31 @@ protected CallTarget parse(ParsingRequest request) throws Exception {
|
216 | 215 | PythonContext context = this.getContextReference().get();
|
217 | 216 | PythonCore pythonCore = context.getCore();
|
218 | 217 | Source source = request.getSource();
|
| 218 | + CompilerDirectives.transferToInterpreter(); |
219 | 219 | if (pythonCore.isInitialized()) {
|
220 | 220 | context.initializeMainModule(source.getPath());
|
221 | 221 |
|
222 | 222 | // if we are running the interpreter, module 'site' is automatically imported
|
223 | 223 | if (source.isInteractive()) {
|
224 |
| - CompilerAsserts.neverPartOfCompilation(); |
225 |
| - // no frame required |
226 |
| - new ImportNode("site").execute(null); |
| 224 | + Truffle.getRuntime().createCallTarget(new TopLevelExceptionHandler(this, doParse(pythonCore, Source.newBuilder(ID, "import site", "<site import>").build()))).call(); |
227 | 225 | }
|
228 | 226 | }
|
229 |
| - RootNode root; |
| 227 | + RootNode root = doParse(pythonCore, source); |
| 228 | + if (pythonCore.isInitialized()) { |
| 229 | + return Truffle.getRuntime().createCallTarget(new TopLevelExceptionHandler(this, root)); |
| 230 | + } else { |
| 231 | + return Truffle.getRuntime().createCallTarget(root); |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | + private RootNode doParse(PythonCore pythonCore, Source source) { |
230 | 236 | try {
|
231 |
| - root = (RootNode) pythonCore.getParser().parse(source.isInteractive() ? ParserMode.InteractiveStatement : ParserMode.File, pythonCore, source, null); |
| 237 | + return (RootNode) pythonCore.getParser().parse(source.isInteractive() ? ParserMode.InteractiveStatement : ParserMode.File, pythonCore, source, null); |
232 | 238 | } catch (PException e) {
|
233 | 239 | // handle PException during parsing (PIncompleteSourceException will propagate through)
|
234 | 240 | Truffle.getRuntime().createCallTarget(new TopLevelExceptionHandler(this, e)).call();
|
235 | 241 | throw e;
|
236 | 242 | }
|
237 |
| - if (pythonCore.isInitialized()) { |
238 |
| - return Truffle.getRuntime().createCallTarget(new TopLevelExceptionHandler(this, root)); |
239 |
| - } else { |
240 |
| - return Truffle.getRuntime().createCallTarget(root); |
241 |
| - } |
242 | 243 | }
|
243 | 244 |
|
244 | 245 | @Override
|
@@ -370,7 +371,7 @@ protected String toString(PythonContext context, Object value) {
|
370 | 371 | }
|
371 | 372 |
|
372 | 373 | public static TruffleLogger getLogger() {
|
373 |
| - return TruffleLogger.getLogger(ID, PythonLanguage.class); |
| 374 | + return TruffleLogger.getLogger(ID); |
374 | 375 | }
|
375 | 376 |
|
376 | 377 | public static Source newSource(PythonContext ctxt, String src, String name) {
|
|
0 commit comments