Skip to content

Define function signatures #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
steveluc opened this issue Jun 9, 2015 · 6 comments
Closed

Define function signatures #127

steveluc opened this issue Jun 9, 2015 · 6 comments
Milestone

Comments

@steveluc
Copy link

steveluc commented Jun 9, 2015

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.

@sunfishcode
Copy link
Member

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
Copy link
Author

steveluc commented 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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

#278 is a pull request which defines function signatures.

@sunfishcode sunfishcode added this to the MVP milestone Jul 28, 2015
@sunfishcode
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants