Skip to content

Instantly share code, notes, and snippets.

@yowl
Last active August 14, 2025 01:05
Show Gist options
  • Select an option

  • Save yowl/72b406c9604b5ff4c170e441fb3e88c8 to your computer and use it in GitHub Desktop.

Select an option

Save yowl/72b406c9604b5ff4c170e441fb3e88c8 to your computer and use it in GitHub Desktop.
Runner interface
// Generated by `wit-bindgen` 0.43.0. DO NOT EDIT!
// <auto-generated />
#nullable enable
namespace RunnerWorld.wit.imports.a.b;
public interface II {
public static async unsafe Task OneArgument(uint x)
{
IInterop.OneArgumentWasmInterop.wasmImportOneArgument(unchecked((int)(x)));
}
public static async unsafe Task<uint> OneResult()
{
void* address = global::System.Runtime.InteropServices.NativeMemory.AlignedAlloc(4, 4);
//TODO: store somewhere with the TaskCompletionSource, possibly in the state, using Task.AsyncState to retrieve it later.
var result = IInterop.OneResultWasmInterop.wasmImportOneResult(address);
global::System.Runtime.InteropServices.NativeMemory.Free(address);
return unchecked((uint)(unchecked((uint)(global::System.BitConverter.ToInt32(new global::System.Span<byte>((byte*)address + 0, 4))))));
}
public static async unsafe Task<uint> OneArgumentAndResult(uint x)
{
void* address = global::System.Runtime.InteropServices.NativeMemory.AlignedAlloc(4, 4);
//TODO: store somewhere with the TaskCompletionSource, possibly in the state, using Task.AsyncState to retrieve it later.
var result = IInterop.OneArgumentAndResultWasmInterop.wasmImportOneArgumentAndResult(unchecked((int)(x)), address);
global::System.Runtime.InteropServices.NativeMemory.Free(address);
return unchecked((uint)(unchecked((uint)(global::System.BitConverter.ToInt32(new global::System.Span<byte>((byte*)address + 0, 4))))));
}
public static async unsafe Task TwoArguments(uint x, uint y)
{
IInterop.TwoArgumentsWasmInterop.wasmImportTwoArguments(unchecked((int)(x)), unchecked((int)(y)));
}
public static async unsafe Task<uint> TwoArgumentsAndResult(uint x, uint y)
{
void* address = global::System.Runtime.InteropServices.NativeMemory.AlignedAlloc(4, 4);
//TODO: store somewhere with the TaskCompletionSource, possibly in the state, using Task.AsyncState to retrieve it later.
var result = IInterop.TwoArgumentsAndResultWasmInterop.wasmImportTwoArgumentsAndResult(unchecked((int)(x)), unchecked((int)(y)), address);
global::System.Runtime.InteropServices.NativeMemory.Free(address);
return unchecked((uint)(unchecked((uint)(global::System.BitConverter.ToInt32(new global::System.Span<byte>((byte*)address + 0, 4))))));
}
}
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using RunnerWorld.wit.imports.a.b;
using System.Text;
public class Program
{
public static async Task Main(string[] args)
{
var t = II.OneArgument(1);
Debug.Assert(t.IsCompletedSuccessfully);
var tOneResult = II.OneResult();
Debug.Assert(tOneResult.IsCompletedSuccessfully);
Debug.Assert(tOneResult.Result == 2);
var tOneArgumentAndResult = II.OneArgumentAndResult(3);
Debug.Assert(tOneArgumentAndResult.IsCompletedSuccessfully);
Debug.Assert(tOneArgumentAndResult.Result == 4);
var tTwoArguments = II.TwoArguments(5, 6);
Debug.Assert(tTwoArguments.IsCompletedSuccessfully);
var tTwoArgumentsAndResult = II.TwoArgumentsAndResult(7, 8);
Debug.Assert(tTwoArgumentsAndResult.IsCompletedSuccessfully);
Debug.Assert(tTwoArgumentsAndResult.Result == 9);
}
}
// Generated by `wit-bindgen` 0.43.0. DO NOT EDIT!
// <auto-generated />
#nullable enable
namespace RunnerWorld.wit.imports.a.b
{
public static class IInterop {
internal static class OneArgumentWasmInterop
{
[global::System.Runtime.InteropServices.DllImportAttribute("a:b/i", EntryPoint = "[async-lower][async]one-argument"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
internal static extern uint wasmImportOneArgument(int p0);
}
internal static class OneResultWasmInterop
{
[global::System.Runtime.InteropServices.DllImportAttribute("a:b/i", EntryPoint = "[async-lower][async]one-result"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
internal static extern unsafe uint wasmImportOneResult(void *taskResultBuffer);
}
internal static class OneArgumentAndResultWasmInterop
{
[global::System.Runtime.InteropServices.DllImportAttribute("a:b/i", EntryPoint = "[async-lower][async]one-argument-and-result"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
internal static extern unsafe uint wasmImportOneArgumentAndResult(int p0, void *taskResultBuffer);
}
internal static class TwoArgumentsWasmInterop
{
[global::System.Runtime.InteropServices.DllImportAttribute("a:b/i", EntryPoint = "[async-lower][async]two-arguments"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
internal static extern uint wasmImportTwoArguments(int p0, int p1);
}
internal static class TwoArgumentsAndResultWasmInterop
{
[global::System.Runtime.InteropServices.DllImportAttribute("a:b/i", EntryPoint = "[async-lower][async]two-arguments-and-result"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
internal static extern unsafe uint wasmImportTwoArgumentsAndResult(int p0, int p1, void *taskResultBuffer);
}
}
}
using System.Diagnostics;
namespace TestWorld.wit.exports.my.test
{
public class IImpl : II
{
public static Task ReadFuture(FutureReader reader)
{
return Task.CompletedTask;
}
public static Task DropFuture(FutureReader reader)
{
return Task.CompletedTask;
}
}
}
// Generated by `wit-bindgen` 0.43.0. DO NOT EDIT!
// <auto-generated />
#nullable enable
namespace TestWorld.wit.exports.a.b;
public interface II {
static abstract Task OneArgument(uint x);
static abstract Task<uint> OneResult();
static abstract Task<uint> OneArgumentAndResult(uint x);
static abstract Task TwoArguments(uint x, uint y);
static abstract Task<uint> TwoArgumentsAndResult(uint x, uint y);
}
// Generated by `wit-bindgen` 0.43.0. DO NOT EDIT!
// <auto-generated />
#nullable enable
namespace TestWorld.wit.exports.my.test
{
public static class IInterop {
[global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(EntryPoint = "[async-lift]my:test/i#[async]read-future")]
public static unsafe uint wasmExportAsyncReadFuture(int p0) {
var reader = new FutureReader(p0);
var ret = IImpl.ReadFuture((reader));
if (ret.IsCompletedSuccessfully)
{
ReadFutureTaskReturn();
return (uint)CallbackCode.Exit;
}
return (uint)CallbackCode.Yield;
// TODO_task_cancel.forget();
}
[global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(EntryPoint = "[callback][async-lift]my:test/i#[async]read-future")]
public static uint ReadFutureCallback(uint eventRaw, uint waitable, uint code)
{
// TODO: decode the parameters
return (uint)CallbackCode.Exit;
}
[global::System.Runtime.InteropServices.DllImportAttribute("[export]my:test/i", EntryPoint = "[task-return][async]read-future"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
internal static extern void ReadFutureTaskReturn();
[global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(EntryPoint = "[async-lift]my:test/i#[async]drop-future")]
public static unsafe uint wasmExportAsyncDropFuture(int p0) {
var reader = new FutureReader(p0);
var ret = IImpl.DropFuture((reader));
if (ret.IsCompletedSuccessfully)
{
DropFutureTaskReturn();
return (uint)CallbackCode.Exit;
}
return (uint)CallbackCode.Yield;
// TODO_task_cancel.forget();
}
[global::System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute(EntryPoint = "[callback][async-lift]my:test/i#[async]drop-future")]
public static uint DropFutureCallback(uint eventRaw, uint waitable, uint code)
{
// TODO: decode the parameters
return (uint)CallbackCode.Exit;
}
[global::System.Runtime.InteropServices.DllImportAttribute("[export]my:test/i", EntryPoint = "[task-return][async]drop-future"), global::System.Runtime.InteropServices.WasmImportLinkageAttribute]
internal static extern void DropFutureTaskReturn();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment