/// A declared core function. /// /// This is a member of both the core alias and canon sections. #[derive(Debug)] pubstruct CoreFunc<'a> { /// Where this `core func` was defined. pub span: Span, /// An identifier that this function is resolved with (optionally) for name /// resolution. pub id: Option<Id<'a>>, /// An optional name for this function stored in the custom `name` section. pub name: Option<NameAnnotation<'a>>, /// The kind of core function. pub kind: CoreFuncKind<'a>,
}
impl<'a> Parse<'a> for CoreFunc<'a> { fn parse(parser: Parser<'a>) -> Result<Self> { let span = parser.parse::<kw::core>()?.0;
parser.parse::<kw::func>()?; let id = parser.parse()?; let name = parser.parse()?; let kind = parser.parens(|p| p.parse())?;
Ok(Self {
span,
id,
name,
kind,
})
}
}
/// Represents the kind of core functions. #[derive(Debug)] #[allow(missing_docs)] pubenum CoreFuncKind<'a> { /// The core function is defined in terms of lowering a component function. /// /// The core function is actually a member of the canon section.
Lower(CanonLower<'a>), /// The core function is defined in terms of aliasing a module instance export. /// /// The core function is actually a member of the core alias section.
Alias(InlineExportAlias<'a, true>),
ResourceNew(CanonResourceNew<'a>),
ResourceDrop(CanonResourceDrop<'a>),
ResourceRep(CanonResourceRep<'a>),
ThreadSpawnRef(CanonThreadSpawnRef<'a>),
ThreadSpawnIndirect(CanonThreadSpawnIndirect<'a>),
ThreadAvailableParallelism(CanonThreadAvailableParallelism),
BackpressureInc,
BackpressureDec,
TaskReturn(CanonTaskReturn<'a>),
TaskCancel,
ContextGet(u32),
ContextSet(u32),
ThreadYield(CanonThreadYield),
SubtaskDrop,
SubtaskCancel(CanonSubtaskCancel),
StreamNew(CanonStreamNew<'a>),
StreamRead(CanonStreamRead<'a>),
StreamWrite(CanonStreamWrite<'a>),
StreamCancelRead(CanonStreamCancelRead<'a>),
StreamCancelWrite(CanonStreamCancelWrite<'a>),
StreamDropReadable(CanonStreamDropReadable<'a>),
StreamDropWritable(CanonStreamDropWritable<'a>),
FutureNew(CanonFutureNew<'a>),
FutureRead(CanonFutureRead<'a>),
FutureWrite(CanonFutureWrite<'a>),
FutureCancelRead(CanonFutureCancelRead<'a>),
FutureCancelWrite(CanonFutureCancelWrite<'a>),
FutureDropReadable(CanonFutureDropReadable<'a>),
FutureDropWritable(CanonFutureDropWritable<'a>),
ErrorContextNew(CanonErrorContextNew<'a>),
ErrorContextDebugMessage(CanonErrorContextDebugMessage<'a>),
ErrorContextDrop,
WaitableSetNew,
WaitableSetWait(CanonWaitableSetWait<'a>),
WaitableSetPoll(CanonWaitableSetPoll<'a>),
WaitableSetDrop,
WaitableJoin,
ThreadIndex,
ThreadNewIndirect(CanonThreadNewIndirect<'a>),
ThreadSwitchTo(CanonThreadSwitchTo),
ThreadSuspend(CanonThreadSuspend),
ThreadResumeLater,
ThreadYieldTo(CanonThreadYieldTo),
}
/// A declared component function. /// /// This may be a member of the import, alias, or canon sections. #[derive(Debug)] pubstruct Func<'a> { /// Where this `func` was defined. pub span: Span, /// An identifier that this function is resolved with (optionally) for name /// resolution. pub id: Option<Id<'a>>, /// An optional name for this function stored in the custom `name` section. pub name: Option<NameAnnotation<'a>>, /// If present, inline export annotations which indicate names this /// definition should be exported under. pub exports: InlineExport<'a>, /// The kind of function. pub kind: FuncKind<'a>,
}
impl<'a> Parse<'a> for Func<'a> { fn parse(parser: Parser<'a>) -> Result<Self> { let span = parser.parse::<kw::func>()?.0; let id = parser.parse()?; let name = parser.parse()?; let exports = parser.parse()?; let kind = parser.parse()?;
Ok(Self {
span,
id,
name,
exports,
kind,
})
}
}
/// Represents the kind of component functions. #[derive(Debug)] pubenum FuncKind<'a> { /// A function which is actually defined as an import, such as: /// /// ```text /// (func (import "foo") (param string)) /// ```
Import { /// The import name of this import.
import: InlineImport<'a>, /// The type that this function will have.
ty: ComponentTypeUse<'a, ComponentFunctionType<'a>>,
}, /// The function is defined in terms of lifting a core function. /// /// The function is actually a member of the canon section.
Lift { /// The lifted function's type.
ty: ComponentTypeUse<'a, ComponentFunctionType<'a>>, /// Information relating to the lifting of the core function.
info: CanonLift<'a>,
}, /// The function is defined in terms of aliasing a component instance export. /// /// The function is actually a member of the alias section.
Alias(InlineExportAlias<'a, false>),
}
/// A WebAssembly canonical function to be inserted into a component. /// /// This is a member of the canonical section. #[derive(Debug)] pubstruct CanonicalFunc<'a> { /// Where this `func` was defined. pub span: Span, /// An identifier that this function is resolved with (optionally) for name /// resolution. pub id: Option<Id<'a>>, /// An optional name for this function stored in the custom `name` section. pub name: Option<NameAnnotation<'a>>, /// What kind of function this is, be it a lowered or lifted function. pub kind: CanonicalFuncKind<'a>,
}
impl<'a> Parse<'a> for CanonicalFunc<'a> { fn parse(parser: Parser<'a>) -> Result<Self> { let span = parser.parse::<kw::canon>()?.0; letmut l = parser.lookahead1();
if l.peek::<kw::lift>()? { let info = parser.parse()?; let (id, name, ty) = parser.parens(|parser| {
parser.parse::<kw::func>()?; let id = parser.parse()?; let name = parser.parse()?; let ty = parser.parse()?;
Ok((id, name, ty))
})?;
Ok(Self {
span,
id,
name,
kind: CanonicalFuncKind::Lift { info, ty },
})
} else { let kind = CoreFuncKind::parse_lookahead(l)?; let (id, name) = parser.parens(|parser| {
parser.parse::<kw::core>()?;
parser.parse::<kw::func>()?; let id = parser.parse()?; let name = parser.parse()?;
Ok((id, name))
})?;
/// Possible ways to define a canonical function in the text format. #[derive(Debug)] #[allow(missing_docs)] pubenum CanonicalFuncKind<'a> { /// A canonical function that is defined in terms of lifting a core function.
Lift { /// The lifted function's type.
ty: ComponentTypeUse<'a, ComponentFunctionType<'a>>, /// Information relating to the lifting of the core function.
info: CanonLift<'a>,
},
/// A canonical function that defines a core function, whose variants are /// delegated to `CoreFuncKind`.
Core(CoreFuncKind<'a>),
}
/// Information relating to lifting a core function. #[derive(Debug)] pubstruct CanonLift<'a> { /// The core function being lifted. pub func: CoreItemRef<'a, kw::func>, /// The canonical options for the lifting. pub opts: Vec<CanonOpt<'a>>,
}
/// Information relating to lowering a component function. #[derive(Debug)] pubstruct CanonLower<'a> { /// The function being lowered. pub func: ItemRef<'a, kw::func>, /// The canonical options for the lowering. pub opts: Vec<CanonOpt<'a>>,
}
/// Information relating to the `resource.new` intrinsic. #[derive(Debug)] pubstruct CanonResourceNew<'a> { /// The resource type that this intrinsic creates an owned reference to. pub ty: Index<'a>,
}
/// Information relating to the `resource.drop` intrinsic. #[derive(Debug)] pubstruct CanonResourceDrop<'a> { /// The resource type that this intrinsic is dropping. pub ty: Index<'a>, /// Whether or not this function is async pub async_: bool,
}
/// Information relating to the `resource.rep` intrinsic. #[derive(Debug)] pubstruct CanonResourceRep<'a> { /// The resource type that this intrinsic is accessing. pub ty: Index<'a>,
}
/// Information relating to the `thread.spawn-ref` intrinsic. #[derive(Debug)] pubstruct CanonThreadSpawnRef<'a> { /// The function type that is being spawned. pub ty: Index<'a>,
}
/// Information relating to the `thread.spawn-indirect` intrinsic. /// /// This should look quite similar to parsing of `CallIndirect`. #[derive(Debug)] pubstruct CanonThreadSpawnIndirect<'a> { /// The function type that is being spawned. pub ty: Index<'a>, /// The table that this spawn is going to be indexing. pub table: CoreItemRef<'a, kw::table>,
}
impl<'a> Parse<'a> for CanonThreadSpawnIndirect<'a> { fn parse(parser: Parser<'a>) -> Result<Self> {
parser.parse::<kw::thread_spawn_indirect>()?; let ty = parser.parse()?; let table = parser.parens(|p| p.parse())?;
Ok(Self { ty, table })
}
}
/// Information relating to the `thread.spawn` intrinsic. #[derive(Debug)] pubstruct CanonThreadAvailableParallelism;
/// Information relating to the `task.return` intrinsic. #[derive(Debug)] pubstruct CanonTaskReturn<'a> { /// The type of the result which may be returned with this intrinsic. pub result: Option<ComponentValType<'a>>, /// The canonical options for storing values. pub opts: Vec<CanonOpt<'a>>,
}
/// Information relating to the `waitable-set.wait` intrinsic. #[derive(Debug)] pubstruct CanonWaitableSetWait<'a> { /// If true, the component instance may be reentered during a call to this /// intrinsic. pub async_: bool, /// The memory to use when returning an event to the caller. pub memory: CoreItemRef<'a, kw::memory>,
}
impl<'a> Parse<'a> for CanonWaitableSetWait<'a> { fn parse(parser: Parser<'a>) -> Result<Self> {
parser.parse::<kw::waitable_set_wait>()?; let async_ = parser.parse::<Option<kw::cancellable>>()?.is_some(); let memory = parser.parens(|p| p.parse())?;
Ok(Self { async_, memory })
}
}
/// Information relating to the `waitable-set.poll` intrinsic. #[derive(Debug)] pubstruct CanonWaitableSetPoll<'a> { /// If true, the component instance may be reentered during a call to this /// intrinsic. pub async_: bool, /// The memory to use when returning an event to the caller. pub memory: CoreItemRef<'a, kw::memory>,
}
impl<'a> Parse<'a> for CanonWaitableSetPoll<'a> { fn parse(parser: Parser<'a>) -> Result<Self> {
parser.parse::<kw::waitable_set_poll>()?; let async_ = parser.parse::<Option<kw::cancellable>>()?.is_some(); let memory = parser.parens(|p| p.parse())?;
Ok(Self { async_, memory })
}
}
/// Information relating to the `thread.yield` intrinsic. #[derive(Debug)] pubstruct CanonThreadYield { /// If true, the component instance may be reentered during a call to this /// intrinsic. pub cancellable: bool,
}
impl<'a> Parse<'a> for CanonThreadYield { fn parse(parser: Parser<'a>) -> Result<Self> {
parser.parse::<kw::thread_yield>()?; let cancellable = parser.parse::<Option<kw::cancellable>>()?.is_some();
Ok(Self { cancellable })
}
}
/// Information relating to the `subtask.cancel` intrinsic. #[derive(Debug)] pubstruct CanonSubtaskCancel { /// If false, block until cancel is finished; otherwise return BLOCKED if /// necessary. pub async_: bool,
}
impl<'a> Parse<'a> for CanonSubtaskCancel { fn parse(parser: Parser<'a>) -> Result<Self> {
parser.parse::<kw::subtask_cancel>()?; let async_ = parser.parse::<Option<kw::r#async>>()?.is_some();
Ok(Self { async_ })
}
}
/// Information relating to the `stream.new` intrinsic. #[derive(Debug)] pubstruct CanonStreamNew<'a> { /// The stream type to instantiate. pub ty: Index<'a>,
}
/// Information relating to the `stream.read` intrinsic. #[derive(Debug)] pubstruct CanonStreamRead<'a> { /// The stream type to instantiate. pub ty: Index<'a>, /// The canonical options for storing values. pub opts: Vec<CanonOpt<'a>>,
}
/// Information relating to the `stream.write` intrinsic. #[derive(Debug)] pubstruct CanonStreamWrite<'a> { /// The stream type to instantiate. pub ty: Index<'a>, /// The canonical options for loading values. pub opts: Vec<CanonOpt<'a>>,
}
/// Information relating to the `stream.cancel-read` intrinsic. #[derive(Debug)] pubstruct CanonStreamCancelRead<'a> { /// The stream type to instantiate. pub ty: Index<'a>, /// If false, block until cancel is finished; otherwise return BLOCKED if /// necessary. pub async_: bool,
}
/// Information relating to the `stream.cancel-write` intrinsic. #[derive(Debug)] pubstruct CanonStreamCancelWrite<'a> { /// The stream type to instantiate. pub ty: Index<'a>, /// If false, block until cancel is finished; otherwise return BLOCKED if /// necessary. pub async_: bool,
}
/// Information relating to the `stream.drop-readable` intrinsic. #[derive(Debug)] pubstruct CanonStreamDropReadable<'a> { /// The stream type to drop. pub ty: Index<'a>,
}
/// Information relating to the `stream.drop-writable` intrinsic. #[derive(Debug)] pubstruct CanonStreamDropWritable<'a> { /// The stream type to drop. pub ty: Index<'a>,
}
/// Information relating to the `future.new` intrinsic. #[derive(Debug)] pubstruct CanonFutureNew<'a> { /// The future type to instantiate. pub ty: Index<'a>,
}
/// Information relating to the `future.read` intrinsic. #[derive(Debug)] pubstruct CanonFutureRead<'a> { /// The future type to instantiate. pub ty: Index<'a>, /// The canonical options for storing values. pub opts: Vec<CanonOpt<'a>>,
}
/// Information relating to the `future.write` intrinsic. #[derive(Debug)] pubstruct CanonFutureWrite<'a> { /// The future type to instantiate. pub ty: Index<'a>, /// The canonical options for loading values. pub opts: Vec<CanonOpt<'a>>,
}
/// Information relating to the `future.cancel-read` intrinsic. #[derive(Debug)] pubstruct CanonFutureCancelRead<'a> { /// The future type to instantiate. pub ty: Index<'a>, /// If false, block until cancel is finished; otherwise return BLOCKED if /// necessary. pub async_: bool,
}
/// Information relating to the `future.cancel-write` intrinsic. #[derive(Debug)] pubstruct CanonFutureCancelWrite<'a> { /// The future type to instantiate. pub ty: Index<'a>, /// If false, block until cancel is finished; otherwise return BLOCKED if /// necessary. pub async_: bool,
}
/// Information relating to the `future.drop-readable` intrinsic. #[derive(Debug)] pubstruct CanonFutureDropReadable<'a> { /// The future type to drop. pub ty: Index<'a>,
}
/// Information relating to the `future.drop-writable` intrinsic. #[derive(Debug)] pubstruct CanonFutureDropWritable<'a> { /// The future type to drop. pub ty: Index<'a>,
}
/// Information relating to the `error-context.new` intrinsic. #[derive(Debug)] pubstruct CanonErrorContextNew<'a> { /// The canonical options for loading the debug message. pub opts: Vec<CanonOpt<'a>>,
}
/// Information relating to the `error-context.debug-message` intrinsic. #[derive(Debug)] pubstruct CanonErrorContextDebugMessage<'a> { /// The canonical options for storing the debug message. pub opts: Vec<CanonOpt<'a>>,
}
/// Information relating to the `thread.new-indirect` intrinsic. #[derive(Debug)] pubstruct CanonThreadNewIndirect<'a> { /// The function type for the thread start function. pub ty: Index<'a>, /// The table to index. pub table: CoreItemRef<'a, kw::table>,
}
impl<'a> Parse<'a> for CanonThreadNewIndirect<'a> { fn parse(parser: Parser<'a>) -> Result<Self> {
parser.parse::<kw::thread_new_indirect>()?; let ty = parser.parse()?; let table = parser.parens(|p| p.parse())?;
Ok(Self { ty, table })
}
}
/// Information relating to the `thread.switch-to` intrinsic. #[derive(Debug)] pubstruct CanonThreadSwitchTo { /// Whether the thread can be cancelled while suspended at this point. pub cancellable: bool,
}
/// Information relating to the `thread.suspend` intrinsic. #[derive(Debug)] pubstruct CanonThreadSuspend { /// Whether the thread can be cancelled while suspended at this point. pub cancellable: bool,
} impl<'a> Parse<'a> for CanonThreadSuspend { fn parse(parser: Parser<'a>) -> Result<Self> {
parser.parse::<kw::thread_suspend>()?; let cancellable = parser.parse::<Option<kw::cancellable>>()?.is_some();
Ok(Self { cancellable })
}
}
/// Information relating to the `thread.yield-to` intrinsic. #[derive(Debug)] pubstruct CanonThreadYieldTo { /// Whether the thread can be cancelled while yielding at this point. pub cancellable: bool,
} impl<'a> Parse<'a> for CanonThreadYieldTo { fn parse(parser: Parser<'a>) -> Result<Self> {
parser.parse::<kw::thread_yield_to>()?; let cancellable = parser.parse::<Option<kw::cancellable>>()?.is_some();
Ok(Self { cancellable })
}
}
#[derive(Debug)] /// Canonical ABI options. pubenum CanonOpt<'a> { /// Encode strings as UTF-8.
StringUtf8, /// Encode strings as UTF-16.
StringUtf16, /// Encode strings as "compact UTF-16".
StringLatin1Utf16, /// Use the specified memory for canonical ABI memory access.
Memory(CoreItemRef<'a, kw::memory>), /// Use the specified reallocation function for memory allocations.
Realloc(CoreItemRef<'a, kw::func>), /// Call the specified function after the lifted function has returned.
PostReturn(CoreItemRef<'a, kw::func>), /// Use the async ABI for lifting or lowering. Async, /// Use the specified function to deliver async events to stackless coroutines.
Callback(CoreItemRef<'a, kw::func>), /// Lower this component function into the specified core function type.
CoreType(CoreItemRef<'a, kw::r#type>), /// Use the GC variant of the canonical ABI.
Gc,
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.