-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Edoardo Vacchi <[email protected]>
- Loading branch information
Showing
6 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/org/extism/chicory/sdk/CachedAotMachineFactory.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.extism.chicory.sdk; | ||
|
||
import com.dylibso.chicory.experimental.aot.AotMachineFactory; | ||
import com.dylibso.chicory.runtime.Instance; | ||
import com.dylibso.chicory.runtime.Machine; | ||
import com.dylibso.chicory.wasm.WasmModule; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
class CachedAotMachineFactory implements Function<Instance, Machine> { | ||
private final Map<WasmModule, AotMachineFactory> factories = new HashMap<>(); | ||
|
||
public CachedAotMachineFactory compile(WasmModule wasmModule) { | ||
factories.put(wasmModule, new AotMachineFactory(wasmModule)); | ||
return this; | ||
} | ||
|
||
public Machine apply(Instance instance) { | ||
if (!factories.containsKey(instance.module())) { | ||
throw new IllegalArgumentException("Instance module is not cached"); | ||
} | ||
var factory = factories.get(instance.module()); | ||
return factory.apply(instance); | ||
} | ||
} |
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 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 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 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 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