Struct ByteCode

Source
pub struct ByteCode { /* private fields */ }
Expand description

An interpreter-ready sequence of instructions.

Process is an execution primitive that can be used to execute generated ByteCode.

Generated ByteCode is highly optimized for size and sees frequent breaking changes. Because of this, there is currently no support for touching the actual bytecode itself. If you wish to view the generated bytecode, you may use the ByteCode::dump_code and ByteCode::dump_data utilities, a wrapper for which is included in the standard netsblox-vm cli.

This type supports serde serialization if the serde feature flag is enabled.

Implementations§

Source§

impl ByteCode

Source

pub fn compile( role: &Role, ) -> Result<(ByteCode, InitInfo, Locations, ScriptInfo<'_>), CompileError<'_>>

Compiles a single project role into an executable form. The core information is stored in ByteCode (instructions acting on a state) and InitInfo (the initial project state).

This also emits a Locations object mapping bytecode index to code location (e.g., the block collabId from project xml), which is needed to provide human-readable error locations at runtime, as well as a ScriptInfo object that contains a symbol table of functions and scripts (needed to execute a specific segment of code).

Examples found in repository?
examples/basic.rs (line 90)
84fn get_running_project(xml: &str, system: Rc<StdSystem<C>>) -> EnvArena {
85    EnvArena::new(|mc| {
86        let parser = ast::Parser::default();
87        let ast = parser.parse(xml).unwrap();
88        assert_eq!(ast.roles.len(), 1); // this should be handled more elegantly in practice - for the sake of this example, we only allow one role
89
90        let (bytecode, init_info, locs, _) = ByteCode::compile(&ast.roles[0]).unwrap();
91
92        let mut proj = Project::from_init(mc, &init_info, Rc::new(bytecode), Settings::default(), system);
93        proj.input(mc, Input::Start); // this is equivalent to clicking the green flag button
94
95        Env { proj: Gc::new(mc, RefLock::new(proj)), locs }
96    })
97}
Source

pub fn dump_code(&self, f: &mut dyn Write) -> Result<()>

Generates a hex dump of the stored code, including instructions and addresses.

Source

pub fn dump_data(&self, f: &mut dyn Write) -> Result<()>

Generate a hex dump of the stored program data, including string literals and meta values.

Source

pub fn total_size(&self) -> usize

Returns the total size of the ByteCode object (in bytes).

Trait Implementations§

Source§

impl<'de> Deserialize<'de> for ByteCode

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ByteCode

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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

Source§

impl<T> ErasedDestructor for T
where T: 'static,