diff --git a/Cargo.lock b/Cargo.lock index e12258b..33886c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,7 +161,7 @@ checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] name = "wasmer-interface-types-fl" -version = "0.17.11" +version = "0.17.12" dependencies = [ "log", "nom", diff --git a/Cargo.toml b/Cargo.toml index aada5ce..8e87ae1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wasmer-interface-types-fl" -version = "0.17.11" +version = "0.17.12" description = "WebAssembly Interface Types library for Wasmer" license = "MIT" authors = ["The Wasmer Engineering Team "] @@ -14,7 +14,7 @@ wast = "8.0" # `serde` is useful only to simplify the users' life. It is not # required by WIT itself, is is used to cross the boundary between the # host and WIT more easily, but it is not used inside Wasm. -serde = { version = "1.0", features = ["derive"], optional = true } +serde = { version = "1.0", features = ["derive", "rc"], optional = true } serde_json = "1.0" safe-transmute = "0.11.0" log = "0.4.11" diff --git a/src/ast.rs b/src/ast.rs index 1d28ec9..1e6415a 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -8,6 +8,7 @@ use crate::{ use serde::Deserialize; use serde::Serialize; +use std::rc::Rc; use std::str; /// Represents the kind of type. @@ -40,10 +41,10 @@ pub enum Type { /// ``` Function { /// Types for the parameters (`(param (name i32))`). - arguments: Vec, + arguments: Rc>, /// Types for the results (`(result …)`). - output_types: Vec, + output_types: Rc>, }, /// A record type, like: @@ -51,7 +52,7 @@ pub enum Type { /// ```wasm,ignore /// (@interface type (record string i32)) /// ``` - Record(RecordType), + Record(Rc), } /// Represents an imported function. diff --git a/src/decoders/binary.rs b/src/decoders/binary.rs index 914268e..f28929a 100644 --- a/src/decoders/binary.rs +++ b/src/decoders/binary.rs @@ -5,6 +5,7 @@ use nom::{ error::{make_error, ErrorKind, ParseError}, Err, IResult, }; +use std::rc::Rc; use std::{convert::TryFrom, str}; /// Parse a type kind. @@ -375,15 +376,15 @@ fn types<'input, E: ParseError<&'input [u8]>>( consume!((input, output_types) = list(input, ty)?); types.push(Type::Function { - arguments, - output_types, + arguments: Rc::new(arguments), + output_types: Rc::new(output_types), }); } TypeKind::Record => { consume!((input, record_type) = record_type(input)?); - types.push(Type::Record(record_type)); + types.push(Type::Record(Rc::new(record_type))); } } } diff --git a/src/decoders/wat.rs b/src/decoders/wat.rs index c2a130d..abe8dcf 100644 --- a/src/decoders/wat.rs +++ b/src/decoders/wat.rs @@ -1,6 +1,7 @@ //! Parse the WIT textual representation into an [AST](crate::ast). use crate::{ast::*, interpreter::Instruction, types::*, vec1::Vec1}; +use std::rc::Rc; pub use wast::parser::ParseBuffer as Buffer; use wast::parser::{self, Cursor, Parse, Parser, Peek, Result}; pub use wast::Error; @@ -552,11 +553,11 @@ impl<'a> Parse<'a> for Type { } Ok(Type::Function { - arguments, - output_types, + arguments: Rc::new(arguments), + output_types: Rc::new(output_types), }) } else if lookahead.peek::() { - Ok(Type::Record(parser.parse()?)) + Ok(Type::Record(Rc::new(parser.parse()?))) } else { Err(lookahead.error()) } diff --git a/src/encoders/wat.rs b/src/encoders/wat.rs index c7e3bd5..91ac722 100644 --- a/src/encoders/wat.rs +++ b/src/encoders/wat.rs @@ -224,7 +224,7 @@ impl<'input> ToString for &Type { Type::Record(record_type) => format!( r#"(@interface type ({record_type}))"#, - record_type = record_type.to_string(), + record_type = record_type.as_ref().to_string(), ), } } diff --git a/src/interpreter/wasm/structures.rs b/src/interpreter/wasm/structures.rs index d25d5ac..0db3ab2 100644 --- a/src/interpreter/wasm/structures.rs +++ b/src/interpreter/wasm/structures.rs @@ -3,8 +3,8 @@ use crate::ast::FunctionArg; use crate::types::RecordType; use crate::{types::InterfaceType, values::InterfaceValue}; -use std::{cell::Cell, ops::Deref}; use std::rc::Rc; +use std::{cell::Cell, ops::Deref}; pub trait TypedIndex: Copy + Clone { fn new(index: usize) -> Self;