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

Introduce the Store #486

Closed
evacchi opened this issue Aug 26, 2024 · 0 comments · Fixed by #495
Closed

Introduce the Store #486

evacchi opened this issue Aug 26, 2024 · 0 comments · Fixed by #495

Comments

@evacchi
Copy link
Collaborator

evacchi commented Aug 26, 2024

Related to #482.

Before introducing HostModules and eventually Linking it probably makes sense to introduce the concept of a Store. See e.g. Wasmtime, wazero and the Spec

A Store is an intermediate-level abstraction that collects Wasm (function/global/memory etc) instances and host-defined state. It simplifies creating instances when there are a lot of interdependencies, but it does not resolve names like a Linker (cf. wasmtime) would do. In other words, the end user is still required to instantiate modules in the right order, but at least this way it will be the Store to keep around all the right globals/functions etc.

E.g. imagine you have modules x, y, z, with z depending on x and y (i.e. importing from names x and y); you would write something like (for instance)

// if there are any host functions independent from Wasm modules
store.withHostFunction(...); // these could be eventually stored in a HostModule 

// Instantiate and register exports automatically into the store.
store.instantiate("x", x); 
store.instantiate("y", y); 

// We can now instantiate z
var zInstance = store.instantiate("z", z); 
// all imports of the type <"x", "foo"> or <"y", "bar"> are found in the store 
// if they are exported by x, y; so instantiation succeeds.

// zInstance is ready to use.
zInstance.call(...)

The API is a strawman, the following would work just as well:

// if there are any host functions independent from Wasm modules
store.withHostFunction(...); // these could be eventutally stored in a Host Module if/when they are introduced.

// Instantiate and register exports automatically into the store.
Instance.builder(x).withStore(store, "x").build(); 
Instance.builder(y).withStore(store, "y").build(); 

// We can now instantiate z
var zInstance = Instance.builder(z).withStore(store).build();

// zInstance is ready to use.
zInstance.call(...)
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 a pull request may close this issue.

1 participant