Merge branch 'master' into feature/dynasm-backend

This commit is contained in:
Brandon Fish
2019-03-12 20:58:22 -05:00
358 changed files with 13992 additions and 1805 deletions

View File

@ -53,10 +53,7 @@ impl AnyfuncTable {
desc: TableDescriptor,
local: &mut vm::LocalTable,
) -> Result<Box<Self>, CreationError> {
let initial_table_backing_len = match desc.maximum {
Some(max) => max,
None => desc.minimum,
} as usize;
let initial_table_backing_len = desc.minimum as usize;
let mut storage = Box::new(AnyfuncTable {
backing: vec![vm::Anyfunc::null(); initial_table_backing_len],

View File

@ -11,6 +11,7 @@ mod anyfunc;
pub use self::anyfunc::Anyfunc;
use self::anyfunc::AnyfuncTable;
use crate::error::GrowError;
pub enum Element<'a> {
Anyfunc(Anyfunc<'a>),
@ -50,6 +51,14 @@ impl Table {
/// # }
/// ```
pub fn new(desc: TableDescriptor) -> Result<Self, CreationError> {
if let Some(max) = desc.maximum {
if max < desc.minimum {
return Err(CreationError::InvalidDescriptor(
"Max table size is less than the minimum size".to_string(),
));
}
}
let mut local = vm::LocalTable {
base: ptr::null_mut(),
count: 0,
@ -100,15 +109,15 @@ impl Table {
}
/// Grow this table by `delta`.
pub fn grow(&self, delta: u32) -> Option<u32> {
pub fn grow(&self, delta: u32) -> Result<u32, GrowError> {
if delta == 0 {
return Some(self.size());
return Ok(self.size());
}
match &mut *self.storage.borrow_mut() {
(TableStorage::Anyfunc(ref mut anyfunc_table), ref mut local) => {
anyfunc_table.grow(delta, local)
}
(TableStorage::Anyfunc(ref mut anyfunc_table), ref mut local) => anyfunc_table
.grow(delta, local)
.ok_or(GrowError::TableGrowError),
}
}
@ -140,3 +149,21 @@ impl fmt::Debug for Table {
.finish()
}
}
#[cfg(test)]
mod table_tests {
use super::{ElementType, Table, TableDescriptor};
#[test]
fn test_initial_table_size() {
let table = Table::new(TableDescriptor {
element: ElementType::Anyfunc,
minimum: 10,
maximum: Some(20),
})
.unwrap();
assert_eq!(table.size(), 10);
}
}