-
Notifications
You must be signed in to change notification settings - Fork 161
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
feat(module) Add Compile
, Module.Instantiate*
, and Module.Close
#33
Merged
Conversation
This file contains 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 patch adds a way to build a real `Module` by using the `Compile` function. Then, a module can instantiated with `Module.Instantiate` or `Module.InstantiateWithImports`. The `NewInstanceWithImports` function has been updated to use a new `newInstanceWithImports` private function that takes an “instance builder” as a parameter, so that it's easier to share code `Instance` and `Module` when it comes to create an `Instance` with its imports, exports, and memory.
Hywan
added
🎉 enhancement
New feature or request
📦 component-extension
About the Go extension
📚 documentation
Do you like to read?
🧪 tests
I love tests
labels
Jun 5, 2019
bors try |
tryBuild succeeded |
bors r+ |
bors bot
added a commit
that referenced
this pull request
Jun 5, 2019
33: feat(module) Add `Compile`, `Module.Instantiate*`, and `Module.Close` r=Hywan a=Hywan Fix #27. This patch adds a way to build a real `Module` by using the `Compile` function. Then, a module can instantiated with `Module.Instantiate` or `Module.InstantiateWithImports`. The `NewInstanceWithImports` function has been updated to use a new `newInstanceWithImports` private function that takes an “instance builder” as a parameter, so that it's easier to share code `Instance` and `Module` when it comes to create an `Instance` with its imports, exports, and memory. Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
Build succeeded |
bors bot
added a commit
that referenced
this pull request
Jun 5, 2019
34: feat(module) Support module serialization and deserialization r=Hywan a=Hywan Sequel of #27 and #33. Ping #23. Example: ```go // Compiles the bytes into a WebAssembly module. module1, _ := wasm.Compile(GetBytes()) defer module1.Close() // Serializes the module into a sequence of bytes. serialization, _ := module1.Serialize() // Do something with `serialization`. // Then later… // Deserializes the module. module2, _ := wasm.DeserializeModule(serialization) defer module2.Close() // And enjoy! // Instantiates the WebAssembly module. instance, _ := module2.Instantiate() defer instance.Close() // Gets an exported function. sum, functionExists := instance.Exports["sum"] fmt.Println(functionExists) // Calls the `sum` exported function with Go values. result, _ := sum(1, 2) fmt.Println(result) // Output: // true // 3 ``` The final API is quite easy to use. I hope `[]byte` is a generic enough type to be accepted by Go caching libraries. Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
📦 component-extension
About the Go extension
📚 documentation
Do you like to read?
🎉 enhancement
New feature or request
🧪 tests
I love tests
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.
Fix #27.
This patch adds a way to build a real
Module
by using theCompile
function. Then, a module can instantiated with
Module.Instantiate
orModule.InstantiateWithImports
.The
NewInstanceWithImports
function has been updated to use a newnewInstanceWithImports
private function that takes an “instancebuilder” as a parameter, so that it's easier to share code
Instance
and
Module
when it comes to create anInstance
with its imports,exports, and memory.