@@ -89,7 +89,6 @@ public final class PythonLanguage extends TruffleLanguage<PythonContext> {
89
89
public static final String EXTENSION = ".py" ;
90
90
91
91
@ CompilationFinal private boolean nativeBuildTime = TruffleOptions .AOT ;
92
- @ CompilationFinal private PythonCore sharedCore ;
93
92
private final NodeFactory nodeFactory ;
94
93
95
94
public PythonLanguage () {
@@ -109,47 +108,17 @@ protected void finalizeContext(PythonContext context) {
109
108
@ Override
110
109
protected boolean patchContext (PythonContext context , Env newEnv ) {
111
110
nativeBuildTime = false ; // now we're running
112
- ensureSysExecutable (context );
113
111
ensureHomeInOptions (newEnv );
114
- if (!optionsAllowPreInitializedContext (context , newEnv )) {
115
- // Incompatible options - cannot use pre-initialized context
116
- return false ;
117
- }
118
- context .setEnv (newEnv );
119
- context .setOut (newEnv .out ());
120
- context .setErr (newEnv .err ());
121
- context .initialize ();
122
- context .getCore ().postInitialize ();
112
+ PythonCore .writeInfo (newEnv , "Using preinitialized context." );
113
+ context .patch (newEnv );
123
114
return true ;
124
115
}
125
116
126
- private static void ensureSysExecutable (PythonContext context ) {
127
- PythonModule sys = context .getCore ().lookupBuiltinModule ("sys" );
128
- sys .setAttribute ("executable" , Compiler .command (new Object []{"com.oracle.svm.core.posix.GetExecutableName" }));
129
- }
130
-
131
- private static boolean optionsAllowPreInitializedContext (PythonContext context , Env newEnv ) {
132
- // Verify that the option for using a shared core is the same as
133
- // at image building time
134
- final boolean useSharedCore = newEnv .getOptions ().get (PythonOptions .SharedCore );
135
- boolean canUsePreinitializedContext = context .getCore ().hasSingletonContext () == !useSharedCore ;
136
- if (canUsePreinitializedContext ) {
137
- PythonCore .writeInfo (newEnv , "Using preinitialized context." );
138
- } else {
139
- PythonCore .writeInfo (newEnv , "Not using preinitialized context." );
140
- }
141
- return canUsePreinitializedContext ;
142
- }
143
-
144
117
@ Override
145
118
protected PythonContext createContext (Env env ) {
146
119
ensureHomeInOptions (env );
147
- if (env .getOptions ().get (PythonOptions .SharedCore ) && sharedCore != null ) {
148
- return new PythonContext (this , env , sharedCore );
149
- } else {
150
- Python3Core newCore = new Python3Core (this , new PythonParserImpl ());
151
- return new PythonContext (this , env , newCore );
152
- }
120
+ Python3Core newCore = new Python3Core (new PythonParserImpl ());
121
+ return new PythonContext (this , env , newCore );
153
122
}
154
123
155
124
private void ensureHomeInOptions (Env env ) {
@@ -230,31 +199,13 @@ protected OptionDescriptors getOptionDescriptors() {
230
199
231
200
@ Override
232
201
protected void initializeContext (PythonContext context ) throws Exception {
233
- Python3Core core = (Python3Core ) getCore ();
234
- boolean fullInit = !PythonOptions .getOption (context , PythonOptions .LazyInit );
235
- if (context .getOptions ().get (PythonOptions .SharedCore )) {
236
- if (sharedCore == null ) {
237
- sharedCore = context .getCore ();
238
- core .bootstrap ();
239
- } else {
240
- fullInit = false ;
241
- }
242
- } else {
243
- core .bootstrap ();
244
- }
245
202
context .initialize ();
246
- if (fullInit ) {
247
- core .initialize ();
248
- }
249
203
}
250
204
251
205
@ Override
252
206
protected CallTarget parse (ParsingRequest request ) throws Exception {
253
207
PythonContext context = this .getContextReference ().get ();
254
208
PythonCore pythonCore = context .getCore ();
255
- if (!pythonCore .isInitialized ()) {
256
- pythonCore .initialize ();
257
- }
258
209
Source source = request .getSource ();
259
210
context .initializeMainModule (source .getPath ());
260
211
@@ -346,8 +297,16 @@ protected Object findMetaObject(PythonContext context, Object value) {
346
297
return null ;
347
298
}
348
299
349
- public static PythonContext getContext () {
350
- return getCurrentContext (PythonLanguage .class );
300
+ public static PythonLanguage getCurrent () {
301
+ return getCurrentLanguage (PythonLanguage .class );
302
+ }
303
+
304
+ public static ContextReference <PythonContext > getContextRef () {
305
+ return getCurrentLanguage (PythonLanguage .class ).getContextReference ();
306
+ }
307
+
308
+ public static PythonCore getCore () {
309
+ return getCurrentContext (PythonLanguage .class ).getCore ();
351
310
}
352
311
353
312
@ Override
@@ -395,11 +354,6 @@ protected String toString(PythonContext context, Object value) {
395
354
return res .toString ();
396
355
}
397
356
398
- public static PythonCore getCore () {
399
- PythonCore core = getCurrentLanguage (PythonLanguage .class ).sharedCore ;
400
- return core != null ? core : getContext ().getCore ();
401
- }
402
-
403
357
public static TruffleLogger getLogger () {
404
358
return TruffleLogger .getLogger (ID , PythonLanguage .class );
405
359
}
@@ -419,7 +373,7 @@ public static Source newSource(PythonContext ctxt, URL url, String name) throws
419
373
private static <E1 extends Exception , E2 extends Exception , E3 extends Exception > Source newSource (PythonContext ctxt , Builder <E1 , E2 , E3 > srcBuilder ,
420
374
String name ) throws E1 {
421
375
Builder <E1 , RuntimeException , RuntimeException > newBuilder = srcBuilder .name (name ).mimeType (MIME_TYPE );
422
- boolean internal = !ctxt .getCore ().isInitialized () && !PythonOptions .getOption (ctxt , PythonOptions .ExposeInternalSources ) && ! PythonOptions . getOption ( ctxt , PythonOptions . LazyInit ) ;
376
+ boolean internal = !ctxt .getCore ().isInitialized () && !PythonOptions .getOption (ctxt , PythonOptions .ExposeInternalSources );
423
377
if (internal ) {
424
378
srcBuilder .internal ();
425
379
}
0 commit comments