Struct csx64::asm::expr::SymbolTable[][src]

pub struct SymbolTable<T> { /* fields omitted */ }

An appendonly map-like collection of defined symbols.

Importantly, an instance of this type is used during assembly/linking to facilitate pre- and user-defined symbols.

The type T is a tag type that is associated with the value to give it additional context. For instance, the assembler uses tags to keep track of declaration line numbers.

Example

let mut symbols: SymbolTable<usize> = Default::default();
symbols.define("foo".into(), 2u64.into(), 0).unwrap();

Note that in the above example expr was technically modified despite eval() being an immutable method. This is what will be referred to as auto-reducing logic: the value of expr isn’t actually different, it’s just a simpler representation of the same value. From a rust perspective, this is perfectly safe because, aside from using debug formatting, it would be impossible to know anything had happened at all due to the fact that SymbolTable is appendonly and Expr is opaque.

The way this is done is that any sub-expression in the expression tree which successfully evaluates is replaced with a value node with equivalent content. Because of this, if an Expr is evaluated using a given symbol table, it should typically never be evaluated with any other symbol table, lest the final value be potentially corrupted. Best practice has that there should be only one symbol table, which is what the assembly and linking functions included in this crate do implicitly.

Implementations

impl<T> SymbolTable<T>[src]

pub fn new() -> Self[src]

Constructs an empty symbol table.

pub fn define(
    &mut self,
    symbol: String,
    value: Expr,
    tag: T
) -> Result<(), String>
[src]

Introduces a new symbol. If not already defined, defines it and returns Ok(()). Otherwise, returns Err(symbol).

pub fn get(&self, symbol: &str) -> Option<&(Expr, T)>[src]

Gets the value of the given symbol if defined.

pub fn clear(&mut self)[src]

Undefines all symbols, effectively restoring the newly-constructed state. This is meant to support resource reuse, and should not be used to remove or modify defined symbols.

pub fn iter(
    &self
) -> impl Iterator<Item = (&String, &(Expr, T))> + FusedIterator
[src]

Iterates over the defined symbols and their values, along with the tag.

Trait Implementations

impl<T> BinaryRead for SymbolTable<T> where
    T: BinaryRead
[src]

impl<T> BinaryWrite for SymbolTable<T> where
    T: BinaryWrite
[src]

impl<T: Clone> Clone for SymbolTable<T>[src]

impl<T> Debug for SymbolTable<T> where
    T: Debug
[src]

impl<T: Default> Default for SymbolTable<T>[src]

impl From<SymbolTable<()>> for Predefines[src]

fn from(symbols: SymbolTable<()>) -> Predefines[src]

Constructs a new set of predefines from a symbol table.

impl<T> SymbolTableCore for SymbolTable<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for SymbolTable<T>

impl<T> Send for SymbolTable<T> where
    T: Send

impl<T> !Sync for SymbolTable<T>

impl<T> Unpin for SymbolTable<T> where
    T: Unpin

impl<T> UnwindSafe for SymbolTable<T> where
    T: UnwindSafe

Blanket Implementations

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

impl<T> Az for T[src]

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

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

impl<T> CheckedAs for T[src]

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

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

impl<T> OverflowingAs for T[src]

impl<T> SaturatingAs for 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.

impl<T> UnwrappedAs for T[src]

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

impl<T> WrappingAs for T[src]