Struct hlbc::Bytecode

source ·
pub struct Bytecode {
Show 13 fields pub version: u8, pub entrypoint: RefFun, pub ints: Vec<i32>, pub floats: Vec<f64>, pub strings: Vec<Str>, pub bytes: Option<(Vec<u8>, Vec<usize>)>, pub debug_files: Option<Vec<Str>>, pub types: Vec<Type>, pub globals: Vec<RefType>, pub natives: Vec<Native>, pub functions: Vec<Function>, pub constants: Option<Vec<ConstantDef>>, pub globals_initializers: HashMap<RefGlobal, usize>, /* private fields */
}
Expand description

Bytecode structure containing all the information. Every field is public for flexibility, but you aren’t encouraged to modify them.

This type is like an arena, you usually work with custom

Fields§

§version: u8

Bytecode format version

§entrypoint: RefFun

Program entrypoint

§ints: Vec<i32>

i32 constant pool

§floats: Vec<f64>

f64 constant pool

§strings: Vec<Str>

String constant pool

§bytes: Option<(Vec<u8>, Vec<usize>)>

Bytes constant pool

Since bytecode v5

§debug_files: Option<Vec<Str>>

Debug file names constant pool

§types: Vec<Type>

Types, contains every possible types expressed in the program

§globals: Vec<RefType>

Globals, holding static variables and such

§natives: Vec<Native>

Native functions references

§functions: Vec<Function>

Code functions pool

§constants: Option<Vec<ConstantDef>>

Constants, initializers for globals

Since bytecode v4

§globals_initializers: HashMap<RefGlobal, usize>

Implementations§

source§

impl Bytecode

source

pub fn ops(&self) -> impl Iterator<Item = (&Function, (usize, &Opcode))>

Iterate on every instruction of every function

source§

impl Bytecode

source

pub fn deserialize(r: &mut impl Read) -> Result<Bytecode>

Load the bytecode from any source. Must be a valid hashlink bytecode binary.

source

pub fn from_file(path: impl AsRef<Path>) -> Result<Self>

source§

impl Bytecode

source

pub fn serialize(&self, w: &mut impl Write) -> Result<()>

Serialize the bytecode to any sink. Bytecode is serialized to the same format.

source§

impl Bytecode

source

pub fn entrypoint(&self) -> &Function

Get the entrypoint function.

source

pub fn main(&self) -> &Function

Get the main function. This will panic if there is no main function in the bytecode (there should always be one)

source

pub fn function_by_name(&self, name: &str) -> Option<&Function>

Get a function by its name.

source

pub fn findex_max(&self) -> usize

source

pub fn functions<'a>(&'a self) -> impl Iterator<Item = FunPtr<'a>> + 'a

Trait Implementations§

source§

impl Debug for Bytecode

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Bytecode

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Index<RefFloat> for Bytecode

§

type Output = f64

The returned type after indexing.
source§

fn index(&self, index: RefFloat) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RefInt> for Bytecode

§

type Output = i32

The returned type after indexing.
source§

fn index(&self, index: RefInt) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RefString> for Bytecode

§

type Output = FlexStr<flexstr::::FlexStrBase::{constant#0}, flexstr::::FlexStrBase::{constant#1}, flexstr::::FlexStrBase::{constant#2}, Arc<str>>

The returned type after indexing.
source§

fn index(&self, index: RefString) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RefType> for Bytecode

§

type Output = Type

The returned type after indexing.
source§

fn index(&self, index: RefType) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl Resolve<RefFloat> for Bytecode

§

type Output<'a> = f64

source§

fn get(&self, index: RefFloat) -> Self::Output<'_>

source§

impl Resolve<RefFun> for Bytecode

§

type Output<'a> = FunPtr<'a>

source§

fn get(&self, index: RefFun) -> Self::Output<'_>

source§

impl Resolve<RefInt> for Bytecode

§

type Output<'a> = i32

source§

fn get(&self, index: RefInt) -> Self::Output<'_>

source§

impl Resolve<RefString> for Bytecode

§

type Output<'a> = FlexStr<flexstr::::FlexStrBase::{constant#0}, flexstr::::FlexStrBase::{constant#1}, flexstr::::FlexStrBase::{constant#2}, Arc<str>>

source§

fn get(&self, index: RefString) -> Self::Output<'_>

source§

impl Resolve<RefType> for Bytecode

§

type Output<'a> = &'a Type

source§

fn get(&self, index: RefType) -> Self::Output<'_>

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, 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.