Skip to content

Commit cb59d76

Browse files
Merge pull request RustPython#439 from RustPython/move_unwrap_constant
Move unwrap_constant from Frame to PyContext.
2 parents 23aa4a7 + 860edc6 commit cb59d76

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

vm/src/frame.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Frame {
169169

170170
match &instruction {
171171
bytecode::Instruction::LoadConst { ref value } => {
172-
let obj = self.unwrap_constant(vm, value);
172+
let obj = vm.ctx.unwrap_constant(value);
173173
self.push_value(obj);
174174
Ok(None)
175175
}
@@ -1026,25 +1026,6 @@ impl Frame {
10261026
Ok(None)
10271027
}
10281028

1029-
fn unwrap_constant(&self, vm: &VirtualMachine, value: &bytecode::Constant) -> PyObjectRef {
1030-
match *value {
1031-
bytecode::Constant::Integer { ref value } => vm.ctx.new_int(value.clone()),
1032-
bytecode::Constant::Float { ref value } => vm.ctx.new_float(*value),
1033-
bytecode::Constant::Complex { ref value } => vm.ctx.new_complex(*value),
1034-
bytecode::Constant::String { ref value } => vm.new_str(value.clone()),
1035-
bytecode::Constant::Bytes { ref value } => vm.ctx.new_bytes(value.clone()),
1036-
bytecode::Constant::Boolean { ref value } => vm.new_bool(value.clone()),
1037-
bytecode::Constant::Code { ref code } => vm.ctx.new_code_object(code.clone()),
1038-
bytecode::Constant::Tuple { ref elements } => vm.ctx.new_tuple(
1039-
elements
1040-
.iter()
1041-
.map(|value| self.unwrap_constant(vm, value))
1042-
.collect(),
1043-
),
1044-
bytecode::Constant::None => vm.ctx.none(),
1045-
}
1046-
}
1047-
10481029
pub fn get_lineno(&self) -> ast::Location {
10491030
self.code.locations[self.lasti].clone()
10501031
}

vm/src/pyobject.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,26 @@ impl PyContext {
667667
ref payload => unimplemented!("set_attr unimplemented for: {:?}", payload),
668668
};
669669
}
670+
671+
pub fn unwrap_constant(&mut self, value: &bytecode::Constant) -> PyObjectRef {
672+
match *value {
673+
bytecode::Constant::Integer { ref value } => self.new_int(value.clone()),
674+
bytecode::Constant::Float { ref value } => self.new_float(*value),
675+
bytecode::Constant::Complex { ref value } => self.new_complex(*value),
676+
bytecode::Constant::String { ref value } => self.new_str(value.clone()),
677+
bytecode::Constant::Bytes { ref value } => self.new_bytes(value.clone()),
678+
bytecode::Constant::Boolean { ref value } => self.new_bool(value.clone()),
679+
bytecode::Constant::Code { ref code } => self.new_code_object(code.clone()),
680+
bytecode::Constant::Tuple { ref elements } => {
681+
let elements = elements
682+
.iter()
683+
.map(|value| self.unwrap_constant(value))
684+
.collect();
685+
self.new_tuple(elements)
686+
}
687+
bytecode::Constant::None => self.none(),
688+
}
689+
}
670690
}
671691

672692
/// This is an actual python object. It consists of a `typ` which is the

0 commit comments

Comments
 (0)