Added support for captured local functions cast to delegates

このコミットが含まれているのは:
Sergio Pedri committed 2019-09-05 17:33:41 +02:00
1 親 a91b44a329
コミット e512c5839e
2ファイル変更
+19 -5

検索条件に一致するファイルはありません

+1 -1
ファイルの表示
@@ -208,7 +208,7 @@ namespace ComputeSharp.Shaders.Translation
{
string
sourceCode = DecompileMethodOrDeclaringType(methodInfo, true),
methodFixedCode = sourceCode.Replace(methodInfo.Name, methodInfo.Name.Replace("<", string.Empty).Replace(">", "_")),
methodFixedCode = sourceCode.Replace(methodInfo.Name, Regex.Replace(methodInfo.Name, "[<>|]", "_")),
prototype = methodFixedCode.Split(Environment.NewLine)[0],
commentedSourceCode = $"// {methodInfo.Name}{Environment.NewLine}{methodFixedCode}",
inFixedSourceCode = Regex.Replace(commentedSourceCode, @"(?<!\w)in ", string.Empty),
+18 -4
ファイルの表示
@@ -99,13 +99,27 @@ namespace ComputeSharp.Tests
Func<float, float> f = x => x * x;
Func<int, float> invert = x => -x;
Gpu.Default.For(1, id => buffer[0] = f(3) + invert(8));
Gpu.Default.For(1, id => buffer[0] = f(3));
float[] result = buffer.GetData();
Assert.IsTrue(MathF.Abs(result[0] - 1) < 0.0001f);
Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f);
}
[TestMethod]
public void StatelessLocalFunctionToDelegate()
{
using ReadWriteBuffer<float> buffer = Gpu.Default.AllocateReadWriteBuffer<float>(1);
float Func(float x) => x * x;
Func<float, float> f = Func;
Gpu.Default.For(1, id => buffer[0] = f(3));
float[] result = buffer.GetData();
Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f);
}
}
}