pub struct Bytecode {
pub elements: Vec<BytecodeElement>,
}
Expand description
Represents the bytecode produced by the compiler.
Bytecode is a wrapper for a list of bytecode elements. It offers an API to extend it by other bytecode, commands or labels.
use jsyc_compiler::{Bytecode, Operation, Instruction, Operand};
let bytecode = Bytecode::new()
.add(Operation::new(Instruction::LoadNum,
vec![Operand::Reg(10), Operand::ShortNum(10)]))
.add(Operation::new(Instruction::Add,
vec![Operand::Reg(10), Operand::Reg(9)]));
Fields§
§elements: Vec<BytecodeElement>
Implementations§
Source§impl Bytecode
impl Bytecode
pub fn new() -> Self
pub fn add(self, command: Operation) -> Self
Sourcepub fn add_label(self, label: Label) -> Self
pub fn add_label(self, label: Label) -> Self
Appends a label as bytecode element.
Sourcepub fn add_bytecode(self, other: Bytecode) -> Self
pub fn add_bytecode(self, other: Bytecode) -> Self
Appends another bytecode onto this bytecode.
Sourcepub fn encode_base64(&self) -> String
pub fn encode_base64(&self) -> String
Returns the base64-encoded bytecode as string.
Sourcepub fn last_op_is_return(&self) -> bool
pub fn last_op_is_return(&self) -> bool
Checks whether the last element is a return instruction.
Sourcepub fn commands_iter_mut(&mut self) -> impl Iterator<Item = &mut Operation>
pub fn commands_iter_mut(&mut self) -> impl Iterator<Item = &mut Operation>
Returns an iterator over all commands in the bytecode.
Trait Implementations§
Source§impl FromIterator<Bytecode> for Bytecode
impl FromIterator<Bytecode> for Bytecode
impl StructuralPartialEq for Bytecode
Auto Trait Implementations§
impl Freeze for Bytecode
impl RefUnwindSafe for Bytecode
impl Send for Bytecode
impl Sync for Bytecode
impl Unpin for Bytecode
impl UnwindSafe for Bytecode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more