Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Generated by `wit-bindgen` 0.45.0.

///|
fn init {
let _ = @add.add(1, 2).unwrap_or_error() catch { Overflow => ... }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Generated by `wit-bindgen` 0.45.0. DO NOT EDIT!

///|
pub(all) suberror ComputationError {
Overflow
} derive(Show, Eq)

///|
pub fn add(x : UInt, y : UInt) -> Result[UInt, ComputationError] {
let return_area = @ffi.malloc(8)
wasmImportAdd(x.reinterpret_as_int(), y.reinterpret_as_int(), return_area)
let lifted4 = match @ffi.load8_u(return_area + 0) {
0 => Result::Ok(@ffi.load32(return_area + 4).reinterpret_as_uint())
1 => {
let lifted = match @ffi.load8_u(return_area + 4) {
0 => ComputationError::Overflow
_ => panic()
}
Result::Err(lifted)
}
_ => panic()
}
@ffi.free(return_area)
return lifted4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package docs:[email protected];

interface add {
variant computation-error {
overflow
}
add: func(x: u32, y: u32) -> result<u32, computation-error>;
}

world adder {
import add;
}
25 changes: 25 additions & 0 deletions component-model/examples/tutorial/moonbit/adder/moon.pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// link configuration for Wasm backend
"link": {
"wasm": {
"exports": [
// Export for cabi_realloc
"cabi_realloc:cabi_realloc",
// Export per the interface definition
"wasmExportAdd:docs:adder/[email protected]#add"
],
"export-memory-name": "memory",
"heap-start-address": 16
}
},
"import": [
{
"path": "docs/adder/ffi",
"alias": "ffi"
},
{
"path": "docs/adder/gen/interface/docs/adder/add",
"alias": "add"
}
]
}
6 changes: 6 additions & 0 deletions component-model/examples/tutorial/moonbit/adder/stub.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Generated by `wit-bindgen` 0.45.0.

///|
pub fn add(x : UInt, y : UInt) -> UInt {
x + y
}
1 change: 1 addition & 0 deletions component-model/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- [JavaScript](./language-support/javascript.md)
- [Python](./language-support/python.md)
- [Rust](./language-support/rust.md)
- [MoonBit](./language-support/moonbit.md)
- [WebAssembly Text Format (WAT)](./language-support/wat.md)
- [Other Languages](./language-support/other-languages.md)
- [Running Components](./running-components.md)
Expand Down
2 changes: 2 additions & 0 deletions component-model/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This documentation is aimed at _users_ of the component model: developers of lib
| [Worlds] | [JavaScript] | |
| | [Python] | |
| | [Rust] | |
| | [MoonBit] | |

[Why Components?]: ./design/why-component-model.md
[Components]: ./design/components.md
Expand All @@ -31,6 +32,7 @@ This documentation is aimed at _users_ of the component model: developers of lib
[JavaScript]: ./language-support/javascript.md
[Python]: ./language-support/python.md
[Rust]: ./language-support/rust.md
[MoonBit]: ./language-support/moonbit.md

[Composing]: ./composing-and-distributing/composing.md
[Running]: ./running-components.md
Expand Down
1 change: 1 addition & 0 deletions component-model/src/language-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ without using a higher-level language front-end.
- [Rust Tooling](./language-support/rust.md)
- [Building a Component with `cargo component`](./language-support/rust.md#building-a-component-with-cargo-component)
- [Running a Component from Rust Applications](./language-support/rust.md#running-a-component-from-rust-appliacations)
- [MoonBit Tooling](./language-support/moonbit.md)
- [WebAssembly Text Format (WAT)](./language-support/wat.md#wat-webassembly-text-format)
- [Building a Component from WAT with `wasm-tools`](./language-support/wat.md#building-a-component-with-wasm-tools)
- [Running a Component with Wasmtime](./language-support/wat.md#running-a-component-with-wasmtime)
Expand Down
Loading