26
26
package com .oracle .graal .python .builtins ;
27
27
28
28
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .IndentationError ;
29
+ import static com .oracle .graal .python .builtins .PythonBuiltinClassType .SyntaxError ;
29
30
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .TabError ;
30
31
import static com .oracle .graal .python .builtins .objects .exception .SyntaxErrorBuiltins .SYNTAX_ERROR_ATTR_FACTORY ;
31
32
import static com .oracle .graal .python .nodes .BuiltinNames .MODULES ;
32
33
import static com .oracle .graal .python .nodes .BuiltinNames .PRINT ;
33
34
import static com .oracle .graal .python .nodes .SpecialAttributeNames .__PACKAGE__ ;
34
- import static com .oracle .graal .python .runtime . exception . PythonErrorType . SyntaxError ;
35
+ import static com .oracle .graal .python .nodes . SpecialMethodNames . __REPR__ ;
35
36
36
37
import java .io .IOException ;
37
38
import java .math .BigInteger ;
@@ -357,9 +358,7 @@ private static String[] initializeCoreFiles() {
357
358
// Order matters!
358
359
List <String > coreFiles = new ArrayList <>(Arrays .asList (
359
360
"type" ,
360
- "_imp" ,
361
361
"function" ,
362
- "_frozen_importlib" ,
363
362
"__graalpython__" ,
364
363
"_weakref" ,
365
364
"faulthandler" ,
@@ -386,8 +385,6 @@ private static String[] initializeCoreFiles() {
386
385
}
387
386
}
388
387
}
389
- // must be last
390
- coreFiles .add ("final_patches" );
391
388
return coreFiles .toArray (new String [coreFiles .size ()]);
392
389
}
393
390
@@ -829,7 +826,7 @@ private void initializeJavaCore() {
829
826
}
830
827
831
828
private void initializeImportlib () {
832
- PythonModule bootstrap = (PythonModule ) ImpModuleBuiltins .importFrozenModuleObject (this , "_frozen_importlib" );
829
+ PythonModule bootstrap = (PythonModule ) ImpModuleBuiltins .importFrozenModuleObject (this , "_frozen_importlib" , false );
833
830
834
831
PyObjectCallMethodObjArgs callNode = PyObjectCallMethodObjArgs .getUncached ();
835
832
WriteAttributeToDynamicObjectNode writeNode = WriteAttributeToDynamicObjectNode .getUncached ();
@@ -843,8 +840,8 @@ private void initializeImportlib() {
843
840
bootstrap = createModule ("importlib._bootstrap" );
844
841
writeNode .execute (bootstrap , __PACKAGE__ , "importlib" );
845
842
addBuiltinModule ("_frozen_importlib" , bootstrap );
846
- loadFile ("importlib/_bootstrap_external.py " , getContext ().getStdlibHome ());
847
- loadFile ("importlib/_bootstrap.py " , getContext ().getStdlibHome ());
843
+ loadFile ("importlib/_bootstrap_external" , getContext ().getStdlibHome (), bootstrapExternal );
844
+ loadFile ("importlib/_bootstrap" , getContext ().getStdlibHome (), bootstrap );
848
845
}
849
846
850
847
callNode .execute (null , bootstrap , "_install" , getSysModule (), lookupBuiltinModule ("_imp" ));
@@ -853,8 +850,11 @@ private void initializeImportlib() {
853
850
importFunc = (PFunction ) readNode .execute (bootstrap , "__import__" );
854
851
importlib = bootstrap ;
855
852
853
+ writeNode .execute (lookupType (PythonBuiltinClassType .PythonModule ), __REPR__ , readNode .execute (bootstrap , "_module_repr" ));
854
+
856
855
// __package__ needs to be set and doesn't get set by _bootstrap setup
857
856
writeNode .execute (bootstrap , __PACKAGE__ , "importlib" );
857
+
858
858
PythonModule bootstrapExternal = (PythonModule ) getSysModules ().getItem ("_frozen_importlib_external" );
859
859
writeNode .execute (bootstrapExternal , __PACKAGE__ , "importlib" );
860
860
}
@@ -1101,16 +1101,20 @@ private Source getInternalSource(String basename, String prefix) {
1101
1101
}
1102
1102
1103
1103
private void loadFile (String s , String prefix ) {
1104
- Supplier <CallTarget > getCode = () -> {
1105
- Source source = getInternalSource (s , prefix );
1106
- return PythonUtils .getOrCreateCallTarget ((RootNode ) getParser ().parse (ParserMode .File , 0 , this , source , null , null ));
1107
- };
1108
- RootCallTarget callTarget = (RootCallTarget ) getLanguage ().cacheCode (s , getCode );
1109
1104
PythonModule mod = lookupBuiltinModule (s );
1110
1105
if (mod == null ) {
1111
1106
// use an anonymous module for the side-effects
1112
1107
mod = factory ().createPythonModule ("__anonymous__" );
1113
1108
}
1109
+ loadFile (s , prefix , mod );
1110
+ }
1111
+
1112
+ private void loadFile (String s , String prefix , PythonModule mod ) {
1113
+ Supplier <CallTarget > getCode = () -> {
1114
+ Source source = getInternalSource (s , prefix );
1115
+ return PythonUtils .getOrCreateCallTarget ((RootNode ) getParser ().parse (ParserMode .File , 0 , this , source , null , null ));
1116
+ };
1117
+ RootCallTarget callTarget = (RootCallTarget ) getLanguage ().cacheCode (s , getCode );
1114
1118
GenericInvokeNode .getUncached ().execute (callTarget , PArguments .withGlobals (mod ));
1115
1119
}
1116
1120
0 commit comments