Struct csx64::asm::expr::SymbolTable [−][src]
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]
&mut self,
symbol: String,
value: Expr,
tag: T
) -> Result<(), String>
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]
&self
) -> impl Iterator<Item = (&String, &(Expr, T))> + FusedIterator
Iterates over the defined symbols and their values, along with the tag.
Trait Implementations
impl<T> BinaryRead for SymbolTable<T> where
T: BinaryRead,
[src]
T: BinaryRead,
impl<T> BinaryWrite for SymbolTable<T> where
T: BinaryWrite,
[src]
T: BinaryWrite,
impl<T: Clone> Clone for SymbolTable<T>
[src]
fn clone(&self) -> SymbolTable<T>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T> Debug for SymbolTable<T> where
T: Debug,
[src]
T: Debug,
impl<T: Default> Default for SymbolTable<T>
[src]
fn default() -> 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,
T: Send,
impl<T> !Sync for SymbolTable<T>
impl<T> Unpin for SymbolTable<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for SymbolTable<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Az for T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> CheckedAs for T
[src]
pub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
[src]
T: CheckedCast<Dst>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> OverflowingAs for T
[src]
pub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
[src]
T: OverflowingCast<Dst>,
impl<T> SaturatingAs for T
[src]
pub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
[src]
T: SaturatingCast<Dst>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> UnwrappedAs for T
[src]
pub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
[src]
T: UnwrappedCast<Dst>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<T> WrappingAs for T
[src]
pub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
[src]
T: WrappingCast<Dst>,