Support stack closures with up to 7 arguments

This commit is contained in:
Alex Crichton 2018-04-04 08:47:48 -07:00
parent c0cad447c1
commit 28d6c1bc12
3 changed files with 26 additions and 2 deletions

View File

@ -1439,7 +1439,13 @@ impl<'a, 'b> SubContext<'a, 'b> {
format!("getObject(arg{})", i)
}
shared::TYPE_STACK_FUNC0 |
shared::TYPE_STACK_FUNC1 => {
shared::TYPE_STACK_FUNC1 |
shared::TYPE_STACK_FUNC2 |
shared::TYPE_STACK_FUNC3 |
shared::TYPE_STACK_FUNC4 |
shared::TYPE_STACK_FUNC5 |
shared::TYPE_STACK_FUNC6 |
shared::TYPE_STACK_FUNC7 => {
let nargs = *arg - shared::TYPE_STACK_FUNC0;
let args = (0..nargs)
.map(|i| format!("arg{}", i))

View File

@ -148,8 +148,14 @@ pub const TYPE_JS_OWNED: u32 = 22;
pub const TYPE_JS_REF: u32 = 23;
pub const TYPE_STACK_FUNC0: u32 = 24;
pub const TYPE_STACK_FUNC1: u32 = 25;
pub const TYPE_STACK_FUNC2: u32 = 26;
pub const TYPE_STACK_FUNC3: u32 = 27;
pub const TYPE_STACK_FUNC4: u32 = 28;
pub const TYPE_STACK_FUNC5: u32 = 29;
pub const TYPE_STACK_FUNC6: u32 = 30;
pub const TYPE_STACK_FUNC7: u32 = 31;
pub const TYPE_CUSTOM_START: u32 = 26;
pub const TYPE_CUSTOM_START: u32 = 32;
pub const TYPE_CUSTOM_REF_FLAG: u32 = 1;
pub fn name_to_descriptor(name: &str) -> u32 {

View File

@ -23,6 +23,12 @@ pub const DESCRIPTOR_JS_REF: Descriptor = Descriptor { __x: *b" 23", };
pub const DESCRIPTOR_STACK_FUNC0: Descriptor = Descriptor { __x: *b" 24", };
pub const DESCRIPTOR_STACK_FUNC1: Descriptor = Descriptor { __x: *b" 25", };
pub const DESCRIPTOR_STACK_FUNC2: Descriptor = Descriptor { __x: *b" 26", };
pub const DESCRIPTOR_STACK_FUNC3: Descriptor = Descriptor { __x: *b" 27", };
pub const DESCRIPTOR_STACK_FUNC4: Descriptor = Descriptor { __x: *b" 28", };
pub const DESCRIPTOR_STACK_FUNC5: Descriptor = Descriptor { __x: *b" 29", };
pub const DESCRIPTOR_STACK_FUNC6: Descriptor = Descriptor { __x: *b" 30", };
pub const DESCRIPTOR_STACK_FUNC7: Descriptor = Descriptor { __x: *b" 31", };
pub trait WasmBoundary {
type Abi: WasmAbi;
@ -407,4 +413,10 @@ macro_rules! stack_closures {
stack_closures! {
() => DESCRIPTOR_STACK_FUNC0
(A) => DESCRIPTOR_STACK_FUNC1
(A B) => DESCRIPTOR_STACK_FUNC2
(A B C) => DESCRIPTOR_STACK_FUNC3
(A B C D) => DESCRIPTOR_STACK_FUNC4
(A B C D E) => DESCRIPTOR_STACK_FUNC5
(A B C D E F) => DESCRIPTOR_STACK_FUNC6
(A B C D E F G) => DESCRIPTOR_STACK_FUNC7
}