Closed lqd closed 8 years ago
Very nice! :) These attributes are something we've wanted in C/C++ for a while, and have hacks instead. Nice to see it done properly in Rust.
@kripken I'd wait for @brson's review before calling it 'done properly' :)
But I also prototyped the same thing for imports, like you said in another issue: eg something along those lines
extern {
#[wasm_import(module="specttest", name="print")]
fn _print_i32(i: i32)
}
That looks good too :)
Like #[wasm_export]
the entry point will eventually need to work the way Rust's other entry points do.
What this will probably mean is that the stdlib (or the user in the case of no-std crates) will define #[start]
like normal; mir2wasm will emit a function that conforms to what wasm expects as the start function (called maybe __wasm_start
); that function will call the function defined in Rust code by #[start]
passing 0s as argc and argv; the Rust start function, which is normally defined in std, will then do nothing with argc and argv, and call the user-defined main
function (passed to start
by __wasm_start
).
For a hint of what the runtime set up looks like see this.
For now this is fine to make progress, but it will need to evolve to be more correct.
@brson I already have something similar in my fork, see https://gist.github.com/lqd/98450b32c115df630f38c8cf4bbe69d7 (this was also printing the result of a start(1,0)
call for testing purposes but both would be changed). This way both the rust main (which already works) and start can be called at Module start automatically.
Would you like a PR for this sooner rather than later then ?
@lqd If you can get it working without the custom attributes easily, yeah, it would be good to pay down that debt.
@brson I did this as part of #26
#[wasm_export]
fns will be compiled as Module exports#[wasm_start]
(or#[main]
) fn will be set as the Module start function#[wasm_start]
method, launching the wast with the interpreter will runreal_main
test
, and for instance passing -e to the interpreter will choose the entry point:binaryen-shell -e test
will execute the function