-
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.
Merge pull request #18 from extism/updated-extism-host-api
- Loosely follow the java-sdk, expose ExtismHostFunction and use an internal ExtismValTypeList that avoids wrapping as much as possible. - Hide the conversion between longs and high-level, types - Add test case following the java-sdk - Update the README Signed-off-by: Edoardo Vacchi <[email protected]>
- Loading branch information
Showing
12 changed files
with
545 additions
and
62 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.extism.chicory.sdk; | ||
|
||
@FunctionalInterface | ||
public interface ExtismFunction { | ||
void apply(CurrentPlugin currentPlugin, ExtismValueList args, ExtismValueList returns); | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/org/extism/chicory/sdk/ExtismTypeConversionException.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,9 @@ | ||
package org.extism.chicory.sdk; | ||
|
||
public class ExtismTypeConversionException extends ExtismException { | ||
|
||
public ExtismTypeConversionException(ExtismValType expected, ExtismValType given) { | ||
super(String.format("Illegal type conversion, wanted %s, given %s", expected.name(), given.name())); | ||
} | ||
|
||
} |
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,39 @@ | ||
package org.extism.chicory.sdk; | ||
|
||
import com.dylibso.chicory.wasm.types.ValueType; | ||
|
||
public enum ExtismValType { | ||
I32(ValueType.I32), | ||
I64(ValueType.I64), | ||
F32(ValueType.F32), | ||
F64(ValueType.F64); | ||
|
||
private final ValueType chicoryType; | ||
|
||
ExtismValType(ValueType chicoryType) { | ||
this.chicoryType = chicoryType; | ||
} | ||
|
||
ValueType toChicoryValueType() { | ||
return chicoryType; | ||
} | ||
|
||
public ExtismValue toExtismValue(long v) { | ||
switch (this) { | ||
case I32: | ||
return ExtismValue.i32(v); | ||
case I64: | ||
return ExtismValue.i64(v); | ||
case F32: | ||
return ExtismValue.f32FromLongBits(v); | ||
case F64: | ||
return ExtismValue.f64FromLongBits(v); | ||
default: | ||
throw new IllegalArgumentException(); | ||
} | ||
} | ||
|
||
public long toChicoryValue(ExtismValue value) { | ||
return 0; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/org/extism/chicory/sdk/ExtismValTypeList.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,33 @@ | ||
package org.extism.chicory.sdk; | ||
|
||
import com.dylibso.chicory.wasm.types.ValueType; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
class ExtismValTypeList { | ||
private final ExtismValType[] types; | ||
private final List<ValueType> chicoryTypes; | ||
|
||
ExtismValTypeList(List<ExtismValType> types) { | ||
this.types = types.toArray(ExtismValType[]::new); | ||
this.chicoryTypes = types.stream().map(ExtismValType::toChicoryValueType) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
List<ValueType> toChicoryTypes() { | ||
return Arrays.stream(types) | ||
.map(ExtismValType::toChicoryValueType) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public ExtismValueList toExtismValueList(long[] args) { | ||
return new ExtismValueList(this.types, args); | ||
} | ||
|
||
public ExtismValueList toExtismValueList() { | ||
return new ExtismValueList(this.types, new long[this.types.length]); | ||
} | ||
|
||
} |
Oops, something went wrong.