MCPcopy Index your code
hub / github.com/RustPython/RustPython / stack_effect

Function stack_effect

crates/stdlib/src/_opcode.rs:168–207  ·  view source on GitHub ↗
(args: StackEffectArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

166
167 #[pyfunction]
168 fn stack_effect(args: StackEffectArgs, vm: &VirtualMachine) -> PyResult<i32> {
169 let oparg = args
170 .oparg
171 .map(|v| {
172 if !v.fast_isinstance(vm.ctx.types.int_type) {
173 return Err(vm.new_type_error(format!(
174 "'{}' object cannot be interpreted as an integer",
175 v.class().name()
176 )));
177 }
178 v.downcast_ref::<PyInt>()
179 .ok_or_else(|| {
180 vm.new_type_error(format!(
181 "'{}' object cannot be interpreted as an integer",
182 v.class().name()
183 ))
184 })?
185 .try_to_primitive::<u32>(vm)
186 })
187 .unwrap_or(Ok(0))?;
188
189 let jump = args
190 .jump
191 .map(|v| {
192 v.try_to_bool(vm).map_err(|_| {
193 vm.new_value_error("stack_effect: jump must be False, True or None")
194 })
195 })
196 .unwrap_or(Ok(false))?;
197
198 let opcode = Opcode::try_from_pyint(args.opcode, vm)?;
199
200 // Raise ValueError if specialized.
201 if opcode.inner().real().is_some_and(|op| op.deopt().is_some()) {
202 return Err(vm.new_value_error("invalid opcode or oparg"));
203 }
204
205 let _ = jump; // Python API accepts jump but it's not used
206 Ok(opcode.stack_effect(oparg))
207 }
208
209 #[pyfunction]
210 fn is_valid(opcode: i32) -> bool {

Callers 2

test_stack_effectMethod · 0.90

Calls 9

fast_isinstanceMethod · 0.80
ok_or_elseMethod · 0.80
try_to_boolMethod · 0.80
deoptMethod · 0.80
stack_effectMethod · 0.80
ErrClass · 0.50
mapMethod · 0.45
realMethod · 0.45
innerMethod · 0.45

Tested by 2

test_stack_effectMethod · 0.72