You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be helpful in reasoning about ABIs if the Call section of the AST document could give some examples of function signature specifications.
How would this proposal handle variable-length parameter lists?
How do compilers place arrays on the stack? Looks like all of the local variable types are scalar.
Variable-length parameter lists in C are lowered by the compiler. The caller allocates a stack buffer, stores the variable-length arguments into it, and then passes a pointer to the buffer to the callee. This has the advantage of not requiring any special platform support.
Arrays on the stack are allocated on the "addressable stack", which is a convention of using part of the application heap in a stack-like manner for variables that need to be addressable.
Applications can decide for themselves how big to make the addressable stack. The WebAssembly platform itself doesn't impose any restrictions on the addressable stack. Addressable stack conventions will certainly need to be part of any common ABI though.
Multiple return value calls are not yet specified, but they likely will be eventually, in which case a function signature will essentially be just a pair of sequences of local types. The first sequence is for the return values, and the second sequence is for the argument values. A CallDirect function will have an operand for each local type in the argument portion of the signature of the called function.
We've punted ABI discussion to later: there currently isn't any way that this is meaningfully exposed through wasm. Once dynamic linking is available we'll need to figure something out, but even then it isn't clear it'll be an issue. See #98 and #53 for further discussion.
Function signatures are defined in #307, which is now merged, along with a note about C varargs. There are also some example functions in the spec test directory.
Activity
sunfishcode commentedon Jun 9, 2015
Variable-length parameter lists in C are lowered by the compiler. The caller allocates a stack buffer, stores the variable-length arguments into it, and then passes a pointer to the buffer to the callee. This has the advantage of not requiring any special platform support.
Arrays on the stack are allocated on the "addressable stack", which is a convention of using part of the application heap in a stack-like manner for variables that need to be addressable.
steveluc commentedon Jun 9, 2015
How is it decided how big the addressable stack should be?
What does a function signature look like? Is there a variable-length list of local variable indices given as part of the CallDirect function?
sunfishcode commentedon Jun 9, 2015
Applications can decide for themselves how big to make the addressable stack. The WebAssembly platform itself doesn't impose any restrictions on the addressable stack. Addressable stack conventions will certainly need to be part of any common ABI though.
Multiple return value calls are not yet specified, but they likely will be eventually, in which case a function signature will essentially be just a pair of sequences of local types. The first sequence is for the return values, and the second sequence is for the argument values. A CallDirect function will have an operand for each local type in the argument portion of the signature of the called function.
jfbastien commentedon Jun 9, 2015
We've punted ABI discussion to later: there currently isn't any way that this is meaningfully exposed through wasm. Once dynamic linking is available we'll need to figure something out, but even then it isn't clear it'll be an issue. See #98 and #53 for further discussion.
sunfishcode commentedon Jul 22, 2015
#278 is a pull request which defines function signatures.
sunfishcode commentedon Aug 21, 2015
Function signatures are defined in #307, which is now merged, along with a note about C varargs. There are also some example functions in the spec test directory.