pub struct Bytecode {Show 15 fields
pub version: u8,
pub entrypoint: RefFun,
pub ints: Vec<i32>,
pub floats: Vec<f64>,
pub strings: Vec<String>,
pub bytes: Option<(Vec<u8>, Vec<usize>)>,
pub debug_files: Option<Vec<String>>,
pub types: Vec<Type>,
pub globals: Vec<RefType>,
pub natives: Vec<Native>,
pub functions: Vec<Function>,
pub constants: Option<Vec<ConstantDef>>,
pub findexes: Vec<RefFunKnown>,
pub fnames: HashMap<String, usize>,
pub globals_initializers: HashMap<RefGlobal, usize>,
}
Expand description
Bytecode structure containing all the information. Every field is public for flexibility, but you aren’t encouraged to modify them.
We try to keep optimizations, and acceleration structures separated from the main data.
Fields
version: u8
Bytecode format version
entrypoint: RefFun
Program entrypoint
ints: Vec<i32>
i32 constant pool
floats: Vec<f64>
f64 constant pool
strings: Vec<String>
String constant pool
bytes: Option<(Vec<u8>, Vec<usize>)>
Bytes constant pool
Since bytecode v5
debug_files: Option<Vec<String>>
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
findexes: Vec<RefFunKnown>
Acceleration structure mapping function references (findex) to functions indexes in the native or function pool.
fnames: HashMap<String, usize>
Acceleration structure mapping function names to function indexes in the function pool
globals_initializers: HashMap<RefGlobal, usize>
Implementations
sourceimpl Bytecode
impl Bytecode
sourcepub fn load(r: &mut impl Read) -> Result<Bytecode>
pub fn load(r: &mut impl Read) -> Result<Bytecode>
Load the bytecode from any source. Must be a valid hashlink bytecode binary.
sourcepub fn serialize(&self, w: &mut impl Write) -> Result<()>
pub fn serialize(&self, w: &mut impl Write) -> Result<()>
Serialize the bytecode to any sink. Bytecode is serialized to the same format.
sourcepub fn entrypoint(&self) -> &Function
pub fn entrypoint(&self) -> &Function
Get the entrypoint function.
sourcepub fn main(&self) -> &Function
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)
sourcepub fn function_by_name(&self, name: &str) -> Option<&Function>
pub fn function_by_name(&self, name: &str) -> Option<&Function>
Get a function by its name.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Bytecode
impl Send for Bytecode
impl Sync for Bytecode
impl Unpin for Bytecode
impl UnwindSafe for Bytecode
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more