nyar_wasm/helpers/
mod.rs

1use dependent_sort::Task;
2use std::fmt::Write;
3
4use crate::{encoder::WastEncoder, DependentGraph, WasiModule, WasiType, WasiValue};
5
6pub trait ToWasiType {
7    fn to_wasi_type(&self) -> WasiType;
8}
9
10pub trait ToWasiValue {
11    fn to_wasi_value(&self) -> WasiValue;
12}
13
14pub(crate) trait ComponentSections {
15    /// Top level definition for the wasi component
16    fn wasi_define<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
17    /// Mark for type who can import to the component instance
18    fn alias_outer<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
19    fn alias_export<W: Write>(&self, w: &mut WastEncoder<W>, module: &WasiModule) -> std::fmt::Result;
20    /// from `wasi` to `wasm`
21    fn canon_lower<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
22    /// Inner definition for the wasm module
23    fn wasm_define<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
24}
25
26pub(crate) trait GroupedTask {
27    fn dependent_task<'a, 'b>(&'a self, graph: &'b DependentGraph) -> Option<Task<WasiType, WasiModule>>
28    where
29        'b: 'a;
30}
31
32pub(crate) trait DependenciesTrace {
33    fn define_language_types(&self, dict: &mut DependentGraph);
34    fn collect_wasi_types<'a, 'i>(&'a self, dict: &'i DependentGraph, collected: &mut Vec<&'i WasiType>)
35    where
36        'a: 'i;
37}
38
39pub(crate) trait TypeReference {
40    fn upper_type<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
41    fn lower_type<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
42    fn lower_type_inner<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
43}
44
45pub(crate) trait TypeReferenceInput {
46    fn upper_input<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
47    fn lower_input<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
48}
49
50pub(crate) trait TypeReferenceOutput {
51    fn upper_output<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
52    fn lower_output<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
53}
54
55pub(crate) trait EmitDefault {
56    /// Emit default instruction for the value
57    fn emit_default<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
58}
59
60pub(crate) trait EmitConstant {
61    /// Emit constant instruction for the value
62    fn emit_constant<W: Write>(&self, w: &mut WastEncoder<W>) -> std::fmt::Result;
63}