Implement WebAssembly reference types and table imports. - #29
Merged
Conversation
added 3 commits
July 22, 2020 17:50
This commit implements `externref` values for .NET bindings. Values can now be any .NET reference type. Parameters and return values for host functions can also be any .NET reference type and will be imported as `externref` values. An example was added to show passing and returning .NET strings as `externref` values. This commit also fixes host function callback rooting so that it is no longer tied to the host. Instead, the `_with_env` functions are used for creating the function and the env is a GCHandle that is rooting the callback. A finalizer for the env is used to free the handle. This makes it so that the .NET callback delegate remains rooted while the underlying Wasmtime `Func` exists. Some refactoring was also done in `Function.cs` to streamline the code a little.
This commit implements support for function references in the .NET API. A `Function` can now be created with `Function.FromCallback` and passed as a value to WebAssembly; this will pass the value as a `funcref`. A `Function` can also be used as a parameter for a host function that accepts a `funcref`. The new method `Invoke` can be used to call the function reference. This also adds a new example project showing some simple function reference interactions.
This commit implements table imports. It defines a new class `Table` representing a table import, which can be defined with `Host.DefineTable`. This also fixes support for null funcrefs.
yurydelendik
approved these changes
Jul 24, 2020
yurydelendik
left a comment
Contributor
There was a problem hiding this comment.
Really good. Most of the time I tried to figure out Interop.ToValue/.DeleteValue pair safety. I recommend to add some disposable object/utility for most of the cases, e.g. SafeValue: IDisposable.
Member
Author
|
I'll see about making the value interface a little safer. |
Member
Author
|
Unfortunately the I'd also rather not wrap I did add some comments though. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR implements support in the .NET API for WebAssembly reference types (extern ref and func ref).
It also implements support for declaring table imports in a
Host.A few bug fixes were made, including using a
GCHandlefor functions so that they are rooted while still alive, rather than keeping a set of functions declared in aHost.Closes #27.