pub struct CodeSection {
    pub section_type: CodeType,
    /* private fields */
}
Expand description

A code section within a KSM file.

A KSM file can have as many of these as required, as each one can represent a user-defined function, or other types of code.

There should be a minimum of three of them in each KSM file in order for it to be properly loaded into kOS.

All of the function code sections should come first, followed by a required, but possibly empty Initialization section, followed by a required, but possibly empty Main section.

Fields§

§section_type: CodeType

The type of code section that this is

Implementations§

source§

impl CodeSection

source

pub fn new(section_type: CodeType) -> Self

Creates a new code section of the provided type

source

pub fn with_instructions(self, iter: impl IntoIterator<Item = Instr>) -> Self

A builder-style method that takes in an iterator of instructions that should be added to this CodeSection

source

pub fn instructions(&self) -> Iter<'_, Instr>

Returns an iterator over all of the instructions in this code section

source

pub fn add(&mut self, instr: Instr)

Adds a new instruction to this code section

source

pub fn size_bytes(&self, index_bytes: IntSize) -> usize

Returns how large this section will be if it is written with the provided number of argument index bytes

source

pub fn write(&self, buf: &mut Vec<u8>, index_bytes: IntSize)

Converts this code section into bytes and appends it to the provided buffer.

This requires the number of bytes required to index into the argument section so that instruction operands can be written using the correct byte width.

source

pub fn parse( source: &mut BufferIterator<'_>, index_bytes: IntSize ) -> Result<Self, CodeSectionParseError>

Parses a code section from bytes.

This requires the number of bytes required to index into the argument section so that instruction operands can be read using the correct byte width.

Trait Implementations§

source§

impl Clone for CodeSection

source§

fn clone(&self) -> CodeSection

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CodeSection

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.