pub struct ProgramHeader<V = Value, Ty = Type> { /* private fields */ }Expand description
Standard header directives in header order, assembled into
ProgramMetadata.
No table index is written by hand. This collects directives in header order and derives every table:
- functions: one per
.func, in.funcorder. A.funcbelongs to the file named by the closest.filebefore it, or to the empty file""if there is none. - entry:
.entry @nameselects the function declared by.func @name. It is optional and may appear at most once. - constants: one per
.const, in.constorder..const str "text"is a string constant and.const fn @namea function reference; other values use the value type’s own syntax, such asu64 42. - source symbols: one per
.source_symbol <index> "<name>"; indices are unique. - strings: each distinct string once, at its first occurrence, in this
order: function names in
.funcorder, then parameter names (by function, then by position), then file names in.funcorder, then.const strliterals in.constorder. Lowering then appends the string literals of.textin address order (MetadataLoweringContextinterns them), so the same file always produces the same table.
Application directives compose with these in one header: an application
declaration enum has a variant holding a ProgramDirective (usually
with #[pattern = "$0"]) and implements StandardDirective; a loader
pushes the standard directives into a ProgramHeader and handles the
others itself.
use vihaco_module::module::{NoInfo, ProgramHeader};
use vihaco_parser::Parse;
use chumsky::Parser;
let header: ProgramHeader = [".file \"a.sst\"", ".func @main() -> u64, locals 0", ".entry @main"]
.into_iter()
.map(|line| vihaco_module::module::ProgramDirective::parser().parse(line).into_result().unwrap())
.collect();
let metadata = header.finish(NoInfo).unwrap();
assert_eq!(metadata.strings, ["main", "a.sst"]);
assert_eq!(metadata.main_function, Some(0));Implementations§
Source§impl<V, Ty> ProgramHeader<V, Ty>
impl<V, Ty> ProgramHeader<V, Ty>
pub fn new() -> Self
Sourcepub fn push(&mut self, directive: ProgramDirective<V, Ty>)
pub fn push(&mut self, directive: ProgramDirective<V, Ty>)
Append the next directive.
Sourcepub fn directives(&self) -> &[ProgramDirective<V, Ty>]
pub fn directives(&self) -> &[ProgramDirective<V, Ty>]
The directives pushed so far, in order.
Sourcepub fn assemble<Info>(
self,
extra: Info,
) -> Result<ProgramMetadata<V, Ty, Info>, Vec<HeaderError>>where
V: ConstantValue,
pub fn assemble<Info>(
self,
extra: Info,
) -> Result<ProgramMetadata<V, Ty, Info>, Vec<HeaderError>>where
V: ConstantValue,
Assemble the tables, reporting every problem.
Problems are duplicate .func names, locals smaller than the
parameter count, more than one .entry, an .entry or .const fn
naming no .func, a constant written as a table index (.const str 3
or .const fn 0), string or function constants the value model cannot
represent, and duplicate .source_symbol indices. Whether each
function has an @name: symbol is checked when the metadata is bound
to .text (ProgramMetadata::validate).
Sourcepub fn finish<Info>(self, extra: Info) -> Result<ProgramMetadata<V, Ty, Info>>where
V: ConstantValue,
pub fn finish<Info>(self, extra: Info) -> Result<ProgramMetadata<V, Ty, Info>>where
V: ConstantValue,
assemble, failing with the first problem.
Trait Implementations§
Source§impl<V: Clone, Ty: Clone> Clone for ProgramHeader<V, Ty>
impl<V: Clone, Ty: Clone> Clone for ProgramHeader<V, Ty>
Source§fn clone(&self) -> ProgramHeader<V, Ty>
fn clone(&self) -> ProgramHeader<V, Ty>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<V, Ty> Default for ProgramHeader<V, Ty>
impl<V, Ty> Default for ProgramHeader<V, Ty>
Source§impl<V, Ty> Extend<ProgramDirective<V, Ty>> for ProgramHeader<V, Ty>
impl<V, Ty> Extend<ProgramDirective<V, Ty>> for ProgramHeader<V, Ty>
Source§fn extend<T: IntoIterator<Item = ProgramDirective<V, Ty>>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = ProgramDirective<V, Ty>>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<V, Ty> FromIterator<ProgramDirective<V, Ty>> for ProgramHeader<V, Ty>
impl<V, Ty> FromIterator<ProgramDirective<V, Ty>> for ProgramHeader<V, Ty>
Source§fn from_iter<T: IntoIterator<Item = ProgramDirective<V, Ty>>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = ProgramDirective<V, Ty>>>(iter: T) -> Self
impl<V: PartialEq, Ty: PartialEq> StructuralPartialEq for ProgramHeader<V, Ty>
Auto Trait Implementations§
impl<V, Ty> Freeze for ProgramHeader<V, Ty>
impl<V, Ty> RefUnwindSafe for ProgramHeader<V, Ty>where
V: RefUnwindSafe,
Ty: RefUnwindSafe,
impl<V, Ty> Send for ProgramHeader<V, Ty>
impl<V, Ty> Sync for ProgramHeader<V, Ty>
impl<V, Ty> Unpin for ProgramHeader<V, Ty>
impl<V, Ty> UnsafeUnpin for ProgramHeader<V, Ty>
impl<V, Ty> UnwindSafe for ProgramHeader<V, Ty>where
V: UnwindSafe,
Ty: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef].