-
Notifications
You must be signed in to change notification settings - Fork 33
Implement Accessing Export Memory #33
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package io.github.kawamuray.wasmtime; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.experimental.Accessors; | ||
|
|
||
| @Accessors(fluent = true) | ||
| @AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
| public class ExportType { | ||
| @Getter | ||
| private final ExternType type; | ||
|
|
||
| @Getter(AccessLevel.PACKAGE) | ||
| private final Object typeObj; | ||
|
|
||
| @Getter | ||
| private final String name; | ||
|
|
||
| private void ensureType(ExternType expected) { | ||
| if (type != expected) { | ||
| throw new RuntimeException( | ||
| String.format("ImportType expected to have type %s but is actually %s", expected, type)); | ||
| } | ||
| } | ||
|
|
||
| public FuncType func() { | ||
| ensureType(ExternType.FUNC); | ||
| return (FuncType) typeObj; | ||
| } | ||
|
|
||
| public GlobalType global() { | ||
| ensureType(ExternType.GLOBAL); | ||
| return (GlobalType) typeObj; | ||
| } | ||
|
|
||
| public MemoryType memory() { | ||
| ensureType(ExternType.MEMORY); | ||
| return (MemoryType) typeObj; | ||
| } | ||
|
|
||
| public TableType table() { | ||
| ensureType(ExternType.TABLE); | ||
| return (TableType) typeObj; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package io.github.kawamuray.wasmtime; | ||
|
|
||
| public enum ExternType { | ||
| FUNC, | ||
| GLOBAL, | ||
| TABLE, | ||
| MEMORY, | ||
| // TODO: Currently Unsupported | ||
| INSTANCE, | ||
| MODULE | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,18 +8,8 @@ | |
| @Accessors(fluent = true) | ||
| @AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
| public class ImportType { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't even need |
||
| public enum Type { | ||
| FUNC, | ||
| GLOBAL, | ||
| TABLE, | ||
| MEMORY, | ||
| // TODO: Currently Unsupported | ||
| INSTANCE, | ||
| MODULE | ||
| } | ||
|
|
||
| @Getter | ||
| private final Type type; | ||
| private final ExternType type; | ||
|
|
||
| @Getter(AccessLevel.PACKAGE) | ||
| private final Object typeObj; | ||
|
|
@@ -30,30 +20,30 @@ public enum Type { | |
| @Getter | ||
| private final String name; | ||
|
|
||
| private void ensureType(ImportType.Type expected) { | ||
| private void ensureType(ExternType expected) { | ||
| if (type != expected) { | ||
| throw new RuntimeException( | ||
| String.format("ImportType expected to have type %s but is actually %s", expected, type)); | ||
| } | ||
| } | ||
|
|
||
| public FuncType func() { | ||
| ensureType(ImportType.Type.FUNC); | ||
| ensureType(ExternType.FUNC); | ||
| return (FuncType) typeObj; | ||
| } | ||
|
|
||
| public GlobalType global() { | ||
| ensureType(ImportType.Type.GLOBAL); | ||
| ensureType(ExternType.GLOBAL); | ||
| return (GlobalType) typeObj; | ||
| } | ||
|
|
||
| public MemoryType memory() { | ||
| ensureType(ImportType.Type.MEMORY); | ||
| ensureType(ExternType.MEMORY); | ||
| return (MemoryType) typeObj; | ||
| } | ||
|
|
||
| public TableType table() { | ||
| ensureType(ImportType.Type.TABLE); | ||
| ensureType(ExternType.TABLE); | ||
| return (TableType) typeObj; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,47 @@ | |
| import lombok.Getter; | ||
| import lombok.experimental.Accessors; | ||
|
|
||
| /** | ||
| * A Store is a collection of WebAssembly instances and host-defined state. | ||
| * <p> | ||
| * All WebAssembly instances and items will be attached to and refer to a Store. For example instances, functions, | ||
| * globals, and tables are all attached to a Store. Instances are created by instantiating a Module within a Store. | ||
| * <p> | ||
| * A Store is intended to be a short-lived object in a program. No form of GC is implemented at this time so once an | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This document has a rust-java gap problems too. The notion of "GC", "drop", and so on. |
||
| * instance is created within a Store it will not be deallocated until the Store itself is dropped. This makes Store | ||
| * unsuitable for creating an unbounded number of instances in it because Store will never release this memory. It’s | ||
| * recommended to have a Store correspond roughly to the lifetime of a "main instance" that an embedding is interested | ||
| * in executing. | ||
| * | ||
| * <h1>Type parameter T</h1> | ||
| * <p> | ||
| * Each Store has a type parameter T associated with it. This T represents state defined by the host. | ||
| * This state will be accessible through the Caller type that host-defined functions get access to. | ||
| * This T is suitable for storing Store-specific information which imported functions may want access to. | ||
| * <p> | ||
| * The data T can be accessed through methods like Store::data and Store::data_mut. | ||
| * Stores, contexts, oh my | ||
| * <p> | ||
| * Most methods in Wasmtime take something of the form AsContext or AsContextMut as the first argument. | ||
| * These two traits allow ergonomically passing in the context you currently have to any method. | ||
| * The primary two sources of contexts are: | ||
| * <p> | ||
| * Store<T> | ||
| * Caller<'_, T> | ||
| * <p> | ||
| * corresponding to what you create and what you have access to in a host function. You can also explicitly acquire | ||
| * a StoreContext or StoreContextMut and pass that around as well. | ||
| * <p> | ||
| * Note that all methods on Store are mirrored onto StoreContext, StoreContextMut, and Caller. This way no matter what | ||
| * form of context you have you can call various methods, create objects, etc. | ||
| * | ||
| * <h1>Stores and Default</h1> | ||
| * <p> | ||
| * You can create a store with default configuration settings using Store::default(). This will create a | ||
| * brand new Engine with default configuration (see Config for more information). | ||
| * | ||
| * @param <T> State defined by the host | ||
| */ | ||
| @Accessors(fluent = true) | ||
| @AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
| public class Store<T> implements Disposable { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.