Move Wasmtime for .NET to the Wasmtime repo.

This moves the Wasmtime for .NET implementation to the Wasmtime repo.

Wasmtime for .NET is a binding of the Wasmtime API for use in .NET.
This commit is contained in:
Peter Huene
2019-11-22 17:11:00 -08:00
parent bbe2a797ba
commit 9fdf5bce8e
100 changed files with 6391 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
using System;
namespace Wasmtime
{
/// <summary>
/// Represents a mutable WebAssembly global value.
/// </summary>
public class MutableGlobal<T>
{
/// <summary>
/// Creates a new <see cref="MutableGlobal&lt;T&gt;" /> with the given initial value.
/// </summary>
/// <param name="initialValue">The initial value of the global.</param>
public MutableGlobal(T initialValue)
{
InitialValue = initialValue;
Kind = Interop.ToValueKind(typeof(T));
}
/// <summary>
/// The value of the global.
/// </summary>
public T Value
{
get
{
if (Handle is null)
{
throw new InvalidOperationException("The global cannot be used before it is instantiated.");
}
unsafe
{
var v = stackalloc Interop.wasm_val_t[1];
Interop.wasm_global_get(Handle.DangerousGetHandle(), v);
// TODO: figure out a way that doesn't box the value
return (T)Interop.ToObject(v);
}
}
set
{
if (Handle is null)
{
throw new InvalidOperationException("The global cannot be used before it is instantiated.");
}
// TODO: figure out a way that doesn't box the value
var v = Interop.ToValue(value, Kind);
unsafe
{
Interop.wasm_global_set(Handle.DangerousGetHandle(), &v);
}
}
}
internal ValueKind Kind { get; private set; }
internal Interop.GlobalHandle Handle { get; set; }
internal T InitialValue { get; private set; }
}
}