Skip to content

Commit

Permalink
Merge pull request #17 from extism/chicory-1.0.0-M2
Browse files Browse the repository at this point in the history
bump: chicory 1.0.0-M2
  • Loading branch information
evacchi authored Dec 12, 2024
2 parents 0ff3ba0 + f84837c commit 6c46c19
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

<java.version>11</java.version>

<chicory.version>1.0.0-M1</chicory.version>
<chicory.version>1.0.0-M2</chicory.version>
<junit.version>3.8.1</junit.version>

<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/extism/chicory/sdk/ChicoryModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import com.dylibso.chicory.experimental.aot.AotMachine;
import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.wasm.Module;
import com.dylibso.chicory.wasm.Parser;
import com.dylibso.chicory.wasm.WasmModule;

import java.nio.file.Path;

class ChicoryModule {

static final boolean IS_NATIVE_IMAGE_AOT = Boolean.getBoolean("com.oracle.graalvm.isaot");

static Module fromWasm(ManifestWasm m) {
static WasmModule fromWasm(ManifestWasm m) {
if (m instanceof ManifestWasmBytes) {
ManifestWasmBytes mwb = (ManifestWasmBytes) m;
return Parser.parse(mwb.bytes);
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/org/extism/chicory/sdk/DependencyGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
import com.dylibso.chicory.runtime.ExportFunction;
import com.dylibso.chicory.runtime.HostFunction;
import com.dylibso.chicory.runtime.ImportFunction;
import com.dylibso.chicory.runtime.ImportValue;
import com.dylibso.chicory.runtime.ImportValues;
import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.runtime.Store;
import com.dylibso.chicory.runtime.WasmFunctionHandle;
import com.dylibso.chicory.wasm.Module;
import com.dylibso.chicory.wasm.WasmModule;
import com.dylibso.chicory.wasm.types.Export;
import com.dylibso.chicory.wasm.types.ExportSection;
import com.dylibso.chicory.wasm.types.ExternalType;
import com.dylibso.chicory.wasm.types.FunctionImport;
import com.dylibso.chicory.wasm.types.FunctionType;
import com.dylibso.chicory.wasm.types.Import;
import com.dylibso.chicory.wasm.types.ImportSection;
import com.dylibso.chicory.wasm.types.Value;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -36,7 +34,7 @@ class DependencyGraph {
private final Logger logger;

private final Map<String, Set<String>> registeredSymbols = new HashMap<>();
private final Map<String, Module> modules = new HashMap<>();
private final Map<String, WasmModule> modules = new HashMap<>();
private final Set<String> hostModules = new HashSet<>();
private final Map<String, Instance> instances = new HashMap<>();
private final Map<QualifiedName, Trampoline> trampolines = new HashMap<>();
Expand Down Expand Up @@ -93,7 +91,7 @@ private void checkCollision(String moduleName, String symbol) {
/**
* Register a Module with the given name.
*/
public void registerModule(String name, Module m) {
public void registerModule(String name, WasmModule m) {
checkCollision(name, null);

ExportSection exportSection = m.exportSection();
Expand All @@ -113,7 +111,7 @@ public void registerSymbol(String name, String symbol) {
public boolean validate() {
boolean valid = true;
for (var kv : modules.entrySet()) {
Module m = kv.getValue();
WasmModule m = kv.getValue();

ImportSection imports = m.importSection();
for (int i = 0; i < imports.importCount(); i++) {
Expand Down Expand Up @@ -156,7 +154,7 @@ public Instance instantiate() {

while (!unresolved.isEmpty()) {
String moduleId = unresolved.peek();
Module m = this.modules.get(moduleId);
WasmModule m = this.modules.get(moduleId);
boolean satisfied = true;
List<HostFunction> trampolines = new ArrayList<>();
ImportSection imports = m.importSection();
Expand Down Expand Up @@ -217,7 +215,7 @@ public Instance instantiate() {
}

private Instance instantiate(String moduleId, List<HostFunction> moreHostFunctions) {
Module m = this.modules.get(moduleId);
WasmModule m = this.modules.get(moduleId);
Objects.requireNonNull(m);

ImportValues importValues =
Expand Down Expand Up @@ -253,7 +251,7 @@ private ImportValues mergeImportValues(ImportValues hostImports, List<HostFuncti
.addTable(hostImports.tables()).build();
}

private HostFunction registerTrampoline(FunctionImport f, Module m) {
private HostFunction registerTrampoline(FunctionImport f, WasmModule m) {
// Trampolines are singletons for each <moduleName, name> pair.
// Trampolines are not registered into the store, as they are not "real" functions.
// They are instead kept separately and passed explicitly to the instance.
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/extism/chicory/sdk/DependencyGraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.dylibso.chicory.log.SystemLogger;
import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.wasi.WasiPreview1;
import com.dylibso.chicory.wasm.Module;
import com.dylibso.chicory.wasm.WasmModule;
import junit.framework.TestCase;

import java.io.IOException;
Expand Down Expand Up @@ -38,10 +38,10 @@ public void testCircularDepsMore() throws IOException {
InputStream mainBytes = this.getClass().getResourceAsStream("/circular-import-more/circular-import-main.wasm");


Module add = parse(addBytes);
Module sub = parse(subBytes);
Module expr = parse(exprBytes);
Module main = parse(mainBytes);
WasmModule add = parse(addBytes);
WasmModule sub = parse(subBytes);
WasmModule expr = parse(exprBytes);
WasmModule main = parse(mainBytes);

{
DependencyGraph dg = new DependencyGraph(new SystemLogger());
Expand Down Expand Up @@ -74,7 +74,7 @@ public void testCircularDepsMore() throws IOException {

public void testHostFunctionDeps() throws IOException {
InputStream requireWasi = this.getClass().getResourceAsStream("/host-functions/import-wasi.wasm");
Module requireWasiM = parse(requireWasi);
WasmModule requireWasiM = parse(requireWasi);

DependencyGraph dg = new DependencyGraph(new SystemLogger());
dg.registerFunctions(wasiPreview1().toHostFunctions());
Expand All @@ -88,7 +88,7 @@ public void testHostFunctionDeps() throws IOException {

public void testInstantiate() throws IOException {
InputStream requireWasi = this.getClass().getResourceAsStream("/host-functions/import-wasi.wasm");
Module requireWasiM = parse(requireWasi);
WasmModule requireWasiM = parse(requireWasi);

DependencyGraph dg = new DependencyGraph(new SystemLogger());
dg.registerFunctions(wasiPreview1().toHostFunctions());
Expand Down

0 comments on commit 6c46c19

Please sign in to comment.