Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 4 additions & 7 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,20 +1351,17 @@ impl Compiler {
.collect()
};

let module_idx = module.as_ref().map(|s| self.name(s.as_str()));

// from .... import (*fromlist)
self.emit_load_const(ConstantData::Integer {
value: (*level).into(),
});
self.emit_load_const(ConstantData::Tuple {
elements: from_list,
});
if let Some(idx) = module_idx {
emit!(self, Instruction::ImportName { idx });
} else {
emit!(self, Instruction::ImportNameless);
}

let module_name = module.as_ref().map_or("", |s| s.as_str());
let module_idx = self.name(module_name);
emit!(self, Instruction::ImportName { idx: module_idx });

if import_star {
// from .... import *
Expand Down
5 changes: 1 addition & 4 deletions crates/compiler-core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,6 @@ pub enum Instruction {
ImportFrom {
idx: Arg<NameIdx>,
},
/// Importing without name
ImportNameless,
/// Importing by name
ImportName {
idx: Arg<NameIdx>,
Expand Down Expand Up @@ -1607,7 +1605,7 @@ impl Instruction {
pub fn stack_effect(&self, arg: OpArg, jump: bool) -> i32 {
match self {
Nop => 0,
ImportName { .. } | ImportNameless => -1,
ImportName { .. } => -1,
ImportFrom { .. } => 1,
LoadFast(_) | LoadNameAny(_) | LoadGlobal(_) | LoadDeref(_) | LoadClassDeref(_) => 1,
StoreFast(_) | StoreLocal(_) | StoreGlobal(_) | StoreDeref(_) => -1,
Expand Down Expand Up @@ -1844,7 +1842,6 @@ impl Instruction {
GetIter => w!(GetIter),
GetLen => w!(GetLen),
ImportFrom { idx } => w!(ImportFrom, name = idx),
ImportNameless => w!(ImportNameless),
ImportName { idx } => w!(ImportName, name = idx),
IsOp(inv) => w!(IS_OP, ?inv),
JumpIfFalseOrPop { target } => w!(JumpIfFalseOrPop, target),
Expand Down
4 changes: 0 additions & 4 deletions crates/vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,10 +939,6 @@ impl ExecutingFrame<'_> {
self.push_value(obj);
Ok(None)
}
bytecode::Instruction::ImportNameless => {
self.import(vm, None)?;
Ok(None)
}
bytecode::Instruction::ImportName { idx } => {
self.import(vm, Some(self.code.names[idx.get(arg) as usize]))?;
Ok(None)
Expand Down
Loading