Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ImportStar
  • Loading branch information
youknowone committed Jul 11, 2025
commit 44cad9fea43b08740fe3571566b265ded0279f3f
7 changes: 6 additions & 1 deletion compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,12 @@ impl Compiler<'_> {

if import_star {
// from .... import *
emit!(self, Instruction::ImportStar);
emit!(
self,
Instruction::CallIntrinsic1 {
func: bytecode::IntrinsicFunction1::ImportStar
}
);
} else {
// from mod import a, b as c

Expand Down
6 changes: 2 additions & 4 deletions compiler/core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ op_arg_enum!(
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum IntrinsicFunction1 {
/// Import * operation
ImportStar = 2,
/// Type parameter related
TypeVar = 7,
ParamSpec = 8,
Expand Down Expand Up @@ -419,8 +421,6 @@ pub enum Instruction {
},
/// Importing without name
ImportNameless,
/// Import *
ImportStar,
/// from ... import ...
ImportFrom {
idx: Arg<NameIdx>,
Expand Down Expand Up @@ -1240,7 +1240,6 @@ impl Instruction {
match self {
Nop => 0,
ImportName { .. } | ImportNameless => -1,
ImportStar => -1,
ImportFrom { .. } => 1,
LoadFast(_) | LoadNameAny(_) | LoadGlobal(_) | LoadDeref(_) | LoadClassDeref(_) => 1,
StoreFast(_) | StoreLocal(_) | StoreGlobal(_) | StoreDeref(_) => -1,
Expand Down Expand Up @@ -1433,7 +1432,6 @@ impl Instruction {
Nop => w!(Nop),
ImportName { idx } => w!(ImportName, name = idx),
ImportNameless => w!(ImportNameless),
ImportStar => w!(ImportStar),
ImportFrom { idx } => w!(ImportFrom, name = idx),
LoadFast(idx) => w!(LoadFast, varname = idx),
LoadNameAny(idx) => w!(LoadNameAny, name = idx),
Expand Down
10 changes: 6 additions & 4 deletions vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,6 @@ impl ExecutingFrame<'_> {
self.import(vm, None)?;
Ok(None)
}
bytecode::Instruction::ImportStar => {
self.import_star(vm)?;
Ok(None)
}
bytecode::Instruction::ImportFrom { idx } => {
let obj = self.import_from(vm, idx.get(arg))?;
self.push_value(obj);
Expand Down Expand Up @@ -2203,6 +2199,12 @@ impl ExecutingFrame<'_> {
vm: &VirtualMachine,
) -> PyResult {
match func {
bytecode::IntrinsicFunction1::ImportStar => {
// arg is the module object
self.push_value(arg); // Push module back on stack for import_star
self.import_star(vm)?;
Ok(vm.ctx.none())
}
bytecode::IntrinsicFunction1::SubscriptGeneric => {
// Used for PEP 695: Generic[*type_params]
crate::builtins::genericalias::subscript_generic(arg, vm)
Expand Down