// Copyright 2022 the Gigamono authors. All rights reserved. GPL-3.0 License. use serde::{Deserialize, Serialize}; /// WebAssembly function type as defined in the spec. /// /// https://webassembly.github.io/spec/core/syntax/types.html#syntax-functype #[derive(Debug, Serialize, Deserialize)] pub struct FuncType { pub params: Vec, pub returns: Vec, } /// WebAssembly value types as defined in the spec. /// /// https://webassembly.github.io/spec/core/syntax/types.html#syntax-valtype #[derive(Debug, Serialize, Deserialize)] pub enum ValType { NumType(NumType), // i32, i64, f32, f64 RefType(RefType), // funcref, externref VecType, // v128 } /// WebAssembly num types as defined in the spec. /// /// https://webassembly.github.io/spec/core/syntax/types.html#syntax-numtype #[derive(Debug, Serialize, Deserialize)] pub enum NumType { I32, I64, F32, F64, } /// WebAssembly num types as defined in the spec. /// /// https://webassembly.github.io/spec/core/syntax/types.html#syntax-reftype #[derive(Debug, Serialize, Deserialize)] pub enum RefType { FuncRef, ExternRef, } /// WebAssembly limits almost as defined in the spec. /// /// A slight deviation from the current spec. Wasmo uses 64-bit types as there will be support for memory64 in the future. /// /// https://webassembly.github.io/spec/core/syntax/types.html#syntax-limits #[derive(Debug, Serialize, Deserialize, Default)] pub struct Limits { /// Intial page count. pub min: u64, /// Maximum page count. pub max: Option, } /// Webassembly memory and table page size. /// 64KiB. pub const _PAGE_SIZE: u32 = 65536; impl Limits { pub fn new(min: u64, max: Option) -> Self { Self { min, max } } }