Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<DevBuild Condition="'$(DevBuild)'==''">false</DevBuild>
<WasmtimeVersion Condition="'$(WasmtimeVersion)'==''">44.0.0</WasmtimeVersion>
<WasmtimeVersion Condition="'$(WasmtimeVersion)'==''">48.0.2</WasmtimeVersion>
<WasmtimeDotnetVersion Condition="'$(WasmtimeDotnetVersion)'==''"></WasmtimeDotnetVersion>
<WasmtimePackageVersion Condition="'$(DevBuild)'=='true'">$(WasmtimeVersion)$(WasmtimeDotnetVersion)-dev</WasmtimePackageVersion>
<WasmtimePackageVersion Condition="'$(WasmtimePackageVersion)'==''">$(WasmtimeVersion)$(WasmtimeDotnetVersion)</WasmtimePackageVersion>
Expand Down
22 changes: 21 additions & 1 deletion src/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public static bool IsNull(this in ExternFunc externfunc)

internal static class ValueType
{
// This is used to identify `v128` types, which cannot be recognised through `wasm_valtype_kind`.
private static readonly IntPtr V128Type = Native.wasmtime_wasm_valtype_v128();

public static IntPtr FromKind(TableKind kind)
{
return FromKind((ValueKind)kind);
Expand All @@ -103,9 +106,12 @@ public static IntPtr FromKind(ValueKind kind)
case ValueKind.Int64:
case ValueKind.Float32:
case ValueKind.Float64:
case ValueKind.V128:
return Native.wasm_valtype_new((byte)kind);

// v128 has no `wasm_valkind_t`, so it needs its own constructor.
case ValueKind.V128:
return Native.wasmtime_wasm_valtype_v128();

case ValueKind.ExternRef:
return Native.wasm_valtype_new(128);

Expand All @@ -119,6 +125,13 @@ public static IntPtr FromKind(ValueKind kind)

public static ValueKind ToKind(IntPtr type)
{
// `v128` has no `wasm_valkind_t` so `wasm_valtype_kind` cannot be used to identify it.
// It has be identified by using `wasmtime_wasm_valtype_equal`.
if (Native.wasmtime_wasm_valtype_equal(type, V128Type))
{
return ValueKind.V128;
}

var kind = (ValueKind)Native.wasm_valtype_kind(type);
switch (kind)
{
Expand All @@ -145,6 +158,13 @@ private static class Native
[DllImport(Engine.LibraryName)]
public static extern IntPtr wasm_valtype_new(byte kind);

[DllImport(Engine.LibraryName)]
public static extern IntPtr wasmtime_wasm_valtype_v128();

[DllImport(Engine.LibraryName)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool wasmtime_wasm_valtype_equal(IntPtr a, IntPtr b);

[DllImport(Engine.LibraryName)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern byte wasm_valtype_kind(IntPtr valueType);
Expand Down