Skip to content

Commit

Permalink
Wasmtime 0.40.0-preview1
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwille committed Aug 30, 2022
1 parent 42123f8 commit c0c5fb1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/Opa.Wasm.Benchmarks/Opa.Wasm.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Opa.Wasm.ConsoleSample/Opa.Wasm.ConsoleSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<ItemGroup>
<PackageReference Include="SharpZipLib" Version="1.3.3" />
<PackageReference Include="Wasmtime" Version="0.39.1-preview2" />
<PackageReference Include="Wasmtime" Version="0.40.0-preview1" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Opa.Wasm/Opa.Wasm.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>0.32.0</Version>
<Version>0.33.0</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/christophwille/dotnet-opa-wasm</PackageProjectUrl>
<RepositoryUrl>https://github.com/christophwille/dotnet-opa-wasm.git</RepositoryUrl>
Expand Down Expand Up @@ -37,7 +37,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="6.0.5" />
<PackageReference Include="Wasmtime" Version="0.39.1-preview2" />
<PackageReference Include="Wasmtime" Version="0.40.0-preview1" />
</ItemGroup>

</Project>
36 changes: 18 additions & 18 deletions src/Opa.Wasm/OpaPolicy.Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,99 +6,99 @@ public partial class OpaPolicy
{
private int? Policy_opa_wasm_abi_version()
{
var global = _instance.GetGlobal(_store, "opa_wasm_abi_version");
return (int?)global?.GetValue(_store);
var global = _instance.GetGlobal("opa_wasm_abi_version");
return (int?)global?.GetValue();
}

private int? Policy_opa_wasm_abi_minor_version()
{
var global = _instance.GetGlobal(_store, "opa_wasm_abi_minor_version");
return (int?)global?.GetValue(_store);
var global = _instance.GetGlobal("opa_wasm_abi_minor_version");
return (int?)global?.GetValue();
}

private int Policy_Builtins()
{
var run = _instance.GetFunction<int>(_store, "builtins");
var run = _instance.GetFunction<int>("builtins");
return run();
}

private int Policy_Entrypoints()
{
var run = _instance.GetFunction<int>(_store, "entrypoints");
var run = _instance.GetFunction<int>("entrypoints");
return run();
}

private int Policy_opa_heap_ptr_get()
{
var run = _instance.GetFunction<int>(_store, "opa_heap_ptr_get");
var run = _instance.GetFunction<int>("opa_heap_ptr_get");
return run();
}

private void Policy_opa_heap_ptr_set(int ptr)
{
var run = _instance.GetAction<int>(_store, "opa_heap_ptr_set");
var run = _instance.GetAction<int>("opa_heap_ptr_set");
run(ptr);
}

private int Policy_opa_eval_ctx_new()
{
var run = _instance.GetFunction<int>(_store, "opa_eval_ctx_new");
var run = _instance.GetFunction<int>("opa_eval_ctx_new");
return run();
}

private void Policy_opa_eval_ctx_set_input(int ctxAddr, int inputAddr)
{
var run = _instance.GetAction<int, int>(_store, "opa_eval_ctx_set_input");
var run = _instance.GetAction<int, int>("opa_eval_ctx_set_input");
run(ctxAddr, inputAddr);
}

private void Policy_opa_eval_ctx_set_data(int ctxAddr, int dataAddr)
{
var run = _instance.GetAction<int, int>(_store, "opa_eval_ctx_set_data");
var run = _instance.GetAction<int, int>("opa_eval_ctx_set_data");
run(ctxAddr, dataAddr);
}

private void Policy_opa_eval_ctx_set_entrypoint(int ctxAddr, int entrypoint)
{
var run = _instance.GetAction<int, int>(_store, "opa_eval_ctx_set_entrypoint");
var run = _instance.GetAction<int, int>("opa_eval_ctx_set_entrypoint");
run(ctxAddr, entrypoint);
}

private void Policy_eval(int ctxAddr)
{
var run = _instance.GetFunction<int, int>(_store, "eval");
var run = _instance.GetFunction<int, int>("eval");
_ = run(ctxAddr);
}

private int Policy_opa_eval(/*int addr, */
int entrypoint_id, int dataaddr, int jsonaddr, int jsonlength, int heapaddr/*, int format*/)
{
var run = _instance.GetFunction<int, int, int, int, int, int, int, int>(_store, "opa_eval");
var run = _instance.GetFunction<int, int, int, int, int, int, int, int>("opa_eval");
return run(0 /* always 0 */, entrypoint_id,
dataaddr, jsonaddr, jsonlength, heapaddr, 0 /* json format */);
}

private int Policy_opa_eval_ctx_get_result(int ctxAddr)
{
var run = _instance.GetFunction<int, int>(_store, "opa_eval_ctx_get_result");
var run = _instance.GetFunction<int, int>("opa_eval_ctx_get_result");
return run(ctxAddr);
}

private int Policy_opa_malloc(int length)
{
var run = _instance.GetFunction<int, int>(_store, "opa_malloc");
var run = _instance.GetFunction<int, int>("opa_malloc");
return run(length);
}

private int Policy_opa_json_parse(int addr, int length)
{
var run = _instance.GetFunction<int, int, int>(_store, "opa_json_parse");
var run = _instance.GetFunction<int, int, int>("opa_json_parse");
return run(addr, length);
}

private int Policy_opa_json_dump(int addrResult)
{
var run = _instance.GetFunction<int, int>(_store, "opa_json_dump");
var run = _instance.GetFunction<int, int>("opa_json_dump");
return run(addrResult);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Opa.Wasm/OpaPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void LinkImports()
_linker.Define(OpaConstants.Module, OpaConstants.Abort, Function.FromCallback(_store,
(Caller caller, int addr) =>
{
string info = _envMemory.ReadNullTerminatedString(_store, addr);
string info = _envMemory.ReadNullTerminatedString(addr);

// NOTE: the generic class will do, as it is unwrapped again by Policy_eval/run?.Invoke
throw new Exception(info);
Expand Down Expand Up @@ -303,11 +303,11 @@ private string FastEvaluate(string json, int? entrypoint)
{
if (!entrypoint.HasValue) entrypoint = 0; // use default entry point

_envMemory.WriteString(_store, _dataHeapPtr, json);
_envMemory.WriteString(_dataHeapPtr, json);

int resultaddr = Policy_opa_eval(entrypoint.Value, _dataAddr, _dataHeapPtr, json.Length, _dataHeapPtr + json.Length);

return _envMemory.ReadNullTerminatedString(_store, resultaddr);
return _envMemory.ReadNullTerminatedString(resultaddr);
}

public void SetDataJson(string json)
Expand All @@ -326,7 +326,7 @@ public void SetData(object data)
private int LoadJson(string json)
{
int addr = Policy_opa_malloc(json.Length);
_envMemory.WriteString(_store, addr, json);
_envMemory.WriteString(addr, json);

int parseAddr = Policy_opa_json_parse(addr, json.Length);

Expand All @@ -341,7 +341,7 @@ private int LoadJson(string json)
private string DumpJson(int addrResult)
{
int addr = Policy_opa_json_dump(addrResult);
return _envMemory.ReadNullTerminatedString(_store, addr);
return _envMemory.ReadNullTerminatedString(addr);
}

public void Dispose()
Expand Down

0 comments on commit c0c5fb1

Please sign in to comment.