Spice up the project README, fill out more docs (#1010)

* Spice up the project README, fill out more docs

This is an attempt to spruce up wasmtime's README.md file as well as
fill out more of the missing documentation in the `docs/` folder.
There's still a long way to go but I hoped here to mostly move around
existing information and add new information. As always happy to have
feedback!

* Tweak CLI wording

* Remove no-longer relevant clause

* Update sandboxing docs

* Handle comments
This commit is contained in:
Alex Crichton
2020-02-27 17:28:08 -06:00
committed by GitHub
parent 35d5c6bdde
commit 8caa5a9476
13 changed files with 388 additions and 89 deletions

57
docs/wasm-wat.md Normal file
View File

@@ -0,0 +1,57 @@
# WebAssembly Text Format (`*.wat`)
While not necessarily a full-blown language you might be curious how Wasmtime
interacts with [the `*.wat` text format][spec]! The `wasmtime` CLI and Rust
embedding API both support the `*.wat` text format by default.
"Hello, World!" is pretty nontrivial in the `*.wat` format since it's
assembly-like and not really intended to be a primary programming language. That
being said we can create a simple add function to call it!
For example if you have a file `add.wat` like so:
```wat
(module
(func (export "add") (param i32 i32) (result i32)
local.get 0
local.get 1
i32.add))
```
Then you can execute this on the CLI with:
```sh
$ wasmtime add.wat --invoke add 1 2
warning: ...
warning: ...
3
```
And we can see that we're already adding numbers!
You can also see how this works in the Rust API like so:
```rust
# extern crate wasmtime;
# extern crate anyhow;
use wasmtime::*;
# fn main() -> anyhow::Result<()> {
let store = Store::default();
let wat = r#"
(module
(func (export "add") (param i32 i32) (result i32)
local.get 0
local.get 1
i32.add))
"#;
let module = Module::new(&store, wat)?;
let instance = Instance::new(&module, &[])?;
let add = instance.get_export("add").and_then(|f| f.func()).unwrap();
let add = add.get2::<i32, i32, i32>()?;
println!("1 + 2 = {}", add(1, 2)?);
# Ok(())
# }
```
[spec]: https://webassembly.github.io/spec/core/text/index.html