Struct lovm2_core::code::CodeObject[][src]

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

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:
    ...
    ret

Values 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: String

Name 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

impl CodeObject[src]

pub fn new() -> Self[src]

pub fn load_from_file<T>(path: T) -> Lovm2Result<Self> where
    T: AsRef<Path>, 
[src]

Tries to load the file as shared object first and falls back to regular deserialization if it failed

pub fn to_bytes(&self) -> Lovm2Result<Vec<u8>>[src]

Return the objects representation as bytes

pub fn store_to_file<T>(&self, path: T) -> Lovm2Result<()> where
    T: AsRef<Path>, 
[src]

Write the object to a file at given path

Trait Implementations

impl CallProtocol for CodeObject[src]

impl Clone for CodeObject[src]

impl Debug for CodeObject[src]

impl Default for CodeObject[src]

impl<'de> Deserialize<'de> for CodeObject[src]

impl From<CodeObject> for Module[src]

impl Serialize for CodeObject[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.