-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStackOperations.cs
More file actions
58 lines (52 loc) · 2.18 KB
/
StackOperations.cs
File metadata and controls
58 lines (52 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Reflection.Emit;
using JetBrains.Annotations;
namespace ILGeneratorExtensions
{
/// <summary>
/// Contains extension methods for performing stack manipulation
/// </summary>
[PublicAPI]
public static class StackOperations
{
/// <summary>
/// Pops the top value off the evaluation stack and discards it
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
[PublicAPI]
public static ILGenerator Pop(this ILGenerator generator) => generator.FluentEmit(OpCodes.Pop);
/// <summary>
/// Pops <paramref name="n"/> values off the evaluation stack and discards them
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="n">The number of evaluation stack values to discard</param>
[PublicAPI]
public static ILGenerator Pop(this ILGenerator generator, uint n)
{
for (int i = 0; i < n; i++)
{
generator.FluentEmit(OpCodes.Pop);
}
return generator;
}
/// <summary>
/// Duplicates the value on the top of the evaluation stack
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
[PublicAPI]
public static ILGenerator Duplicate(this ILGenerator generator) => generator.FluentEmit(OpCodes.Dup);
/// <summary>
/// Duplicates the value on the top of the evaluation stack <paramref name="n"/> times
/// </summary>
/// <param name="generator">The <see cref="T:System.Reflection.Emit.ILGenerator" /> to emit instructions from</param>
/// <param name="n">The number of times to duplicate the value</param>
[PublicAPI]
public static ILGenerator Duplicate(this ILGenerator generator, uint n)
{
for (int i = 0; i < n; i++)
{
generator.FluentEmit(OpCodes.Dup);
}
return generator;
}
}
}