diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2024-01-22 01:15:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-22 01:15:28 +0100 |
| commit | 0b2bd6c33d086b52952206efa03aead00021bb4a (patch) | |
| tree | 513883b826731696643a164a0c1deb14e8141aca /crates/types | |
| parent | 7b456a58f70c0a1dbaf289d285b14a6b139495f7 (diff) | |
| parent | c0dd4bc48f703b46f6e0f683c10c015c92f46bba (diff) | |
Merge pull request #1 from explodingcamera/imports
feat: host functions, rewrite linker
Diffstat (limited to 'crates/types')
| -rw-r--r-- | crates/types/src/lib.rs | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 069f134..965c97e 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -2,10 +2,7 @@ #![forbid(unsafe_code)] #![doc(test( no_crate_inject, - attr( - deny(warnings, rust_2018_idioms), - allow(dead_code, unused_assignments, unused_variables) - ) + attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_assignments, unused_variables)) ))] #![warn(missing_debug_implementations, rust_2018_idioms, unreachable_pub)] @@ -28,7 +25,7 @@ extern crate alloc; mod instructions; use core::{fmt::Debug, ops::Range}; -use alloc::{boxed::Box, sync::Arc, vec::Vec}; +use alloc::boxed::Box; pub use instructions::*; /// A TinyWasm WebAssembly Module @@ -306,7 +303,7 @@ pub type ModuleInstanceAddr = Addr; /// A WebAssembly External Value. /// /// See <https://webassembly.github.io/spec/core/exec/runtime.html#external-values> -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum ExternVal { Func(FuncAddr), Table(TableAddr), @@ -314,6 +311,26 @@ pub enum ExternVal { Global(GlobalAddr), } +impl ExternVal { + pub fn kind(&self) -> ExternalKind { + match self { + Self::Func(_) => ExternalKind::Func, + Self::Table(_) => ExternalKind::Table, + Self::Mem(_) => ExternalKind::Memory, + Self::Global(_) => ExternalKind::Global, + } + } + + pub fn new(kind: ExternalKind, addr: Addr) -> Self { + match kind { + ExternalKind::Func => Self::Func(addr), + ExternalKind::Table => Self::Table(addr), + ExternalKind::Memory => Self::Mem(addr), + ExternalKind::Global => Self::Global(addr), + } + } +} + /// The type of a WebAssembly Function. /// /// See <https://webassembly.github.io/spec/core/syntax/types.html#function-types> @@ -326,10 +343,7 @@ pub struct FuncType { impl FuncType { /// Get the number of parameters of a function type. pub fn empty() -> Self { - Self { - params: Box::new([]), - results: Box::new([]), - } + Self { params: Box::new([]), results: Box::new([]) } } } @@ -372,19 +386,11 @@ pub struct TableType { impl TableType { pub fn empty() -> Self { - Self { - element_type: ValType::FuncRef, - size_initial: 0, - size_max: None, - } + Self { element_type: ValType::FuncRef, size_initial: 0, size_max: None } } pub fn new(element_type: ValType, size_initial: u32, size_max: Option<u32>) -> Self { - Self { - element_type, - size_initial, - size_max, - } + Self { element_type, size_initial, size_max } } } @@ -400,11 +406,7 @@ pub struct MemoryType { impl MemoryType { pub fn new_32(page_count_initial: u64, page_count_max: Option<u64>) -> Self { - Self { - arch: MemoryArch::I32, - page_count_initial, - page_count_max, - } + Self { arch: MemoryArch::I32, page_count_initial, page_count_max } } // pub fn new_64(page_count_initial: u64, page_count_max: Option<u64>) -> Self { |
