pub struct CodeObject {
pub name: String,
pub loc: Option<String>,
pub uses: Vec<String>,
pub entries: Vec<(usize, usize)>,
pub consts: Vec<Value>,
pub idents: Vec<Variable>,
pub code: Vec<Instruction>,
}Expand description
CodeObject contains the bytecode as well as all the data used by it.
The entries attribute is a vector of name-offset pairs where the first component is an
index into idents. This information is essential for the run_bytecode function used by
CodeObjectFunction. It shouldn’t be necessary to manually alter entries. By default,
the subprogram named ENTRY_POINT will be at offset 0:
main:
...
ret
add:
...
retValues will be returned over the value stack. Every code object has
to return some value on termination. If no value is produced, Nil is implicitly returned.
Fields§
§name: StringName of the object. This is used as the modules name when imported.
loc: Option<String>Location of objects origin.
uses: Vec<String>Modules required for executing this object successfully.
entries: Vec<(usize, usize)>Entry points for the bytecode in the form Vec<(index_into_idents, bytecode_offset)>. These are the functions of the module.
consts: Vec<Value>Necessary constants.
idents: Vec<Variable>Necessary identifiers.
code: Vec<Instruction>Bytecode itself.
Implementations§
Source§impl CodeObject
impl CodeObject
pub fn new() -> Self
Sourcepub fn load_from_file<T>(path: T) -> Lovm2Result<Self>
pub fn load_from_file<T>(path: T) -> Lovm2Result<Self>
Tries to load the file as shared object first and falls back to regular deserialization if it failed
Sourcepub fn to_bytes(&self) -> Lovm2Result<Vec<u8>>
pub fn to_bytes(&self) -> Lovm2Result<Vec<u8>>
Return the objects representation as bytes
Sourcepub fn store_to_file<T>(&self, path: T) -> Lovm2Result<()>
pub fn store_to_file<T>(&self, path: T) -> Lovm2Result<()>
Write the object to a file at given path
Trait Implementations§
Source§impl CallProtocol for CodeObject
impl CallProtocol for CodeObject
Source§impl Clone for CodeObject
impl Clone for CodeObject
Source§fn clone(&self) -> CodeObject
fn clone(&self) -> CodeObject
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more