Skip to content

Commit 44cad9f

Browse files
committed
ImportStar
1 parent 0ae6b45 commit 44cad9f

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

compiler/codegen/src/compile.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,12 @@ impl Compiler<'_> {
784784

785785
if import_star {
786786
// from .... import *
787-
emit!(self, Instruction::ImportStar);
787+
emit!(
788+
self,
789+
Instruction::CallIntrinsic1 {
790+
func: bytecode::IntrinsicFunction1::ImportStar
791+
}
792+
);
788793
} else {
789794
// from mod import a, b as c
790795

compiler/core/src/bytecode.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ op_arg_enum!(
382382
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
383383
#[repr(u8)]
384384
pub enum IntrinsicFunction1 {
385+
/// Import * operation
386+
ImportStar = 2,
385387
/// Type parameter related
386388
TypeVar = 7,
387389
ParamSpec = 8,
@@ -419,8 +421,6 @@ pub enum Instruction {
419421
},
420422
/// Importing without name
421423
ImportNameless,
422-
/// Import *
423-
ImportStar,
424424
/// from ... import ...
425425
ImportFrom {
426426
idx: Arg<NameIdx>,
@@ -1240,7 +1240,6 @@ impl Instruction {
12401240
match self {
12411241
Nop => 0,
12421242
ImportName { .. } | ImportNameless => -1,
1243-
ImportStar => -1,
12441243
ImportFrom { .. } => 1,
12451244
LoadFast(_) | LoadNameAny(_) | LoadGlobal(_) | LoadDeref(_) | LoadClassDeref(_) => 1,
12461245
StoreFast(_) | StoreLocal(_) | StoreGlobal(_) | StoreDeref(_) => -1,
@@ -1433,7 +1432,6 @@ impl Instruction {
14331432
Nop => w!(Nop),
14341433
ImportName { idx } => w!(ImportName, name = idx),
14351434
ImportNameless => w!(ImportNameless),
1436-
ImportStar => w!(ImportStar),
14371435
ImportFrom { idx } => w!(ImportFrom, name = idx),
14381436
LoadFast(idx) => w!(LoadFast, varname = idx),
14391437
LoadNameAny(idx) => w!(LoadNameAny, name = idx),

vm/src/frame.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,6 @@ impl ExecutingFrame<'_> {
541541
self.import(vm, None)?;
542542
Ok(None)
543543
}
544-
bytecode::Instruction::ImportStar => {
545-
self.import_star(vm)?;
546-
Ok(None)
547-
}
548544
bytecode::Instruction::ImportFrom { idx } => {
549545
let obj = self.import_from(vm, idx.get(arg))?;
550546
self.push_value(obj);
@@ -2203,6 +2199,12 @@ impl ExecutingFrame<'_> {
22032199
vm: &VirtualMachine,
22042200
) -> PyResult {
22052201
match func {
2202+
bytecode::IntrinsicFunction1::ImportStar => {
2203+
// arg is the module object
2204+
self.push_value(arg); // Push module back on stack for import_star
2205+
self.import_star(vm)?;
2206+
Ok(vm.ctx.none())
2207+
}
22062208
bytecode::IntrinsicFunction1::SubscriptGeneric => {
22072209
// Used for PEP 695: Generic[*type_params]
22082210
crate::builtins::genericalias::subscript_generic(arg, vm)

0 commit comments

Comments
 (0)