-
Notifications
You must be signed in to change notification settings - Fork 70
doc(moonbit): add MoonBit explanation #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
daf21bf
doc(moonbit): add MoonBit explanation
peter-jerry-ye 1a241f9
fix(moonbit): bump tool version and extract code
peter-jerry-ye 7e8e658
chore(moonbit): use rust codefence for highlighting
peter-jerry-ye 6f84561
fix(moonbit): apply suggestions
peter-jerry-ye 7616e6a
fix(moonbit): update installation section
peter-jerry-ye a1fac79
fix(lang/moonbit): fix numbering of steps
vados-cosmonic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
component-model/examples/tutorial/moonbit/adder-with-error/stub.mbt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => ... } | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
component-model/examples/tutorial/moonbit/adder-with-error/top.mbt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
12 changes: 12 additions & 0 deletions
12
component-model/examples/tutorial/moonbit/adder-with-error/world.wit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
component-model/examples/tutorial/moonbit/adder/moon.pkg.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.