[][src]Enum pir_8_emu::binutils::pir_8_as::AssemblerDirective

pub enum AssemblerDirective<'s> {
    SetOrigin(u16),
    SaveLabel(&'s str),
    LoadLabel(&'s stri16LabelFragment),
    InsertLiteral(&'s str),
}

An assembler directive, extending the normal assembly syntax

Variants

SetOrigin(u16)

Start writing the code at the specified address, 0-padding thereupto

Using this directive the second time or after processing an instruction is an error

Syntax: :origin [address]

SaveLabel(&'s str)

Save the current output address to recall later

Syntax: :label save [name]

LoadLabel(&'s stri16LabelFragment)

Load the specified part of the label with the specified name, or wait for it to be saved later, adding the specified offset

Not having saved all previously loaded labels by the end of input is an error

Attempting to load a full label when the current instruction doesn't expect 2-byte data is an error, and attempting to load a partial label when the current instruction doesn't expect 1-byte data is an error.

Syntax: :label load [full|high|low] [name]

Syntax: :label load-offset [full|high|low] [name] [offset]

InsertLiteral(&'s str)

Blindly write the specified literal

Attempting to insert a literal when the current instruction is expecting data is an error

Syntax: :literal "UwU"

Methods

impl<'s> AssemblerDirective<'s>[src]

pub fn from_str(s: &'s str) -> Result<Option<Self>, ParseInstructionError>[src]

Parse a directive as found among other assembly

If the specified string doesn't start with a colon, Ok(None) is returned

Examples

assert_eq!(AssemblerDirective::from_str(":origin 0x0110"),
           Ok(Some(AssemblerDirective::SetOrigin(0x0110))));

assert_eq!(AssemblerDirective::from_str(": label load full OwO"),
           Ok(Some(AssemblerDirective::LoadLabel("OwO", 0, LabelFragment::Full))));

assert_eq!(AssemblerDirective::from_str(": label load-offset high OwO -1"),
           Ok(Some(AssemblerDirective::LoadLabel("OwO", -1, LabelFragment::High))));

assert_eq!(AssemblerDirective::from_str("label save uwu"),
           Ok(None));

pub fn obey(
    &self,
    next_output_address: &mut Option<u16>,
    labels: &mut BTreeMap<String, u16>
) -> Result<Option<Result<LabelLoad, &'s str>>, AssemblerDirectiveObeyError<'s>>
[src]

Obey this directive, updating the output address and labelset as required

Examples

let mut next_output_address = None;
let mut labels = BTreeMap::new();

assert_eq!(AssemblerDirective::SetOrigin(0x0110)
               .obey(&mut next_output_address, &mut labels),
           Ok(None));

assert_eq!(AssemblerDirective::LoadLabel("owo", 0, LabelFragment::Full)
               .obey(&mut next_output_address, &mut labels),
           Ok(Some(Ok(LabelLoad::WaitFor("owo".to_string(), 0, LabelFragment::Full)))));
assert_eq!(AssemblerDirective::SaveLabel("owo")
               .obey(&mut next_output_address, &mut labels),
           Ok(None));
assert_eq!(AssemblerDirective::LoadLabel("owo", 0, LabelFragment::High)
               .obey(&mut next_output_address, &mut labels),
           Ok(Some(Ok(LabelLoad::HaveImmediately(0x0110, LabelFragment::High)))));
assert_eq!(AssemblerDirective::LoadLabel("owo", 0x0F, LabelFragment::Low)
               .obey(&mut next_output_address, &mut labels),
           Ok(Some(Ok(LabelLoad::HaveImmediately(0x011F, LabelFragment::Low)))));

assert_eq!(AssemblerDirective::InsertLiteral("EwE")
               .obey(&mut next_output_address, &mut labels),
           Ok(Some(Err("EwE"))));

assert_eq!(next_output_address, Some(0x0110));
assert_eq!(labels, vec![("owo".to_string(), 0x0110)].into_iter().collect());

Trait Implementations

impl<'s> Clone for AssemblerDirective<'s>[src]

impl<'s> Copy for AssemblerDirective<'s>[src]

impl<'s> Debug for AssemblerDirective<'s>[src]

impl<'s> Eq for AssemblerDirective<'s>[src]

impl<'s> Hash for AssemblerDirective<'s>[src]

impl<'s> Ord for AssemblerDirective<'s>[src]

impl<'s> PartialEq<AssemblerDirective<'s>> for AssemblerDirective<'s>[src]

impl<'s> PartialOrd<AssemblerDirective<'s>> for AssemblerDirective<'s>[src]

impl<'s> StructuralEq for AssemblerDirective<'s>[src]

impl<'s> StructuralPartialEq for AssemblerDirective<'s>[src]

Auto Trait Implementations

impl<'s> RefUnwindSafe for AssemblerDirective<'s>

impl<'s> Send for AssemblerDirective<'s>

impl<'s> Sync for AssemblerDirective<'s>

impl<'s> Unpin for AssemblerDirective<'s>

impl<'s> UnwindSafe for AssemblerDirective<'s>

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> Downcast for T where
    T: Any
[src]

impl<T> DowncastSync for T where
    T: Send + Sync + Any
[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.