80
80
import com .oracle .truffle .api .dsl .Bind ;
81
81
import com .oracle .truffle .api .dsl .Cached ;
82
82
import com .oracle .truffle .api .dsl .Specialization ;
83
- import com .oracle .truffle .api .frame .MaterializedFrame ;
84
83
import com .oracle .truffle .api .frame .VirtualFrame ;
85
84
import com .oracle .truffle .api .instrumentation .StandardTags ;
86
85
import com .oracle .truffle .api .instrumentation .Tag ;
@@ -118,7 +117,6 @@ protected final Object importModule(VirtualFrame frame, String name) {
118
117
return importModule (frame , name , PNone .NONE , PythonUtils .EMPTY_STRING_ARRAY , 0 );
119
118
}
120
119
121
-
122
120
public static final Object importModule (String name ) {
123
121
return importModule (name , PythonUtils .EMPTY_STRING_ARRAY );
124
122
}
@@ -164,7 +162,8 @@ protected final Object importModule(VirtualFrame frame, String name, Object glob
164
162
}
165
163
166
164
/**
167
- * Equivalent to CPython's import_name. We also pass the builtins module in, because we ignore what it's set to in the frame and globals.
165
+ * Equivalent to CPython's import_name. We also pass the builtins module in, because we ignore
166
+ * what it's set to in the frame and globals.
168
167
*/
169
168
abstract static class ImportName extends Node {
170
169
protected abstract Object execute (VirtualFrame frame , PythonContext context , PythonModule builtins , String name , Object globals , String [] fromList , int level );
@@ -211,7 +210,8 @@ protected static final int indexOfDot(String name) {
211
210
}
212
211
213
212
@ Specialization (guards = {"level == 0" , "fromList.length == 0" , "dotIndex < 0" })
214
- static Object levelZeroNoFromlist (VirtualFrame frame , PythonContext context , String name , @ SuppressWarnings ("unused" ) Object globals , @ SuppressWarnings ("unused" ) String [] fromList , @ SuppressWarnings ("unused" ) int level ,
213
+ static Object levelZeroNoFromlist (VirtualFrame frame , PythonContext context , String name , @ SuppressWarnings ("unused" ) Object globals , @ SuppressWarnings ("unused" ) String [] fromList ,
214
+ @ SuppressWarnings ("unused" ) int level ,
215
215
@ SuppressWarnings ("unused" ) @ Bind ("indexOfDot(name)" ) int dotIndex ,
216
216
@ Cached PRaiseNode raiseNode ,
217
217
@ Cached PyDictGetItem getModuleNode ,
@@ -281,13 +281,18 @@ static Object genericImport(VirtualFrame frame, PythonContext context, String na
281
281
Object front = new ModuleFront (name .substring (0 , dotIndex ));
282
282
// cpython recurses, we have transformed the recursion into a loop
283
283
do {
284
- // we omit a few arguments in the recursion, because that makes things simpler.
284
+ // we omit a few arguments in the recursion, because that makes things
285
+ // simpler.
285
286
// globals are null, fromlist is empty, level is 0
286
- front = genericImportRecursion (frame , context , (ModuleFront )front ,
287
- raiseNode , // raiseNode only needed if front.length() == 0 at this point
288
- getModuleNode , // used multiple times to get the 'front' module
289
- ensureInitialized , // used multiple times on the 'front' module
290
- findAndLoad ); // used multiple times, but always to call the exact same function
287
+ front = genericImportRecursion (frame , context , (ModuleFront ) front ,
288
+ raiseNode , // raiseNode only needed if front.length() ==
289
+ // 0 at this point
290
+ getModuleNode , // used multiple times to get the 'front'
291
+ // module
292
+ ensureInitialized , // used multiple times on the
293
+ // 'front' module
294
+ findAndLoad ); // used multiple times, but always to call
295
+ // the exact same function
291
296
} while (recursiveCase .profile (front instanceof ModuleFront ));
292
297
return front ;
293
298
} else {
@@ -344,8 +349,8 @@ static final Object genericImportRecursion(VirtualFrame frame, PythonContext con
344
349
}
345
350
346
351
/**
347
- * Equivalent of CPython's PyModuleSpec_IsInitializing, but for convenience it takes the
348
- * module, not the spec.
352
+ * Equivalent of CPython's PyModuleSpec_IsInitializing, but for convenience it takes the module,
353
+ * not the spec.
349
354
*/
350
355
static abstract class PyModuleIsInitializing extends Node {
351
356
abstract boolean execute (VirtualFrame frame , Object mod );
@@ -361,7 +366,8 @@ static boolean isInitializing(VirtualFrame frame, Object mod,
361
366
Object initializing = getInitNode .execute (frame , spec , "_initializing" );
362
367
return isTrue .execute (frame , initializing );
363
368
} catch (PException e ) {
364
- // _PyModuleSpec_IsInitializing clears any error that happens during getting the __spec__ or _initializing attributes
369
+ // _PyModuleSpec_IsInitializing clears any error that happens during getting the
370
+ // __spec__ or _initializing attributes
365
371
return false ;
366
372
}
367
373
}
@@ -378,7 +384,9 @@ static void ensureInitialized(VirtualFrame frame, PythonContext context, Object
378
384
@ Cached PyModuleIsInitializing isInitializing ,
379
385
@ Cached PyObjectCallMethodObjArgs callLockUnlock ) {
380
386
if (isInitializing .execute (frame , mod )) {
381
- callLockUnlock .execute (frame , context .getImportlib (), "_lock_unlock_module" , name ); // blocks until done
387
+ callLockUnlock .execute (frame , context .getImportlib (), "_lock_unlock_module" , name ); // blocks
388
+ // until
389
+ // done
382
390
}
383
391
}
384
392
}
@@ -433,7 +441,8 @@ String resolveName(VirtualFrame frame, String name, Object globals, int level,
433
441
// TODO: emit warning
434
442
// Object parent = getParent.execute(frame, spec, "parent");
435
443
// equal = PyObject_RichCompareBool(package, parent, Py_EQ);
436
- // if (equal == 0) { PyErr_WarnEx(PyExc_ImportWarning, "__package__ != __spec__.parent", 1) }
444
+ // if (equal == 0) { PyErr_WarnEx(PyExc_ImportWarning, "__package__ !=
445
+ // __spec__.parent", 1) }
437
446
}
438
447
} else if (spec != null && spec != PNone .NONE ) {
439
448
if ((branchStates & PKG_IS_NULL ) == 0 ) {
@@ -535,11 +544,11 @@ static Object findAndLoad(VirtualFrame frame, PythonContext context, String absN
535
544
// Object sysMetaPath = readPath.execute(sys, "meta_path");
536
545
// Object sysPathHooks = readPath.execute(sys, "path_hooks");
537
546
// audit.execute("import", new Object[] {
538
- // absName,
539
- // PNone.NONE,
540
- // sysPath == PNone.NO_VALUE ? PNone.NONE : sysPath,
541
- // sysMetaPath == PNone.NO_VALUE ? PNone.NONE : sysMetaPath,
542
- // sysPathHooks == PNone.NO_VALUE ? PNone.NONE : sysPathHooks);
547
+ // absName,
548
+ // PNone.NONE,
549
+ // sysPath == PNone.NO_VALUE ? PNone.NONE : sysPath,
550
+ // sysMetaPath == PNone.NO_VALUE ? PNone.NONE : sysMetaPath,
551
+ // sysPathHooks == PNone.NO_VALUE ? PNone.NONE : sysPathHooks);
543
552
return callFindAndLoad .execute (frame , context .getImportlib (), "_find_and_load" , absName , context .importFunc ());
544
553
}
545
554
}
0 commit comments