Struct rustpython_compiler_core::CodeObject
source · pub struct CodeObject<C: Constant = ConstantData> {Show 16 fields
pub instructions: Box<[Instruction]>,
pub locations: Box<[Location]>,
pub flags: CodeFlags,
pub posonlyarg_count: usize,
pub arg_count: usize,
pub kwonlyarg_count: usize,
pub source_path: C::Name,
pub first_line_number: usize,
pub max_stackdepth: u32,
pub obj_name: C::Name,
pub cell2arg: Option<Box<[isize]>>,
pub constants: Box<[C]>,
pub names: Box<[C::Name]>,
pub varnames: Box<[C::Name]>,
pub cellvars: Box<[C::Name]>,
pub freevars: Box<[C::Name]>,
}Expand description
Primary container of a single code object. Each python function has a codeobject. Also a module has a codeobject.
Fields§
§instructions: Box<[Instruction]>§locations: Box<[Location]>§flags: CodeFlags§posonlyarg_count: usize§arg_count: usize§kwonlyarg_count: usize§source_path: C::Name§first_line_number: usize§max_stackdepth: u32§obj_name: C::Name§cell2arg: Option<Box<[isize]>>§constants: Box<[C]>§names: Box<[C::Name]>§varnames: Box<[C::Name]>§cellvars: Box<[C::Name]>§freevars: Box<[C::Name]>Implementations§
source§impl<C: Constant> CodeObject<C>
impl<C: Constant> CodeObject<C>
sourcepub fn arg_names(&self) -> Arguments<'_, C::Name>
pub fn arg_names(&self) -> Arguments<'_, C::Name>
Get all arguments of the code object like inspect.getargs
sourcepub fn label_targets(&self) -> BTreeSet<Label>
pub fn label_targets(&self) -> BTreeSet<Label>
Return the labels targeted by the instructions of this CodeObject
sourcepub fn display_expand_codeobjects(&self) -> impl Display + '_
pub fn display_expand_codeobjects(&self) -> impl Display + '_
Recursively display this CodeObject
sourcepub fn map_bag<Bag: ConstantBag>(self, bag: Bag) -> CodeObject<Bag::Constant>
pub fn map_bag<Bag: ConstantBag>(self, bag: Bag) -> CodeObject<Bag::Constant>
Map this CodeObject to one that holds a Bag::Constant
sourcepub fn map_clone_bag<Bag: ConstantBag>(
&self,
bag: &Bag
) -> CodeObject<Bag::Constant>
pub fn map_clone_bag<Bag: ConstantBag>(
&self,
bag: &Bag
) -> CodeObject<Bag::Constant>
Same as map_bag but clones self
source§impl CodeObject<ConstantData>
impl CodeObject<ConstantData>
sourcepub fn from_bytes(data: &[u8]) -> Result<Self, CodeDeserializeError>
pub fn from_bytes(data: &[u8]) -> Result<Self, CodeDeserializeError>
Load a code object from bytes
Trait Implementations§
source§impl<C: Clone + Constant> Clone for CodeObject<C>where
C::Name: Clone,
impl<C: Clone + Constant> Clone for CodeObject<C>where
C::Name: Clone,
source§fn clone(&self) -> CodeObject<C>
fn clone(&self) -> CodeObject<C>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl<C: Constant> Debug for CodeObject<C>
impl<C: Constant> Debug for CodeObject<C>
source§impl<'de, C> Deserialize<'de> for CodeObject<C>where
C::Name: Deserialize<'de> + Deserialize<'de>,
C: Deserialize<'de> + Constant,
impl<'de, C> Deserialize<'de> for CodeObject<C>where
C::Name: Deserialize<'de> + Deserialize<'de>,
C: Deserialize<'de> + Constant,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more