Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,10 @@ wasm-tools component new target/gen.wasm -o target/gen.component.wasm
You may use `--gen-dir` to specify which package should be responsible for the exportation. The default is `gen` as mentioned above.
This can be useful having one project that exports multiple worlds.

Generated projects use `moon.mod` and `moon.pkg`, with WebAssembly export mappings
configured in the export package's `moon.pkg`.
Generated projects use `moon.mod` and `moon.pkg`, with WebAssembly export names
specified by `#export_name` annotations in the export package.

When using `wit-bindgen moonbit`, you may use `--derive-show` or `--derive-eq` to derive `Show` or `Eq` traits for all types.
When using `wit-bindgen moonbit`, you may use `--derive-debug` or `--derive-eq` to generate `#derive(Debug)` or `#derive(Eq)` annotations for types without future or stream fields.
You may also use `--derive-error`, which will make types containing `Error` as error types in MoonBit.

#### MoonBit ABI compatibility
Expand Down
3 changes: 2 additions & 1 deletion crates/moonbit/src/async/async_abi.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ extern "wasm" fn int_array2ptr(array : FixedArray[Int]) -> Int =
#|(func (param i32) (result i32) local.get 0)

///|
struct WaitableSet(Int) derive(Eq, Hash)
#derive(Eq, Hash)
struct WaitableSet(Int)

///|
#deprecated
Expand Down
3 changes: 2 additions & 1 deletion crates/moonbit/src/async/promise.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ pub struct Promise[X] {
}

///|
pub(all) suberror PromiseClosed derive(Debug)
#derive(Debug)
pub(all) suberror PromiseClosed

///|
#deprecated
Expand Down
3 changes: 2 additions & 1 deletion crates/moonbit/src/async/task.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pub struct Task[X] {
///|
/// An observed task terminated by cancellation. This is an ordinary error in
/// the waiter, distinct from cancellation of the waiter itself.
pub suberror TaskCancelled derive(Debug)
#derive(Debug)
pub suberror TaskCancelled

///|
#deprecated
Expand Down
5 changes: 2 additions & 3 deletions crates/moonbit/src/async_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,15 +970,14 @@ impl<'a> InterfaceGenerator<'a> {
let export = format!(
r#"
///|
#export_name({callback_export_name:?})
#doc(hidden)
pub fn {export_func_name}(event_raw : Int, waitable : Int, code : Int) -> Int {{
{package}{export_func_name}(event_raw, waitable, code)
}}
"#,
);
self.world_gen
.export
.insert(callback_export_name, (export_func_name.clone(), export));
self.world_gen.export.insert(callback_export_name, export);

true
}
Expand Down
1 change: 1 addition & 0 deletions crates/moonbit/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ extern "wasm" fn mbt_ffi_free(position : Int) =

pub(crate) const CABI_REALLOC: &str = r#"
///|
#export_name("cabi_realloc")
pub fn mbt_ffi_cabi_realloc(
src_offset : Int,
src_size : Int,
Expand Down
2 changes: 1 addition & 1 deletion crates/moonbit/src/ffi/async_primitive.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn current_coroutine_done() -> Bool {
}

///|
pub(all) suberror Cancelled derive(Show)
pub(all) suberror Cancelled

///|
pub fn Coroutine::cancel(self : Coroutine) -> Unit {
Expand Down
12 changes: 8 additions & 4 deletions crates/moonbit/src/ffi/wasm_primitive.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ pub(open) trait Waitable {
}

///|
#derive(Eq)
pub(all) enum SubtaskStatus {
Starting(Int)
Started(Int)
Returned(Int)
StartCancelled(Int)
ReturnCancelled(Int)
} derive(Eq, Show)
}

///|
pub fn SubtaskStatus::decode(int : Int) -> SubtaskStatus {
Expand All @@ -43,6 +44,7 @@ pub fn SubtaskStatus::handle(self : Self) -> Int {
}

///|
#derive(Eq)
pub(all) enum Event {
None
Subtask
Expand All @@ -51,7 +53,7 @@ pub(all) enum Event {
FutureRead
FutureWrite
TaskCancel
} derive(Eq, Show)
}

///|
pub fn Event::decode(int : Int) -> Event {
Expand Down Expand Up @@ -81,12 +83,13 @@ pub fn Event::encode(self : Self) -> Int {
}

///|
#derive(Eq)
pub(all) enum WaitableStatus {
Completed(Int)
Dropped(Int)
Cancelled(Int)
Blocking
} derive(Eq, Show)
}

///|
let waitable_status_block : Int = 0xffff_ffff
Expand All @@ -111,12 +114,13 @@ pub fn WaitableStatus::count(int : Int) -> Int {
}

///|
#derive(Eq)
pub(all) enum CallbackCode {
Exit
Yield
Wait(Int)
Cancel(Int)
} derive(Eq, Show)
}

///|
pub fn CallbackCode::encode(self : Self) -> Int {
Expand Down
Loading
Loading