File tree Expand file tree Collapse file tree 9 files changed +372
-0
lines changed
examples/tutorial/moonbit Expand file tree Collapse file tree 9 files changed +372
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Generated by `wit-bindgen` 0.45.0.
2
+
3
+ ///|
4
+ fn init {
5
+ let _ = @add .add (1 , 2 ).unwrap_or_error () catch { Overflow => ... }
6
+
7
+ }
Original file line number Diff line number Diff line change
1
+ // Generated by `wit-bindgen` 0.45.0. DO NOT EDIT!
2
+
3
+ ///|
4
+ pub (all ) suberror ComputationError {
5
+ Overflow
6
+ } derive (Show , Eq )
7
+
8
+ ///|
9
+ pub fn add (x : UInt , y : UInt ) -> Result [UInt , ComputationError ] {
10
+ let return_area = @ffi .malloc (8 )
11
+ wasmImportAdd (x .reinterpret_as_int (), y .reinterpret_as_int (), return_area )
12
+ let lifted4 = match @ffi .load8_u (return_area + 0 ) {
13
+ 0 => Result ::Ok (@ffi .load32 (return_area + 4 ).reinterpret_as_uint ())
14
+ 1 => {
15
+ let lifted = match @ffi .load8_u (return_area + 4 ) {
16
+ 0 => ComputationError ::Overflow
17
+ _ => panic ()
18
+ }
19
+ Result ::Err (lifted )
20
+ }
21
+ _ => panic ()
22
+ }
23
+ @ffi .free (return_area )
24
+ return lifted4
25
+ }
Original file line number Diff line number Diff line change
1
+ package docs : adder @ 0.1.0;
2
+
3
+ interface add {
4
+ variant computation-error {
5
+ overflow
6
+ }
7
+ add : func (x : u32 , y : u32 ) -> result <u32 , computation-error >;
8
+ }
9
+
10
+ world adder {
11
+ import add ;
12
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ // link configuration for Wasm backend
3
+ "link" : {
4
+ "wasm" : {
5
+ "exports" : [
6
+ // Export for cabi_realloc
7
+ " cabi_realloc:cabi_realloc" ,
8
+ // Export per the interface definition
9
+ " wasmExportAdd:docs:adder/[email protected] #add"
10
+ ],
11
+ "export-memory-name" : " memory" ,
12
+ "heap-start-address" : 16
13
+ }
14
+ },
15
+ "import" : [
16
+ {
17
+ "path" : " docs/adder/ffi" ,
18
+ "alias" : " ffi"
19
+ },
20
+ {
21
+ "path" : " docs/adder/gen/interface/docs/adder/add" ,
22
+ "alias" : " add"
23
+ }
24
+ ]
25
+ }
Original file line number Diff line number Diff line change
1
+ // Generated by `wit-bindgen` 0.45.0.
2
+
3
+ ///|
4
+ pub fn add (x : UInt , y : UInt ) -> UInt {
5
+ x + y
6
+ }
Original file line number Diff line number Diff line change 23
23
- [ JavaScript] ( ./language-support/javascript.md )
24
24
- [ Python] ( ./language-support/python.md )
25
25
- [ Rust] ( ./language-support/rust.md )
26
+ - [ MoonBit] ( ./language-support/moonbit.md )
26
27
- [ WebAssembly Text Format (WAT)] ( ./language-support/wat.md )
27
28
- [ Other Languages] ( ./language-support/other-languages.md )
28
29
- [ Running Components] ( ./running-components.md )
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ This documentation is aimed at _users_ of the component model: developers of lib
19
19
| [ Worlds] | [ JavaScript] | |
20
20
| | [ Python] | |
21
21
| | [ Rust] | |
22
+ | | [ MoonBit] | |
22
23
23
24
[ Why Components? ] : ./design/why-component-model.md
24
25
[ Components ] : ./design/components.md
@@ -31,6 +32,7 @@ This documentation is aimed at _users_ of the component model: developers of lib
31
32
[ JavaScript ] : ./language-support/javascript.md
32
33
[ Python ] : ./language-support/python.md
33
34
[ Rust ] : ./language-support/rust.md
35
+ [ MoonBit ] : ./language-support/moonbit.md
34
36
35
37
[ Composing ] : ./composing-and-distributing/composing.md
36
38
[ Running ] : ./running-components.md
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ without using a higher-level language front-end.
37
37
- [ Rust Tooling] ( ./language-support/rust.md )
38
38
- [ Building a Component with ` cargo component ` ] ( ./language-support/rust.md#building-a-component-with-cargo-component )
39
39
- [ Running a Component from Rust Applications] ( ./language-support/rust.md#running-a-component-from-rust-appliacations )
40
+ - [ MoonBit Tooling] ( ./language-support/moonbit.md )
40
41
- [ WebAssembly Text Format (WAT)] ( ./language-support/wat.md#wat-webassembly-text-format )
41
42
- [ Building a Component from WAT with ` wasm-tools ` ] ( ./language-support/wat.md#building-a-component-with-wasm-tools )
42
43
- [ Running a Component with Wasmtime] ( ./language-support/wat.md#running-a-component-with-wasmtime )
You can’t perform that action at this time.
0 commit comments