Skip to content

Conversation

@abelstuker
Copy link
Contributor

Closes #297.

This extends the implementation to support WebAssembly's multi-value proposal, allowing functions and control structures to return multiple values. This change aligns with the accepted proposal https://github.com/WebAssembly/multi-value/blob/master/proposals/multi-value/Overview.md.

Functions can now return multiple values:

;; Function returning two values
(func $add-and-subtract (param i32 i32) (result i32 i32)
  (local.get 0) 
  (local.get 1)
  (i32.add)
  (local.get 0) 
  (local.get 1)
  (i32.sub)
)

;; The function call returns two values
(i32.const 10)
(i32.const 5)
(call $add-and-subtract)
;; Stack now has: 15, 5

Control structures support multi-value types:

;; Block with multi-value result
(block (result i32 i32)
  (i32.const 42)
  (i32.const 99)
)

;; If/else with multi-value result
(if (result i32 i32)
  (then
    (i32.const 100)
    (i32.const 200)
  )
  (else
    (i32.const 300)
    (i32.const 400)
  )
)

The host can now invoke functions with multiple return values:

// Invoke function and capture multiple results
StackValue outputs[8];
uint32_t out_count = 0;
bool ok = this->invoke(m, fidx, 0, nullptr, 8, outputs, &out_count);

// Access individual results
int32_t result1 = outputs[0].value.uint32;
int32_t result2 = outputs[1].value.uint32;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📑 Multi-value Extension

2 participants