pub struct CodeObject<C = ConstantData>where
C: Constant,{Show 19 fields
pub instructions: CodeUnits,
pub locations: Box<[(SourceLocation, SourceLocation)]>,
pub flags: CodeFlags,
pub posonlyarg_count: u32,
pub arg_count: u32,
pub kwonlyarg_count: u32,
pub source_path: <C as Constant>::Name,
pub first_line_number: Option<OneIndexed>,
pub max_stackdepth: u32,
pub obj_name: <C as Constant>::Name,
pub qualname: <C as Constant>::Name,
pub constants: Constants<C>,
pub names: Box<[<C as Constant>::Name]>,
pub varnames: Box<[<C as Constant>::Name]>,
pub cellvars: Box<[<C as Constant>::Name]>,
pub freevars: Box<[<C as Constant>::Name]>,
pub localspluskinds: Box<[u8]>,
pub linetable: Box<[u8]>,
pub exceptiontable: Box<[u8]>,
}Expand description
Primary container of a single code object. Each python function has a code object. Also a module has a code object.
Fields§
§instructions: CodeUnits§locations: Box<[(SourceLocation, SourceLocation)]>§flags: CodeFlags§posonlyarg_count: u32Number of positional-only arguments
arg_count: u32§kwonlyarg_count: u32§source_path: <C as Constant>::Name§first_line_number: Option<OneIndexed>§max_stackdepth: u32§obj_name: <C as Constant>::NameName of the object that created this code object
qualname: <C as Constant>::NameQualified name of the object (like CPython’s co_qualname)
constants: Constants<C>§names: Box<[<C as Constant>::Name]>§varnames: Box<[<C as Constant>::Name]>§cellvars: Box<[<C as Constant>::Name]>§freevars: Box<[<C as Constant>::Name]>§localspluskinds: Box<[u8]>Per-slot kind flags: CO_FAST_LOCAL, CO_FAST_CELL, CO_FAST_FREE, CO_FAST_HIDDEN. Length = nlocalsplus (nlocals + ncells + nfrees).
linetable: Box<[u8]>Line number table (CPython 3.11+ format)
exceptiontable: Box<[u8]>Exception handling table
Implementations§
Source§impl<C> CodeObject<C>where
C: Constant,
impl<C> CodeObject<C>where
C: Constant,
Sourcepub fn arg_names(&self) -> Arguments<'_, <C as Constant>::Name>
pub fn arg_names(&self) -> Arguments<'_, <C as Constant>::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_code_objects(&self) -> impl Display
pub fn display_expand_code_objects(&self) -> impl Display
Recursively display this CodeObject
Sourcepub fn map_bag<Bag>(
self,
bag: Bag,
) -> CodeObject<<Bag as ConstantBag>::Constant>where
Bag: ConstantBag,
pub fn map_bag<Bag>(
self,
bag: Bag,
) -> CodeObject<<Bag as ConstantBag>::Constant>where
Bag: ConstantBag,
Map this CodeObject to one that holds a Bag::Constant
Sourcepub fn map_clone_bag<Bag>(
&self,
bag: &Bag,
) -> CodeObject<<Bag as ConstantBag>::Constant>where
Bag: ConstantBag,
pub fn map_clone_bag<Bag>(
&self,
bag: &Bag,
) -> CodeObject<<Bag as ConstantBag>::Constant>where
Bag: ConstantBag,
Same as map_bag but clones self
Trait Implementations§
Source§impl<C> Clone for CodeObject<C>
impl<C> Clone for CodeObject<C>
Source§fn clone(&self) -> CodeObject<C>
fn clone(&self) -> CodeObject<C>
Returns a duplicate 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> Debug for CodeObject<C>where
C: Constant,
impl<C> Debug for CodeObject<C>where
C: Constant,
Source§impl<C> Display for CodeObject<C>where
C: Constant,
impl<C> Display for CodeObject<C>where
C: Constant,
Source§impl<C> InstrDisplayContext for CodeObject<C>where
C: Constant,
impl<C> InstrDisplayContext for CodeObject<C>where
C: Constant,
Source§impl ToPyObject for CodeObject
impl ToPyObject for CodeObject
fn to_pyobject(self, vm: &VirtualMachine) -> PyObjectRef
Source§impl ToPyObject for CodeObject<Literal>
impl ToPyObject for CodeObject<Literal>
fn to_pyobject(self, vm: &VirtualMachine) -> PyObjectRef
Auto Trait Implementations§
impl<C = ConstantData> !Freeze for CodeObject<C>
impl<C = ConstantData> !RefUnwindSafe for CodeObject<C>
impl<C> Send for CodeObject<C>
impl<C> Sync for CodeObject<C>
impl<C> Unpin for CodeObject<C>
impl<C> UnsafeUnpin for CodeObject<C>
impl<C> UnwindSafe for CodeObject<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
fn overflowing_into(self) -> (U, bool)
Source§impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
fn rounding_into(self, rm: RoundingMode) -> (U, Ordering)
Source§impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
fn saturating_into(self) -> U
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read more