Skip to content

Commit adb47c0

Browse files
committed
Compile time constants WIP
1 parent 53d5d99 commit adb47c0

2 files changed

Lines changed: 2 additions & 34 deletions

File tree

EasySourceGenerators.Generators/DataBuilding/DataMethodBodyBuilders.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,39 +42,6 @@ public record DataMethodBodyBuilderStage4<TParam1, TReturnType>(BodyGenerationDa
4242

4343
public IMethodBodyGenerator BodyReturningConstant(Func<TReturnType> constantValueFactory) =>
4444
new DataMethodBodyGenerator(Data with { ReturnConstantValueFactory = constantValueFactory });
45-
46-
public IMethodBodyGeneratorSwitchBody<TParam1, TReturnType> BodyWithSwitchStatement()
47-
=> throw new NotImplementedException(); //TODO: Remove explicit SwitchStatements with `for` and `constants`, like so:
48-
/*
49-
.ForMethod().WithReturnType<int>().WithParameter<int>()
50-
.BodyWithSwitchStatement()
51-
.ForCases(0, 1, 2, 300, 301, 302, 303).ReturnConstantValue(decimalNumber => SlowMath.CalculatePiDecimal(decimalNumber))
52-
.ForDefaultCase().UseProvidedBody(decimalNumber => SlowMath.CalculatePiDecimal(decimalNumber));
53-
54-
Will be replaced with:
55-
56-
.ForMethod().WithReturnType<int>().WithParameter<int>()
57-
.WithCompileTimeConstants(() => new
58-
{
59-
PrecomputedTargets = new HashSet<int>(new int[] { 0, 1, 2, 300, 301, 302, 303 })
60-
})
61-
.UseProvidedBody(decimalNumber, constants =>
62-
{
63-
if (constants.PrecomputedTargets.Contains(decimalNumber)) return SlowMath.CalculatePiDecimal(decimalNumber);
64-
else return SlowMath.CalculatePiDecimal(decimalNumber);
65-
});
66-
67-
Or (in the case of PI), just simply:
68-
69-
.ForMethod().WithReturnType<int>().WithParameter<int>()
70-
.UseProvidedBody(decimalNumber =>
71-
{
72-
var precomputedTargets = new HashSet<int>(new int[] { 0, 1, 2, 300, 301, 302, 303 })
73-
74-
if (precomputedTargets.Contains(decimalNumber)) return SlowMath.CalculatePiDecimal(decimalNumber);
75-
else return SlowMath.CalculatePiDecimal(decimalNumber);
76-
});
77-
*/
7845
}
7946

8047
public record DataMethodBodyBuilderStage4NoArg<TReturnType>(BodyGenerationData Data) : IMethodBodyBuilderStage4NoArg<TReturnType>

EasySourceGenerators.Generators/DataBuilding/DataRecords.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ public record BodyGenerationData(
66
Type? ReturnType = null,
77
Type[]? ParametersTypes = null,
88
Delegate? RuntimeDelegateBody = null,
9-
Delegate? ReturnConstantValueFactory = null
9+
Delegate? ReturnConstantValueFactory = null,
10+
object? CompileTimeConstants = null
1011
);

0 commit comments

Comments
 (0)