Assembler

Struct Assembler 

Source
pub struct Assembler<'a, R, W>
where R: Read, W: Write,
{ pub symbol_table: HashMap<String, u16>, pub instructions: Vec<Instruction>, /* private fields */ }
Expand description

Struct to represent the Assembler’s internal logic. Contains the file references, symbol table, and other necessary state. Can be constructed using the build function.

Fields§

§symbol_table: HashMap<String, u16>

Symbol table to store the addresses of labels and variables. The symbol table is populated during the build of the Assembler.

§instructions: Vec<Instruction>

Vector of Instruction(s) used to store the parsed instructions from the source file. The vector is populated on build and can be used in tandem with the symbol table for custom implementations.

Implementations§

Source§

impl<'a, R, W> Assembler<'a, R, W>
where R: Read, W: Write,

Source

pub fn build( in_file: &'a mut R, out_file: &'a mut W, symbol_file: Option<&'a mut W>, ) -> Result<Assembler<'a, R, W>, Box<dyn Error>>

Constructor for the Assembler struct, returns a Result wrapping either the successfully constructed Assembler or an Err. Takes an input [File] and an output [File] reference as arguments. Returns a Result wrapping the built Assembler instance if successful.

Source

pub fn advance_once(&mut self)

Function to advance the assembler by one instruction, this encoded instruction is then immediately written to the output file.

Source

pub fn advance_to_end(&mut self)

Function to advance the assembler to the end of the file, encoding all instructions and writing them all at once to the output file.

Source

pub fn get_next_encoded_instruction(&mut self) -> Option<String>

Function to get the next encoded instruction from the assembler. Used internally by the Assembler::advance_once and Assembler::advance_to_end functions. But can also be used to get the encoded instructions as strings rather than being written to a file. Returns None if there are no more instructions to encode. Either use this function, or the Assembler::advance_once and Assembler::advance_to_end functions, mixing the two may result in unexpected behavior.

Auto Trait Implementations§

§

impl<'a, R, W> Freeze for Assembler<'a, R, W>

§

impl<'a, R, W> !RefUnwindSafe for Assembler<'a, R, W>

§

impl<'a, R, W> Send for Assembler<'a, R, W>
where W: Send, R: Send,

§

impl<'a, R, W> Sync for Assembler<'a, R, W>
where W: Sync, R: Sync,

§

impl<'a, R, W> Unpin for Assembler<'a, R, W>

§

impl<'a, R, W> !UnwindSafe for Assembler<'a, R, W>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

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

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.