111
111
import com .oracle .graal .python .builtins .objects .dict .PDict ;
112
112
import com .oracle .graal .python .builtins .objects .exception .OSErrorEnum ;
113
113
import com .oracle .graal .python .builtins .objects .exception .OSErrorEnum .ErrorAndMessagePair ;
114
+ import com .oracle .graal .python .builtins .objects .function .PArguments ;
114
115
import com .oracle .graal .python .builtins .objects .function .PBuiltinFunction ;
115
116
import com .oracle .graal .python .builtins .objects .function .PFunction ;
116
117
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
143
144
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
144
145
import com .oracle .graal .python .nodes .function .builtins .clinic .ArgumentClinicProvider ;
145
146
import com .oracle .graal .python .nodes .object .GetClassNode ;
147
+ import com .oracle .graal .python .nodes .object .GetOrCreateDictNode ;
146
148
import com .oracle .graal .python .nodes .statement .AbstractImportNode ;
147
149
import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
148
150
import com .oracle .graal .python .nodes .util .CastToTruffleStringNode ;
149
151
import com .oracle .graal .python .nodes .util .ToNativePrimitiveStorageNode ;
152
+ import com .oracle .graal .python .runtime .ExecutionContext ;
150
153
import com .oracle .graal .python .runtime .PosixSupportLibrary ;
151
154
import com .oracle .graal .python .runtime .PythonContext ;
152
155
import com .oracle .graal .python .runtime .PythonImageBuildOptions ;
@@ -341,7 +344,7 @@ private void runFile(PythonContext context, TruffleString inputFilePath) {
341
344
TruffleFile file = context .getPublicTruffleFileRelaxed (inputFilePath );
342
345
builder = Source .newBuilder (PythonLanguage .ID , file );
343
346
}
344
- source = builder .mimeType (PythonLanguage .MIME_TYPE ).build ();
347
+ source = builder .mimeType (PythonLanguage .getCompileMimeType ( 0 , 0 ) ).build ();
345
348
// TODO we should handle non-IO errors better
346
349
} catch (IOException e ) {
347
350
ErrorAndMessagePair error = OSErrorEnum .fromException (e , TruffleString .EqualNode .getUncached ());
@@ -355,8 +358,21 @@ private void runFile(PythonContext context, TruffleString inputFilePath) {
355
358
// The exit value is hardcoded in CPython too
356
359
throw new PythonExitException (this , 2 );
357
360
}
361
+ PythonLanguage language = context .getLanguage ();
358
362
CallTarget callTarget = context .getEnv ().parsePublic (source );
359
- callTarget .call (PythonUtils .EMPTY_OBJECT_ARRAY );
363
+ Object [] arguments = PArguments .create ();
364
+ PythonModule mainModule = context .getMainModule ();
365
+ PDict mainDict = GetOrCreateDictNode .executeUncached (mainModule );
366
+ PArguments .setGlobals (arguments , mainModule );
367
+ PArguments .setSpecialArgument (arguments , mainDict );
368
+ PArguments .setException (arguments , PException .NO_EXCEPTION );
369
+ context .initializeMainModule (inputFilePath );
370
+ Object state = ExecutionContext .IndirectCalleeContext .enterIndirect (language , context , arguments );
371
+ try {
372
+ callTarget .call (arguments );
373
+ } finally {
374
+ ExecutionContext .IndirectCalleeContext .exit (language , context , state );
375
+ }
360
376
}
361
377
362
378
// Equivalent of CPython's pymain_run_module
0 commit comments