-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContinuation.cs
More file actions
33 lines (29 loc) · 1016 Bytes
/
Copy pathContinuation.cs
File metadata and controls
33 lines (29 loc) · 1016 Bytes
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
using System.Collections.Generic;
using System.Linq;
namespace Liu233w.StackMachine
{
/// <summary>
/// 程序的续延,需要配合 <see cref="StackMachine"/> 使用
/// </summary>
public class Continuation
{
private Stack<StackFrameFunction> _callingStack;
internal Continuation(Stack<StackFrameFunction> callingStack)
{
_callingStack = DeepCopyStack(callingStack);
}
/// <summary>
/// 获取调用栈,将调用栈中的每个 stackMachine 设置成指定的对象
/// </summary>
/// <returns></returns>
internal Stack<StackFrameFunction> GetCallingStack()
{
return DeepCopyStack(_callingStack);
}
private static Stack<StackFrameFunction> DeepCopyStack(Stack<StackFrameFunction> stack)
{
var snapshot = stack.Select(item => (StackFrameFunction)item.Clone());
return new Stack<StackFrameFunction>(snapshot.Reverse());
}
}
}