From ea639ed420547d7e02b2646f57ccc3bf5c0658e7 Mon Sep 17 00:00:00 2001 From: Rerumu Date: Sun, 28 Nov 2021 03:35:58 -0500 Subject: [PATCH] Add block multi-value support --- wasm/Cargo.toml | 1 + wasm/src/backend/ast/transformer.rs | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index b055c2c..1e7ac7c 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" [dependencies.parity-wasm] git = "https://github.com/paritytech/parity-wasm.git" +features = ["multi_value"] diff --git a/wasm/src/backend/ast/transformer.rs b/wasm/src/backend/ast/transformer.rs index 1f07c12..5bcd036 100644 --- a/wasm/src/backend/ast/transformer.rs +++ b/wasm/src/backend/ast/transformer.rs @@ -61,6 +61,12 @@ impl<'a> Transformer<'a> { } } + fn get_type_of(&self, index: u32) -> Arity { + let types = self.wasm.type_section().unwrap().types(); + + Arity::from_index(types, index) + } + fn push_recall(&mut self, num: u32) { let len = self.stack.len(); @@ -70,11 +76,15 @@ impl<'a> Transformer<'a> { } fn push_block_result(&mut self, typ: BlockType) { - if matches!(typ, BlockType::NoResult) { - return; - } + let num = match typ { + BlockType::NoResult => { + return; + } + BlockType::Value(_) => 1, + BlockType::TypeIndex(i) => self.get_type_of(i).num_result, + }; - self.push_recall(1); + self.push_recall(num); } // If any expressions are still pending at the start of @@ -138,8 +148,7 @@ impl<'a> Transformer<'a> { } fn gen_call_indirect(&mut self, typ: u32, table: u8, stat: &mut Vec) { - let types = self.wasm.type_section().unwrap().types(); - let arity = Arity::from_index(types, typ); + let arity = self.get_type_of(typ); let index = self.stack.pop().unwrap(); let param_list = self