Skip to content
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

Get and Set Globals #540

Merged
merged 13 commits into from
Apr 5, 2024
Merged

Get and Set Globals #540

merged 13 commits into from
Apr 5, 2024

Conversation

RoyalIcing
Copy link
Collaborator

@RoyalIcing RoyalIcing commented Apr 3, 2024

Add Wasmex.Instance.get_global_value/3 and Wasmex.Instance.set_global_value/4 to read and write globals.

I don’t believe languages like Rust or C allow exporting globals, but in raw WebAssembly this is very much possible:

(module
  (global (export "meaning_of_life") i32 (i32.const 42))
  (global (export "count") (mut i64) (i64.const 0))
)

I’ve followed what appears to be the convention of returning string errors. If you like I can make them atoms like {:error, :not_found} or {:error, :immutable}.

@RoyalIcing RoyalIcing requested a review from tessi April 3, 2024 01:24
@RoyalIcing RoyalIcing self-assigned this Apr 3, 2024
@RoyalIcing RoyalIcing changed the title Get and set globals Get and Set Globals Apr 3, 2024
Copy link
Owner

@tessi tessi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this is great 💜 love the change, fits perfectly to existing conventions, implements a missing festure and reads really well.

Thank you.

If you like, you may add your work to the changelog :)

test/example_wasm_files/globals.wat Show resolved Hide resolved
test/wasmex/instance_test.exs Show resolved Hide resolved
@RoyalIcing RoyalIcing merged commit f9ed3b0 into main Apr 5, 2024
17 checks passed
@RoyalIcing RoyalIcing deleted the read-write-globals branch April 5, 2024 06:25
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.

2 participants