brson / miri

An experimental compiler from Rust to WebAssembly (inactive - do not use)
Apache License 2.0
209 stars 15 forks source link

Handle the Module start function and Module exports with attributes #23

Closed lqd closed 8 years ago

lqd commented 8 years ago
kripken commented 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.

lqd commented 8 years ago

@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)
}
kripken commented 8 years ago

That looks good too :)

brson commented 8 years ago

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.

lqd commented 8 years ago

@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 ?

brson commented 8 years ago

@lqd If you can get it working without the custom attributes easily, yeah, it would be good to pay down that debt.

lqd commented 8 years ago

@brson I did this as part of #26