use Rc in ast types

This commit is contained in:
vms 2020-11-04 23:26:33 +03:00
parent 748d00e2e7
commit fe4206afc6
7 changed files with 17 additions and 14 deletions

2
Cargo.lock generated
View File

@ -161,7 +161,7 @@ checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "wasmer-interface-types-fl"
version = "0.17.11"
version = "0.17.12"
dependencies = [
"log",
"nom",

View File

@ -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 <engineering@wasmer.io>"]
@ -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"

View File

@ -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<FunctionArg>,
arguments: Rc<Vec<FunctionArg>>,
/// Types for the results (`(result …)`).
output_types: Vec<InterfaceType>,
output_types: Rc<Vec<InterfaceType>>,
},
/// A record type, like:
@ -51,7 +52,7 @@ pub enum Type {
/// ```wasm,ignore
/// (@interface type (record string i32))
/// ```
Record(RecordType),
Record(Rc<RecordType>),
}
/// Represents an imported function.

View File

@ -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)));
}
}
}

View File

@ -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::<keyword::record>() {
Ok(Type::Record(parser.parse()?))
Ok(Type::Record(Rc::new(parser.parse()?)))
} else {
Err(lookahead.error())
}

View File

@ -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(),
),
}
}

View File

@ -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;