summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorHenry Gressmann <mail@henrygressmann.de>2024-01-22 01:05:35 +0100
committerHenry Gressmann <mail@henrygressmann.de>2024-01-22 01:05:35 +0100
commit49a4bf2a3a40f56a86928a2847e32b21e800d263 (patch)
tree02e2f704cbd8484eb56a105ca5edbd55bb454f85 /crates
parent1eb6f3160a5c6036926bd3db757d2ff3ca4b1a53 (diff)
host function calls, fix call isolation issues
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates')
-rw-r--r--crates/tinywasm/src/func.rs21
-rw-r--r--crates/tinywasm/src/imports.rs12
-rw-r--r--crates/tinywasm/src/instance.rs36
-rw-r--r--crates/tinywasm/src/runtime/executor/macros.rs7
-rw-r--r--crates/tinywasm/src/runtime/executor/mod.rs29
-rw-r--r--crates/tinywasm/src/runtime/stack/value_stack.rs31
-rw-r--r--crates/tinywasm/src/store.rs201
-rw-r--r--crates/tinywasm/tests/generated/mvp.csv2
-rw-r--r--crates/tinywasm/tests/generated/progress-mvp.svg6
9 files changed, 202 insertions, 143 deletions
diff --git a/crates/tinywasm/src/func.rs b/crates/tinywasm/src/func.rs
index 74043a9..0a65e02 100644
--- a/crates/tinywasm/src/func.rs
+++ b/crates/tinywasm/src/func.rs
@@ -52,7 +52,13 @@ impl FuncHandle {
}
}
- let wasm_func = &func_inst.assert_wasm()?;
+ let wasm_func = match &func_inst.func {
+ crate::Function::Host(h) => {
+ let func = h.func.clone();
+ return (func)(store, params);
+ }
+ crate::Function::Wasm(ref f) => f,
+ };
// 6. Let f be the dummy frame
debug!("locals: {:?}", wasm_func.locals);
@@ -76,11 +82,7 @@ impl FuncHandle {
let res = stack.values.last_n(result_m)?;
// The values are returned as the results of the invocation.
- Ok(res
- .iter()
- .zip(func_ty.results.iter())
- .map(|(v, ty)| v.attach_type(*ty))
- .collect())
+ Ok(res.iter().zip(func_ty.results.iter()).map(|(v, ty)| v.attach_type(*ty)).collect())
}
}
@@ -184,11 +186,8 @@ macro_rules! impl_from_wasm_value_tuple_single {
fn from_wasm_value_tuple(values: Vec<WasmValue>) -> Result<Self> {
#[allow(unused_variables, unused_mut)]
let mut iter = values.into_iter();
- Ok($T::try_from(
- iter.next()
- .ok_or(Error::Other("Not enough values in WasmValue vector".to_string()))?,
- )
- .map_err(|_| Error::Other("Could not convert WasmValue to expected type".to_string()))?)
+ Ok($T::try_from(iter.next().ok_or(Error::Other("Not enough values in WasmValue vector".to_string()))?)
+ .map_err(|_| Error::Other("Could not convert WasmValue to expected type".to_string()))?)
}
}
};
diff --git a/crates/tinywasm/src/imports.rs b/crates/tinywasm/src/imports.rs
index f89ba64..e17f866 100644
--- a/crates/tinywasm/src/imports.rs
+++ b/crates/tinywasm/src/imports.rs
@@ -12,7 +12,7 @@ use alloc::{
};
use tinywasm_types::{
Addr, Export, ExternVal, ExternalKind, FuncAddr, GlobalAddr, GlobalType, Import, MemAddr, MemoryType,
- ModuleInstanceAddr, TableAddr, TableType, WasmFunction, WasmValue,
+ ModuleInstanceAddr, TableAddr, TableType, TypeAddr, WasmFunction, WasmValue,
};
/// The internal representation of a function
@@ -25,6 +25,16 @@ pub enum Function {
Wasm(WasmFunction),
}
+impl Function {
+ /// Get the function's type
+ pub fn ty(&self, module: &crate::ModuleInstance) -> tinywasm_types::FuncType {
+ match self {
+ Self::Host(f) => f.ty.clone(),
+ Self::Wasm(f) => module.func_ty(f.ty_addr).clone(),
+ }
+ }
+}
+
/// A host function
#[derive(Clone)]
pub struct HostFunction {
diff --git a/crates/tinywasm/src/instance.rs b/crates/tinywasm/src/instance.rs
index 92db518..9ad1cfd 100644
--- a/crates/tinywasm/src/instance.rs
+++ b/crates/tinywasm/src/instance.rs
@@ -59,10 +59,17 @@ impl ModuleInstance {
addrs.globals.extend(store.init_globals(data.globals.into(), idx)?);
addrs.funcs.extend(store.init_funcs(data.funcs.into(), idx)?);
addrs.tables.extend(store.init_tables(data.table_types.into(), idx)?);
+
+ log::info!("init_mems: {:?}", addrs.mems);
addrs.mems.extend(store.init_mems(data.memory_types.into(), idx)?);
+ log::info!("init_mems2: {:?}", addrs.mems);
+ log::info!("init_mems g: {:?}", store.data.mems.len());
+
+ let elem_addrs = store.init_elems(&addrs.tables, data.elements.into(), idx)?;
+ log::info!("init_elems: {:?}", addrs.mems);
- let elem_addrs = store.add_elems(data.elements.into(), idx)?;
- let data_addrs = store.add_datas(data.data.into(), idx)?;
+ let data_addrs = store.init_datas(&addrs.mems, data.data.into(), idx)?;
+ log::info!("init_datas: {:?}", addrs.mems);
let instance = ModuleInstanceInner {
store_id: store.id(),
@@ -119,26 +126,22 @@ impl ModuleInstance {
}
pub(crate) fn func_ty(&self, addr: FuncAddr) -> &FuncType {
- &self.0.types[addr as usize]
+ &self.0.types.get(addr as usize).expect("No func type for func, this is a bug")
}
// resolve a function address to the global store address
pub(crate) fn resolve_func_addr(&self, addr: FuncAddr) -> FuncAddr {
- self.0.func_addrs[addr as usize]
+ *self.0.func_addrs.get(addr as usize).expect("No func addr for func, this is a bug")
}
// resolve a table address to the global store address
pub(crate) fn resolve_table_addr(&self, addr: TableAddr) -> TableAddr {
- self.0.table_addrs[addr as usize]
- }
-
- pub(crate) fn resolve_elem_addr(&self, addr: ElemAddr) -> ElemAddr {
- self.0.elem_addrs[addr as usize]
+ *self.0.table_addrs.get(addr as usize).expect("No table addr for table, this is a bug")
}
// resolve a memory address to the global store address
pub(crate) fn resolve_mem_addr(&self, addr: MemAddr) -> MemAddr {
- self.0.mem_addrs[addr as usize]
+ *self.0.mem_addrs.get(addr as usize).expect("No mem addr for mem, this is a bug")
}
// resolve a global address to the global store address
@@ -158,15 +161,9 @@ impl ModuleInstance {
};
let func_inst = store.get_func(func_addr as usize)?;
- let func = func_inst.assert_wasm()?;
- let ty = self
- .0
- .types
- .get(func.ty_addr as usize)
- .ok_or_else(|| Error::Other(format!("Invalid function type address: {}", func.ty_addr)))?
- .clone();
+ let ty = func_inst.func.ty(&self);
- Ok(FuncHandle { addr: func_addr, module: self.clone(), name: Some(name.to_string()), ty })
+ Ok(FuncHandle { addr: func_addr, module: self.clone(), name: Some(name.to_string()), ty: ty.clone() })
}
/// Get a typed exported function by name
@@ -206,8 +203,7 @@ impl ModuleInstance {
let func_addr = self.0.func_addrs.get(func_index as usize).expect("No func addr for start func, this is a bug");
let func_inst = store.get_func(*func_addr as usize)?;
- let func = func_inst.assert_wasm()?;
- let ty = self.0.types[func.ty_addr as usize].clone();
+ let ty = func_inst.func.ty(&self);
Ok(Some(FuncHandle { module: self.clone(), addr: *func_addr, ty, name: None }))
}
diff --git a/crates/tinywasm/src/runtime/executor/macros.rs b/crates/tinywasm/src/runtime/executor/macros.rs
index c1bb50f..5b20851 100644
--- a/crates/tinywasm/src/runtime/executor/macros.rs
+++ b/crates/tinywasm/src/runtime/executor/macros.rs
@@ -63,8 +63,7 @@ macro_rules! mem_store {
let val = val as $store_type;
let val = val.to_le_bytes();
- mem.borrow_mut()
- .store(($arg.offset + addr) as usize, $arg.align as usize, &val)?;
+ mem.borrow_mut().store(($arg.offset + addr) as usize, $arg.align as usize, &val)?;
}};
}
@@ -225,9 +224,7 @@ macro_rules! checked_int_arithmetic {
return Err(Error::Trap(crate::Trap::DivisionByZero));
}
- let result = a_casted
- .$op(b_casted)
- .ok_or_else(|| Error::Trap(crate::Trap::IntegerOverflow))?;
+ let result = a_casted.$op(b_casted).ok_or_else(|| Error::Trap(crate::Trap::IntegerOverflow))?;
// Cast back to original type if different
$stack.values.push((result as $from).into());
diff --git a/crates/tinywasm/src/runtime/executor/mod.rs b/crates/tinywasm/src/runtime/executor/mod.rs
index 62f17e7..1072577 100644
--- a/crates/tinywasm/src/runtime/executor/mod.rs
+++ b/crates/tinywasm/src/runtime/executor/mod.rs
@@ -25,7 +25,7 @@ impl DefaultRuntime {
// The function to execute, gets updated from ExecResult::Call
let mut func_inst = store.get_func(cf.func_ptr)?.clone();
- let mut wasm_func = func_inst.assert_wasm()?;
+ let mut wasm_func = func_inst.assert_wasm().expect("exec expected wasm function");
let mut instrs = &wasm_func.instructions;
// TODO: we might be able to index into the instructions directly
@@ -36,7 +36,7 @@ impl DefaultRuntime {
ExecResult::Call => {
cf = stack.call_stack.pop()?;
func_inst = store.get_func(cf.func_ptr)?.clone();
- wasm_func = func_inst.assert_wasm()?;
+ wasm_func = func_inst.assert_wasm().expect("call expected wasm function");
instrs = &wasm_func.instructions;
continue;
}
@@ -128,14 +128,24 @@ fn exec_one(
// prepare the call frame
let func_idx = module.resolve_func_addr(*v);
let func_inst = store.get_func(func_idx as usize)?;
- let func = func_inst.assert_wasm()?;
+ let func = match &func_inst.func {
+ crate::Function::Wasm(ref f) => f,
+ crate::Function::Host(host_func) => {
+ let func = host_func.func.clone();
+ let params = stack.values.pop_params(&host_func.ty.params)?;
+ let res = (func)(store, &params)?;
+ stack.values.extend_from_typed(&res);
+ return Ok(ExecResult::Ok);
+ }
+ };
+
let func_ty = module.func_ty(func.ty_addr);
debug!("params: {:?}", func_ty.params);
debug!("stack: {:?}", stack.values);
let params = stack.values.pop_n(func_ty.params.len())?;
- let call_frame = CallFrame::new_raw(*v as usize, &params, func.locals.to_vec());
+ let call_frame = CallFrame::new_raw(func_idx as usize, &params, func.locals.to_vec());
// push the call frame
cf.instr_ptr += 1; // skip the call instruction
@@ -157,7 +167,16 @@ fn exec_one(
// prepare the call frame
let func_inst = store.get_func(func_addr as usize)?;
- let func = func_inst.assert_wasm()?;
+ let func = match &func_inst.func {
+ crate::Function::Wasm(ref f) => f,
+ crate::Function::Host(host_func) => {
+ let func = host_func.func.clone();
+ let params = stack.values.pop_params(&host_func.ty.params)?;
+ let res = (func)(store, &params)?;
+ stack.values.extend_from_typed(&res);
+ return Ok(ExecResult::Ok);
+ }
+ };
let func_ty = module.func_ty(func.ty_addr);
if func_ty != call_ty {
diff --git a/crates/tinywasm/src/runtime/stack/value_stack.rs b/crates/tinywasm/src/runtime/stack/value_stack.rs
index 10054bc..1021289 100644
--- a/crates/tinywasm/src/runtime/stack/value_stack.rs
+++ b/crates/tinywasm/src/runtime/stack/value_stack.rs
@@ -2,6 +2,7 @@ use core::ops::Range;
use crate::{runtime::RawWasmValue, Error, Result};
use alloc::vec::Vec;
+use tinywasm_types::{ValType, WasmValue};
// minimum stack size
pub(crate) const STACK_SIZE: usize = 1024;
@@ -16,10 +17,7 @@ pub(crate) struct ValueStack {
impl Default for ValueStack {
fn default() -> Self {
- Self {
- stack: Vec::with_capacity(STACK_SIZE),
- top: 0,
- }
+ Self { stack: Vec::with_capacity(STACK_SIZE), top: 0 }
}
}
@@ -31,6 +29,12 @@ impl ValueStack {
}
#[inline]
+ pub(crate) fn extend_from_typed(&mut self, values: &[WasmValue]) {
+ self.top += values.len();
+ self.stack.extend(values.iter().map(|v| RawWasmValue::from(*v)));
+ }
+
+ #[inline]
pub(crate) fn len(&self) -> usize {
assert!(self.top <= self.stack.len());
self.top
@@ -38,10 +42,7 @@ impl ValueStack {
pub(crate) fn truncate_keep(&mut self, n: usize, end_keep: usize) {
let total_to_keep = n + end_keep;
- assert!(
- self.top >= total_to_keep,
- "Total to keep should be less than or equal to self.top"
- );
+ assert!(self.top >= total_to_keep, "Total to keep should be less than or equal to self.top");
let current_size = self.stack.len();
if current_size <= total_to_keep {
@@ -79,9 +80,19 @@ impl ValueStack {
self.stack.pop().ok_or(Error::StackUnderflow)
}
+ #[inline]
+ pub(crate) fn pop_params(&mut self, types: &[ValType]) -> Result<Vec<WasmValue>> {
+ let n = types.len();
+ if self.top < n {
+ return Err(Error::StackUnderflow);
+ }
+ self.top -= n;
+ let res = self.stack.drain(self.top..).rev().map(|v| v.attach_type(types[n - 1])).collect();
+ Ok(res)
+ }
+
pub(crate) fn break_to(&mut self, new_stack_size: usize, result_count: usize) {
- self.stack
- .copy_within((self.top - result_count)..self.top, new_stack_size);
+ self.stack.copy_within((self.top - result_count)..self.top, new_stack_size);
self.top = new_stack_size + result_count;
self.stack.truncate(self.top);
}
diff --git a/crates/tinywasm/src/store.rs b/crates/tinywasm/src/store.rs
index 426ca78..e7fc7b1 100644
--- a/crates/tinywasm/src/store.rs
+++ b/crates/tinywasm/src/store.rs
@@ -106,8 +106,8 @@ impl Store {
self.module_instance_count as ModuleInstanceAddr
}
- /// Initialize the store with global state from the given module
pub(crate) fn add_instance(&mut self, instance: ModuleInstance) -> Result<()> {
+ assert!(instance.id() == self.module_instance_count as ModuleInstanceAddr);
self.module_instances.push(instance);
self.module_instance_count += 1;
Ok(())
@@ -117,8 +117,9 @@ impl Store {
pub(crate) fn init_funcs(&mut self, funcs: Vec<WasmFunction>, idx: ModuleInstanceAddr) -> Result<Vec<FuncAddr>> {
let func_count = self.data.funcs.len();
let mut func_addrs = Vec::with_capacity(func_count);
- for func in funcs.into_iter() {
- func_addrs.push(self.add_func(Function::Wasm(func), idx)?);
+ for (i, func) in funcs.into_iter().enumerate() {
+ self.data.funcs.push(Rc::new(FunctionInstance { func: Function::Wasm(func), owner: idx }));
+ func_addrs.push((i + func_count) as FuncAddr);
}
Ok(func_addrs)
}
@@ -128,7 +129,8 @@ impl Store {
let table_count = self.data.tables.len();
let mut table_addrs = Vec::with_capacity(table_count);
for (i, table) in tables.into_iter().enumerate() {
- table_addrs.push(self.add_table(table, idx)?);
+ self.data.tables.push(Rc::new(RefCell::new(TableInstance::new(table, idx))));
+ table_addrs.push((i + table_count) as TableAddr);
}
Ok(table_addrs)
}
@@ -138,7 +140,13 @@ impl Store {
let mem_count = self.data.mems.len();
let mut mem_addrs = Vec::with_capacity(mem_count);
for (i, mem) in mems.into_iter().enumerate() {
- mem_addrs.push(self.add_mem(mem, idx)?);
+ if let MemoryArch::I64 = mem.arch {
+ return Err(Error::UnsupportedFeature("64-bit memories".to_string()));
+ }
+ log::info!("adding memory: {:?}", mem);
+ self.data.mems.push(Rc::new(RefCell::new(MemoryInstance::new(mem, idx))));
+
+ mem_addrs.push((i + mem_count) as MemAddr);
}
Ok(mem_addrs)
}
@@ -155,87 +163,14 @@ impl Store {
Ok(global_addrs)
}
- pub(crate) fn add_global(&mut self, ty: GlobalType, value: RawWasmValue, idx: ModuleInstanceAddr) -> Result<Addr> {
- self.data.globals.push(Rc::new(RefCell::new(GlobalInstance::new(ty, value, idx))));
- Ok(self.data.globals.len() as Addr - 1)
- }
-
- pub(crate) fn add_table(&mut self, table: TableType, idx: ModuleInstanceAddr) -> Result<TableAddr> {
- self.data.tables.push(Rc::new(RefCell::new(TableInstance::new(table, idx))));
- Ok(self.data.tables.len() as TableAddr - 1)
- }
-
- pub(crate) fn add_mem(&mut self, mem: MemoryType, idx: ModuleInstanceAddr) -> Result<MemAddr> {
- if let MemoryArch::I64 = mem.arch {
- return Err(Error::UnsupportedFeature("64-bit memories".to_string()));
- }
- self.data.mems.push(Rc::new(RefCell::new(MemoryInstance::new(mem, idx))));
- Ok(self.data.mems.len() as MemAddr - 1)
- }
-
- pub(crate) fn add_elem(&mut self, elem: Element, idx: ModuleInstanceAddr) -> Result<ElemAddr> {
- let init = elem
- .items
- .iter()
- .map(|item| {
- item.addr()
- .ok_or_else(|| Error::UnsupportedFeature(format!("const expression other than ref: {:?}", item)))
- })
- .collect::<Result<Vec<_>>>()?;
-
- self.data.elems.push(ElemInstance::new(elem.kind, idx, Some(init)));
- Ok(self.data.elems.len() as ElemAddr - 1)
- }
-
- pub(crate) fn add_data(&mut self, data: Data, idx: ModuleInstanceAddr) -> Result<DataAddr> {
- self.data.datas.push(DataInstance::new(data.data.to_vec(), idx));
- Ok(self.data.datas.len() as DataAddr - 1)
- }
-
- pub(crate) fn add_func(&mut self, func: Function, idx: ModuleInstanceAddr) -> Result<FuncAddr> {
- self.data.funcs.push(Rc::new(FunctionInstance { func, owner: idx }));
- Ok(self.data.funcs.len() as FuncAddr - 1)
- }
-
- /// Evaluate a constant expression, only supporting i32 globals and i32.const
- pub(crate) fn eval_i32_const(&self, const_instr: &tinywasm_types::ConstInstruction) -> Result<i32> {
- use tinywasm_types::ConstInstruction::*;
- let val = match const_instr {
- I32Const(i) => *i,
- GlobalGet(addr) => {
- let addr = *addr as usize;
- let global = self.data.globals[addr].clone();
- let val = global.borrow().value;
- i32::from(val)
- }
- _ => return Err(Error::Other("expected i32".to_string())),
- };
- Ok(val)
- }
-
- /// Evaluate a constant expression
- pub(crate) fn eval_const(&self, const_instr: &tinywasm_types::ConstInstruction) -> Result<RawWasmValue> {
- use tinywasm_types::ConstInstruction::*;
- let val = match const_instr {
- F32Const(f) => RawWasmValue::from(*f),
- F64Const(f) => RawWasmValue::from(*f),
- I32Const(i) => RawWasmValue::from(*i),
- I64Const(i) => RawWasmValue::from(*i),
- GlobalGet(addr) => {
- let addr = *addr as usize;
- let global = self.data.globals[addr].clone();
- let val = global.borrow().value;
- val
- }
- RefNull(v) => v.default_value().into(),
- RefFunc(idx) => RawWasmValue::from(*idx as i64),
- };
- Ok(val)
- }
-
/// Add elements to the store, returning their addresses in the store
/// Should be called after the tables have been added
- pub(crate) fn add_elems(&mut self, elems: Vec<Element>, idx: ModuleInstanceAddr) -> Result<Vec<Addr>> {
+ pub(crate) fn init_elems(
+ &mut self,
+ table_addrs: &[TableAddr],
+ elems: Vec<Element>,
+ idx: ModuleInstanceAddr,
+ ) -> Result<Vec<Addr>> {
let elem_count = self.data.elems.len();
let mut elem_addrs = Vec::with_capacity(elem_count);
for (i, elem) in elems.into_iter().enumerate() {
@@ -262,13 +197,17 @@ impl Store {
// this one is active, so we need to initialize it (essentially a `table.init` instruction)
ElementKind::Active { offset, table } => {
let offset = self.eval_i32_const(&offset)?;
+ let table_addr = table_addrs
+ .get(table as usize)
+ .copied()
+ .ok_or_else(|| Error::Other(format!("table {} not found for element {}", table, i)))?;
// a. Let n be the length of the vector elem[i].init
// b. Execute the instruction sequence einstrs
// c. Execute the instruction i32.const 0
// d. Execute the instruction i32.const n
// e. Execute the instruction table.init tableidx i
- if let Some(table) = self.data.tables.get_mut(table as usize) {
+ if let Some(table) = self.data.tables.get_mut(table_addr as usize) {
table.borrow_mut().init(offset, &init)?;
} else {
log::error!("table {} not found", table);
@@ -287,7 +226,12 @@ impl Store {
}
/// Add data to the store, returning their addresses in the store
- pub(crate) fn add_datas(&mut self, datas: Vec<Data>, idx: ModuleInstanceAddr) -> Result<Vec<Addr>> {
+ pub(crate) fn init_datas(
+ &mut self,
+ mem_addrs: &[MemAddr],
+ datas: Vec<Data>,
+ idx: ModuleInstanceAddr,
+ ) -> Result<Vec<Addr>> {
let data_count = self.data.datas.len();
let mut data_addrs = Vec::with_capacity(data_count);
for (i, data) in datas.into_iter().enumerate() {
@@ -299,6 +243,11 @@ impl Store {
return Err(Error::UnsupportedFeature("data segments for non-zero memories".to_string()));
}
+ let mem_addr = mem_addrs
+ .get(mem_addr as usize)
+ .copied()
+ .ok_or_else(|| Error::Other(format!("memory {} not found for data segment {}", mem_addr, i)))?;
+
let offset = self.eval_i32_const(&offset)?;
let mem =
@@ -308,7 +257,7 @@ impl Store {
mem.borrow_mut().store(offset as usize, 0, &data.data)?;
- // drop the date
+ // drop the data
continue;
}
Passive => {}
@@ -320,6 +269,84 @@ impl Store {
Ok(data_addrs)
}
+ pub(crate) fn add_global(&mut self, ty: GlobalType, value: RawWasmValue, idx: ModuleInstanceAddr) -> Result<Addr> {
+ self.data.globals.push(Rc::new(RefCell::new(GlobalInstance::new(ty, value, idx))));
+ Ok(self.data.globals.len() as Addr - 1)
+ }
+
+ pub(crate) fn add_table(&mut self, table: TableType, idx: ModuleInstanceAddr) -> Result<TableAddr> {
+ self.data.tables.push(Rc::new(RefCell::new(TableInstance::new(table, idx))));
+ Ok(self.data.tables.len() as TableAddr - 1)
+ }
+
+ pub(crate) fn add_mem(&mut self, mem: MemoryType, idx: ModuleInstanceAddr) -> Result<MemAddr> {
+ if let MemoryArch::I64 = mem.arch {
+ return Err(Error::UnsupportedFeature("64-bit memories".to_string()));
+ }
+ self.data.mems.push(Rc::new(RefCell::new(MemoryInstance::new(mem, idx))));
+ Ok(self.data.mems.len() as MemAddr - 1)
+ }
+
+ pub(crate) fn add_elem(&mut self, elem: Element, idx: ModuleInstanceAddr) -> Result<ElemAddr> {
+ let init = elem
+ .items
+ .iter()
+ .map(|item| {
+ item.addr()
+ .ok_or_else(|| Error::UnsupportedFeature(format!("const expression other than ref: {:?}", item)))
+ })
+ .collect::<Result<Vec<_>>>()?;
+
+ self.data.elems.push(ElemInstance::new(elem.kind, idx, Some(init)));
+ Ok(self.data.elems.len() as ElemAddr - 1)
+ }
+
+ pub(crate) fn add_data(&mut self, data: Data, idx: ModuleInstanceAddr) -> Result<DataAddr> {
+ self.data.datas.push(DataInstance::new(data.data.to_vec(), idx));
+ Ok(self.data.datas.len() as DataAddr - 1)
+ }
+
+ pub(crate) fn add_func(&mut self, func: Function, idx: ModuleInstanceAddr) -> Result<FuncAddr> {
+ self.data.funcs.push(Rc::new(FunctionInstance { func, owner: idx }));
+ Ok(self.data.funcs.len() as FuncAddr - 1)
+ }
+
+ /// Evaluate a constant expression, only supporting i32 globals and i32.const
+ pub(crate) fn eval_i32_const(&self, const_instr: &tinywasm_types::ConstInstruction) -> Result<i32> {
+ use tinywasm_types::ConstInstruction::*;
+ let val = match const_instr {
+ I32Const(i) => *i,
+ GlobalGet(addr) => {
+ let addr = *addr as usize;
+ let global = self.data.globals[addr].clone();
+ let val = global.borrow().value;
+ i32::from(val)
+ }
+ _ => return Err(Error::Other("expected i32".to_string())),
+ };
+ Ok(val)
+ }
+
+ /// Evaluate a constant expression
+ pub(crate) fn eval_const(&self, const_instr: &tinywasm_types::ConstInstruction) -> Result<RawWasmValue> {
+ use tinywasm_types::ConstInstruction::*;
+ let val = match const_instr {
+ F32Const(f) => RawWasmValue::from(*f),
+ F64Const(f) => RawWasmValue::from(*f),
+ I32Const(i) => RawWasmValue::from(*i),
+ I64Const(i) => RawWasmValue::from(*i),
+ GlobalGet(addr) => {
+ let addr = *addr as usize;
+ let global = self.data.globals[addr].clone();
+ let val = global.borrow().value;
+ val
+ }
+ RefNull(v) => v.default_value().into(),
+ RefFunc(idx) => RawWasmValue::from(*idx as i64),
+ };
+ Ok(val)
+ }
+
/// Get the function at the actual index in the store
pub(crate) fn get_func(&self, addr: usize) -> Result<&Rc<FunctionInstance>> {
self.data.funcs.get(addr).ok_or_else(|| Error::Other(format!("function {} not found", addr)))
diff --git a/crates/tinywasm/tests/generated/mvp.csv b/crates/tinywasm/tests/generated/mvp.csv
index a1eaf8c..824bf55 100644
--- a/crates/tinywasm/tests/generated/mvp.csv
+++ b/crates/tinywasm/tests/generated/mvp.csv
@@ -2,4 +2,4 @@
0.0.5,11135,9093,[{"name":"address.wast","passed":1,"failed":259},{"name":"align.wast","passed":108,"failed":48},{"name":"binary-leb128.wast","passed":78,"failed":13},{"name":"binary.wast","passed":107,"failed":5},{"name":"block.wast","passed":170,"failed":53},{"name":"br.wast","passed":20,"failed":77},{"name":"br_if.wast","passed":29,"failed":89},{"name":"br_table.wast","passed":24,"failed":150},{"name":"call.wast","passed":18,"failed":73},{"name":"call_indirect.wast","passed":34,"failed":136},{"name":"comments.wast","passed":5,"failed":3},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":25,"failed":594},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":22,"failed":39},{"name":"elem.wast","passed":27,"failed":72},{"name":"endianness.wast","passed":1,"failed":68},{"name":"exports.wast","passed":90,"failed":6},{"name":"f32.wast","passed":1018,"failed":1496},{"name":"f32_bitwise.wast","passed":4,"failed":360},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":1018,"failed":1496},{"name":"f64_bitwise.wast","passed":4,"failed":360},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":1,"failed":7},{"name":"float_exprs.wast","passed":275,"failed":625},{"name":"float_literals.wast","passed":112,"failed":51},{"name":"float_memory.wast","passed":0,"failed":90},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":81,"failed":91},{"name":"func_ptrs.wast","passed":7,"failed":29},{"name":"global.wast","passed":50,"failed":60},{"name":"i32.wast","passed":85,"failed":375},{"name":"i64.wast","passed":31,"failed":385},{"name":"if.wast","passed":116,"failed":125},{"name":"imports.wast","passed":23,"failed":160},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":25,"failed":26},{"name":"labels.wast","passed":13,"failed":16},{"name":"left-to-right.wast","passed":0,"failed":96},{"name":"linking.wast","passed":5,"failed":127},{"name":"load.wast","passed":59,"failed":38},{"name":"local_get.wast","passed":18,"failed":18},{"name":"local_set.wast","passed":38,"failed":15},{"name":"local_tee.wast","passed":41,"failed":56},{"name":"loop.wast","passed":42,"failed":78},{"name":"memory.wast","passed":30,"failed":49},{"name":"memory_grow.wast","passed":11,"failed":85},{"name":"memory_redundancy.wast","passed":1,"failed":7},{"name":"memory_size.wast","passed":6,"failed":36},{"name":"memory_trap.wast","passed":1,"failed":181},{"name":"names.wast","passed":484,"failed":2},{"name":"nop.wast","passed":4,"failed":84},{"name":"return.wast","passed":20,"failed":64},{"name":"select.wast","passed":28,"failed":120},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":2,"failed":5},{"name":"start.wast","passed":4,"failed":16},{"name":"store.wast","passed":59,"failed":9},{"name":"switch.wast","passed":2,"failed":26},{"name":"token.wast","passed":39,"failed":19},{"name":"traps.wast","passed":4,"failed":32},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":0,"failed":64},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":9,"failed":41},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
0.1.0,17630,2598,[{"name":"address.wast","passed":5,"failed":255},{"name":"align.wast","passed":108,"failed":48},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":110,"failed":2},{"name":"block.wast","passed":193,"failed":30},{"name":"br.wast","passed":84,"failed":13},{"name":"br_if.wast","passed":90,"failed":28},{"name":"br_table.wast","passed":25,"failed":149},{"name":"call.wast","passed":29,"failed":62},{"name":"call_indirect.wast","passed":36,"failed":134},{"name":"comments.wast","passed":7,"failed":1},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":371,"failed":248},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":47,"failed":14},{"name":"elem.wast","passed":50,"failed":49},{"name":"endianness.wast","passed":1,"failed":68},{"name":"exports.wast","passed":92,"failed":4},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":2,"failed":6},{"name":"float_exprs.wast","passed":761,"failed":139},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":6,"failed":84},{"name":"float_misc.wast","passed":437,"failed":4},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":124,"failed":48},{"name":"func_ptrs.wast","passed":10,"failed":26},{"name":"global.wast","passed":51,"failed":59},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":120,"failed":121},{"name":"imports.wast","passed":74,"failed":109},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":14,"failed":15},{"name":"left-to-right.wast","passed":1,"failed":95},{"name":"linking.wast","passed":21,"failed":111},{"name":"load.wast","passed":60,"failed":37},{"name":"local_get.wast","passed":32,"failed":4},{"name":"local_set.wast","passed":50,"failed":3},{"name":"local_tee.wast","passed":68,"failed":29},{"name":"loop.wast","passed":93,"failed":27},{"name":"memory.wast","passed":34,"failed":45},{"name":"memory_grow.wast","passed":12,"failed":84},{"name":"memory_redundancy.wast","passed":1,"failed":7},{"name":"memory_size.wast","passed":6,"failed":36},{"name":"memory_trap.wast","passed":2,"failed":180},{"name":"names.wast","passed":485,"failed":1},{"name":"nop.wast","passed":46,"failed":42},{"name":"return.wast","passed":73,"failed":11},{"name":"select.wast","passed":86,"failed":62},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":2,"failed":5},{"name":"start.wast","passed":9,"failed":11},{"name":"store.wast","passed":59,"failed":9},{"name":"switch.wast","passed":2,"failed":26},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":22,"failed":14},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":50,"failed":14},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":35,"failed":15},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
0.2.0,19344,884,[{"name":"address.wast","passed":181,"failed":79},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":220,"failed":3},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":171,"failed":3},{"name":"call.wast","passed":73,"failed":18},{"name":"call_indirect.wast","passed":50,"failed":120},{"name":"comments.wast","passed":7,"failed":1},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":439,"failed":180},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":47,"failed":14},{"name":"elem.wast","passed":56,"failed":43},{"name":"endianness.wast","passed":29,"failed":40},{"name":"exports.wast","passed":92,"failed":4},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":6,"failed":2},{"name":"float_exprs.wast","passed":890,"failed":10},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":78,"failed":12},{"name":"float_misc.wast","passed":437,"failed":4},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":168,"failed":4},{"name":"func_ptrs.wast","passed":10,"failed":26},{"name":"global.wast","passed":103,"failed":7},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":231,"failed":10},{"name":"imports.wast","passed":80,"failed":103},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":26,"failed":3},{"name":"left-to-right.wast","passed":92,"failed":4},{"name":"linking.wast","passed":29,"failed":103},{"name":"load.wast","passed":93,"failed":4},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":93,"failed":4},{"name":"loop.wast","passed":116,"failed":4},{"name":"memory.wast","passed":78,"failed":1},{"name":"memory_grow.wast","passed":91,"failed":5},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":35,"failed":7},{"name":"memory_trap.wast","passed":180,"failed":2},{"name":"names.wast","passed":485,"failed":1},{"name":"nop.wast","passed":78,"failed":10},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":114,"failed":34},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":11,"failed":9},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
-0.3.0-alpha.0,19691,537,[{"name":"address.wast","passed":223,"failed":37},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":220,"failed":3},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"call.wast","passed":76,"failed":15},{"name":"call_indirect.wast","passed":151,"failed":19},{"name":"comments.wast","passed":7,"failed":1},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":54,"failed":7},{"name":"elem.wast","passed":61,"failed":38},{"name":"endianness.wast","passed":29,"failed":40},{"name":"exports.wast","passed":92,"failed":4},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":7,"failed":1},{"name":"float_exprs.wast","passed":890,"failed":10},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":80,"failed":10},{"name":"float_misc.wast","passed":437,"failed":4},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":169,"failed":3},{"name":"func_ptrs.wast","passed":19,"failed":17},{"name":"global.wast","passed":106,"failed":4},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":232,"failed":9},{"name":"imports.wast","passed":65,"failed":118},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":26,"failed":3},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":18,"failed":114},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":116,"failed":4},{"name":"memory.wast","passed":34,"failed":45},{"name":"memory_grow.wast","passed":89,"failed":7},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":180,"failed":2},{"name":"names.wast","passed":485,"failed":1},{"name":"nop.wast","passed":78,"failed":10},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":143,"failed":5},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":14,"failed":6},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
+0.3.0-alpha.0,19831,397,[{"name":"address.wast","passed":260,"failed":0},{"name":"align.wast","passed":156,"failed":0},{"name":"binary-leb128.wast","passed":91,"failed":0},{"name":"binary.wast","passed":112,"failed":0},{"name":"block.wast","passed":220,"failed":3},{"name":"br.wast","passed":97,"failed":0},{"name":"br_if.wast","passed":118,"failed":0},{"name":"br_table.wast","passed":174,"failed":0},{"name":"call.wast","passed":76,"failed":15},{"name":"call_indirect.wast","passed":155,"failed":15},{"name":"comments.wast","passed":7,"failed":1},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":619,"failed":0},{"name":"custom.wast","passed":11,"failed":0},{"name":"data.wast","passed":61,"failed":0},{"name":"elem.wast","passed":69,"failed":30},{"name":"endianness.wast","passed":29,"failed":40},{"name":"exports.wast","passed":92,"failed":4},{"name":"f32.wast","passed":2514,"failed":0},{"name":"f32_bitwise.wast","passed":364,"failed":0},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":2514,"failed":0},{"name":"f64_bitwise.wast","passed":364,"failed":0},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":7,"failed":1},{"name":"float_exprs.wast","passed":900,"failed":0},{"name":"float_literals.wast","passed":163,"failed":0},{"name":"float_memory.wast","passed":90,"failed":0},{"name":"float_misc.wast","passed":437,"failed":4},{"name":"forward.wast","passed":5,"failed":0},{"name":"func.wast","passed":170,"failed":2},{"name":"func_ptrs.wast","passed":20,"failed":16},{"name":"global.wast","passed":106,"failed":4},{"name":"i32.wast","passed":460,"failed":0},{"name":"i64.wast","passed":416,"failed":0},{"name":"if.wast","passed":232,"failed":9},{"name":"imports.wast","passed":70,"failed":113},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":108,"failed":0},{"name":"int_literals.wast","passed":51,"failed":0},{"name":"labels.wast","passed":26,"failed":3},{"name":"left-to-right.wast","passed":96,"failed":0},{"name":"linking.wast","passed":18,"failed":114},{"name":"load.wast","passed":97,"failed":0},{"name":"local_get.wast","passed":36,"failed":0},{"name":"local_set.wast","passed":53,"failed":0},{"name":"local_tee.wast","passed":97,"failed":0},{"name":"loop.wast","passed":116,"failed":4},{"name":"memory.wast","passed":79,"failed":0},{"name":"memory_grow.wast","passed":92,"failed":4},{"name":"memory_redundancy.wast","passed":8,"failed":0},{"name":"memory_size.wast","passed":42,"failed":0},{"name":"memory_trap.wast","passed":182,"failed":0},{"name":"names.wast","passed":486,"failed":0},{"name":"nop.wast","passed":78,"failed":10},{"name":"return.wast","passed":84,"failed":0},{"name":"select.wast","passed":143,"failed":5},{"name":"skip-stack-guard-page.wast","passed":11,"failed":0},{"name":"stack.wast","passed":7,"failed":0},{"name":"start.wast","passed":20,"failed":0},{"name":"store.wast","passed":68,"failed":0},{"name":"switch.wast","passed":28,"failed":0},{"name":"token.wast","passed":58,"failed":0},{"name":"traps.wast","passed":36,"failed":0},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":64,"failed":0},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":50,"failed":0},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
diff --git a/crates/tinywasm/tests/generated/progress-mvp.svg b/crates/tinywasm/tests/generated/progress-mvp.svg
index 5e3f57b..1f8316a 100644
--- a/crates/tinywasm/tests/generated/progress-mvp.svg
+++ b/crates/tinywasm/tests/generated/progress-mvp.svg
@@ -53,12 +53,12 @@ v0.2.0 (19344)
</text>
<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="716,345 716,350 "/>
<text x="898" y="355" dy="0.76em" text-anchor="middle" font-family="Victor Mono" font-size="12.096774193548388" opacity="1" fill="#000000">
-v0.3.0-alpha.0 (19775)
+v0.3.0-alpha.0 (19831)
</text>
<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="898,345 898,350 "/>
<rect x="266" y="185" width="172" height="159" opacity="0.5" fill="#0000FF" stroke="none"/>
-<rect x="630" y="67" width="172" height="277" opacity="0.5" fill="#0000FF" stroke="none"/>
+<rect x="812" y="60" width="172" height="284" opacity="0.5" fill="#0000FF" stroke="none"/>
<rect x="85" y="212" width="171" height="132" opacity="0.5" fill="#0000FF" stroke="none"/>
-<rect x="812" y="61" width="172" height="283" opacity="0.5" fill="#0000FF" stroke="none"/>
+<rect x="630" y="67" width="172" height="277" opacity="0.5" fill="#0000FF" stroke="none"/>
<rect x="448" y="92" width="172" height="252" opacity="0.5" fill="#0000FF" stroke="none"/>
</svg>